Skip to content

Commit

Permalink
Issue 2895 configure isort (#146)
Browse files Browse the repository at this point in the history
* Sort imports using isort

No functional changes, just configured isort in pyproject.toml
and ran it.
* Clean imports

Removed unused imports and disabled pylint warnings on some lines.
  • Loading branch information
PiispaH authored Jul 18, 2024
1 parent 075d179 commit 8da9d87
Show file tree
Hide file tree
Showing 40 changed files with 141 additions and 141 deletions.
2 changes: 1 addition & 1 deletion .github/pull_request_template.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ Fixes # (issue)
- [ ] Documentation (also in Toolbox repo) is up-to-date
- [ ] Release notes in Toolbox repo have been updated
- [ ] Unit tests have been added/updated accordingly
- [ ] Code has been formatted by black
- [ ] Code has been formatted by black & isort
- [ ] Unit tests pass
9 changes: 9 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,12 @@ ignore_errors = true
[tool.black]
line-length = 120
exclude = '\.git|version.py'

[tool.isort]
profile = "black"
lines_between_sections = 0
force_sort_within_sections = true
honor_case_in_force_sorted_sections = true
skip = ["version.py"]
line_length = 120
known_first_party = ["spinedb_api"]
15 changes: 7 additions & 8 deletions spine_engine/execution_managers/conda_kernel_spec_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,18 @@
# https://github.com/Anaconda-Platform/nb_conda_kernels/blob/master/nb_conda_kernels/manager.py

# -*- coding: utf-8 -*-
import logging
import glob
import json
import logging
import os
from os.path import abspath, basename, dirname, join, split
import re
import shutil
import subprocess
import sys
import time
import glob

import os
from os.path import join, split, dirname, basename, abspath
from traitlets import Bool, Unicode, TraitError, validate
from jupyter_client.kernelspec import KernelSpecManager, KernelSpec, NoSuchKernel
from jupyter_client.kernelspec import KernelSpec, KernelSpecManager, NoSuchKernel
from traitlets import Bool, TraitError, Unicode, validate

CACHE_TIMEOUT = 60

Expand Down Expand Up @@ -109,7 +108,7 @@ def clean_kernel_name(kname):
kname.encode("ascii")
except UnicodeEncodeError:
# Replace accented characters with unaccented equivalents
import unicodedata
import unicodedata # pylint: disable=import-outside-toplevel

nfkd_form = unicodedata.normalize("NFKD", kname)
kname = "".join([c for c in nfkd_form if not unicodedata.combining(c)])
Expand Down
4 changes: 1 addition & 3 deletions spine_engine/execution_managers/conda_kernel_spec_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@
# https://github.com/Anaconda-Platform/nb_conda_kernels/blob/master/nb_conda_kernels/runner.py

from __future__ import print_function

import os
import sys
import subprocess
import locale
import sys

try:
from shlex import quote
Expand Down
6 changes: 3 additions & 3 deletions spine_engine/execution_managers/kernel_execution_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@
"""

import os
import sys
import subprocess
import sys
import uuid
from jupyter_client.manager import KernelManager
from jupyter_client.kernelspec import NoSuchKernel
from jupyter_client.manager import KernelManager
from spine_engine.execution_managers.conda_kernel_spec_manager import CondaKernelSpecManager
from ..utils.helpers import Singleton
from .execution_manager_base import ExecutionManagerBase
from spine_engine.execution_managers.conda_kernel_spec_manager import CondaKernelSpecManager


class GroupedKernelManager(KernelManager):
Expand Down
16 changes: 8 additions & 8 deletions spine_engine/execution_managers/persistent_execution_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,20 @@
as well as some convenience functions.
"""
import uuid
from dataclasses import dataclass
from multiprocessing import Lock, Process
import os
from queue import Empty, Queue
import signal
import socket
import socketserver
from subprocess import PIPE, Popen
import sys
import os
import signal
import threading
import time
from dataclasses import dataclass
from subprocess import Popen, PIPE
from multiprocessing import Process, Lock
from queue import Queue, Empty
from ..utils.helpers import Singleton
import uuid
from ..utils.execution_resources import persistent_process_semaphore
from ..utils.helpers import Singleton
from .execution_manager_base import ExecutionManagerBase

if sys.platform == "win32":
Expand Down
4 changes: 2 additions & 2 deletions spine_engine/execution_managers/process_execution_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
"""

import sys
import subprocess
import sys
from threading import Thread
from .execution_manager_base import ExecutionManagerBase
from ..utils.execution_resources import one_shot_process_semaphore
from .execution_manager_base import ExecutionManagerBase


class ProcessExecutionManager(ExecutionManagerBase):
Expand Down
6 changes: 3 additions & 3 deletions spine_engine/execution_managers/spine_repl.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@
# this program. If not, see <http://www.gnu.org/licenses/>.
######################################################################################################################

import socketserver
import code
import socket
import socketserver
import threading
import code

try:
import readline
import itertools
import readline

_history_offset = -1
_history_saved_line = ""
Expand Down
9 changes: 5 additions & 4 deletions spine_engine/jumpster.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,13 @@
"""
In-house dagster replacement that also handles jumps.
"""
from collections import namedtuple
from enum import Enum, unique
import queue
import sys
import threading
import queue
from enum import Enum, unique
from collections import namedtuple
from .utils.helpers import serializable_error_info_from_exc_info, ExecutionDirection as ED
from .utils.helpers import ExecutionDirection as ED
from .utils.helpers import serializable_error_info_from_exc_info


@unique
Expand Down
25 changes: 10 additions & 15 deletions spine_engine/project_item/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,31 +10,26 @@
# this program. If not, see <http://www.gnu.org/licenses/>.
######################################################################################################################
""" Provides connection classes for linking project items. """
from contextlib import ExitStack
from dataclasses import asdict, dataclass, field
from multiprocessing import Lock
import os
import subprocess
import tempfile
from contextlib import ExitStack
from multiprocessing import Lock
from datapackage import Package
from spinedb_api import DatabaseMapping, SpineDBAPIError, SpineDBVersionError
from spinedb_api.filters.scenario_filter import SCENARIO_FILTER_TYPE
from spinedb_api.filters.alternative_filter import ALTERNATIVE_FILTER_TYPE
from spinedb_api.purge import purge_url
from spine_engine.project_item.project_item_resource import (
file_resource,
make_cmd_line_arg,
expand_cmd_line_args,
file_resource,
labelled_resource_args,
make_cmd_line_arg,
)
from spine_engine.utils.helpers import (
resolve_current_python_interpreter,
ItemExecutionFinishState,
PartCount,
ExecutionDirection as ED,
)
from spine_engine.utils.helpers import ExecutionDirection as ED
from spine_engine.utils.helpers import ItemExecutionFinishState, PartCount, resolve_current_python_interpreter
from spine_engine.utils.queue_logger import QueueLogger

from spinedb_api import DatabaseMapping, SpineDBAPIError, SpineDBVersionError
from spinedb_api.filters.alternative_filter import ALTERNATIVE_FILTER_TYPE
from spinedb_api.filters.scenario_filter import SCENARIO_FILTER_TYPE
from spinedb_api.purge import purge_url

SUPPORTED_FILTER_TYPES = {ALTERNATIVE_FILTER_TYPE, SCENARIO_FILTER_TYPE}

Expand Down
6 changes: 3 additions & 3 deletions spine_engine/project_item/project_item_resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@
# this program. If not, see <http://www.gnu.org/licenses/>.
######################################################################################################################
""" Provides the ProjectItemResource class. """
import copy
import uuid
from contextlib import contextmanager
import copy
from pathlib import Path
from urllib.parse import urlparse
from urllib.request import url2pathname
import uuid
from spinedb_api.filters.tools import clear_filter_configs
from spinedb_api.spine_db_server import closing_spine_db_server, quick_db_checkout
from spinedb_api.spine_db_client import SpineDBClient
from spinedb_api.spine_db_server import closing_spine_db_server, quick_db_checkout
from ..utils.helpers import PartCount


Expand Down
2 changes: 1 addition & 1 deletion spine_engine/project_item/project_item_specification.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

"""Contains project item specification class."""
import json
from spine_engine.utils.helpers import shorten, gather_leaf_data
from spine_engine.utils.helpers import gather_leaf_data, shorten


class ProjectItemSpecification:
Expand Down
2 changes: 1 addition & 1 deletion spine_engine/server/certificate_creator.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
"""

import os
import sys
import shutil
import sys
import zmq.auth


Expand Down
15 changes: 7 additions & 8 deletions spine_engine/server/engine_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,23 @@
"""
Contains EngineServer class for running a Zero-MQ server with Spine Engine.
"""
import enum
import ipaddress
import json.decoder
import os
import queue
import time
import threading
import ipaddress
import enum
import uuid
import zmq
from zmq.auth.thread import ThreadAuthenticator
from spine_engine.server.util.server_message import ServerMessage
from spine_engine.server.request import Request
from spine_engine.server.remote_execution_service import RemoteExecutionService
from spine_engine.server.persistent_execution_service import PersistentExecutionService
from spine_engine.server.ping_service import PingService
from spine_engine.server.project_extractor_service import ProjectExtractorService
from spine_engine.server.project_retriever_service import ProjectRetrieverService
from spine_engine.server.persistent_execution_service import PersistentExecutionService
from spine_engine.server.project_remover_service import ProjectRemoverService
from spine_engine.server.project_retriever_service import ProjectRetrieverService
from spine_engine.server.remote_execution_service import RemoteExecutionService
from spine_engine.server.request import Request
from spine_engine.server.util.server_message import ServerMessage


class ServerSecurityModel(enum.Enum):
Expand Down
2 changes: 1 addition & 1 deletion spine_engine/server/persistent_execution_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
Contains a class for remote persistent execution manager related actions.
"""

import threading
import json
import threading
import zmq
from spine_engine.server.service_base import ServiceBase

Expand Down
4 changes: 2 additions & 2 deletions spine_engine/server/ping_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
Contains a class for handling ping requests.
"""

import threading
import json
import zmq
import threading
import zmq # pylint: disable=unused-import
from spine_engine.server.service_base import ServiceBase
from spine_engine.server.util.server_message import ServerMessage

Expand Down
6 changes: 3 additions & 3 deletions spine_engine/server/project_extractor_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@
Contains a class for extracting a project ZIP file into a new directory on server.
"""

import os
import json
import os
import threading
import uuid
import zmq
from spine_engine.utils.helpers import get_file_size
import zmq # pylint: disable=unused-import
from spine_engine.server.service_base import ServiceBase
from spine_engine.server.util.server_message import ServerMessage
from spine_engine.server.util.zip_handler import ZipHandler
from spine_engine.utils.helpers import get_file_size


class ProjectExtractorService(threading.Thread, ServiceBase):
Expand Down
2 changes: 1 addition & 1 deletion spine_engine/server/project_remover_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import os
import shutil
import threading
import zmq
import zmq # pylint: disable=unused-import
from spine_engine.server.service_base import ServiceBase


Expand Down
6 changes: 3 additions & 3 deletions spine_engine/server/project_retriever_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@
Contains a class for sending a finished project back to client.
"""

import json
import os
import shutil
import threading
import json
import zmq
from spine_engine.utils.helpers import get_file_size
import zmq # pylint: disable=unused-import
from spine_engine.server.service_base import ServiceBase
from spine_engine.server.util.server_message import ServerMessage
from spine_engine.utils.helpers import get_file_size


class ProjectRetrieverService(threading.Thread, ServiceBase):
Expand Down
2 changes: 1 addition & 1 deletion spine_engine/server/remote_execution_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
import threading
import zmq
from spine_engine import SpineEngine
from spine_engine.utils.helpers import get_file_size
from spine_engine.server.service_base import ServiceBase
from spine_engine.server.util.event_data_converter import EventDataConverter
from spine_engine.utils.helpers import get_file_size


class RemoteExecutionService(threading.Thread, ServiceBase):
Expand Down
Loading

0 comments on commit 8da9d87

Please sign in to comment.