Skip to content

Commit

Permalink
Enforce import order with isort
Browse files Browse the repository at this point in the history
  • Loading branch information
fabcor-maxiv committed Oct 23, 2024
1 parent 7f32b4b commit 88e3c7f
Show file tree
Hide file tree
Showing 51 changed files with 339 additions and 273 deletions.
4 changes: 4 additions & 0 deletions .isort.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[settings]
profile=black
py_version=38
force_grid_wrap=2
5 changes: 5 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ repos:
- --remove-duplicate-keys
- --ignore-pass-after-docstring

- repo: https://github.com/pycqa/isort
rev: 5.13.2
hooks:
- id: isort

- repo: https://github.com/psf/black
rev: 22.8.0
hooks:
Expand Down
1 change: 0 additions & 1 deletion mxcubeweb-server
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,5 @@

from mxcubeweb import main


if __name__ == "__main__":
main()
8 changes: 5 additions & 3 deletions mxcubeweb/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,17 @@
# Disabling E402 (module level import not at top of file)
# for the lines below as we are monkey patching
import argparse # noqa: E402
import mock # noqa: E402
import os # noqa: E402
import sys # noqa: E402
import traceback # noqa: E402
from pathlib import Path # noqa: E402
from mxcubeweb.server import Server as server # noqa: E402

import mock # noqa: E402
from mxcubecore import HardwareRepository as HWR # noqa: E402

from mxcubeweb.app import MXCUBEApplication as mxcube # noqa: E402
from mxcubeweb.config import Config # noqa: E402
from mxcubecore import HardwareRepository as HWR # noqa: E402
from mxcubeweb.server import Server as server # noqa: E402

sys.modules["Qub"] = mock.Mock()
sys.modules["Qub.CTools"] = mock.Mock()
Expand Down
6 changes: 2 additions & 4 deletions mxcubeweb/__version__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,8 @@
)
except ImportError:
# Python3.7 module backport
from importlib_metadata import (
PackageNotFoundError,
version, # pyright: ignore[reportMissingImports]
)
from importlib_metadata import version # pyright: ignore[reportMissingImports]
from importlib_metadata import PackageNotFoundError

__version__: str
try:
Expand Down
35 changes: 16 additions & 19 deletions mxcubeweb/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,38 +3,37 @@
for accessing and manipulating those.
"""

import json
import logging
import os
import sys
import logging
import traceback
import json
import time

from pathlib import Path
import traceback
from logging import StreamHandler
from logging.handlers import TimedRotatingFileHandler
from pathlib import Path

from mxcubecore import ColorFormatter
from mxcubecore import HardwareRepository as HWR
from mxcubecore import removeLoggingHandlers, ColorFormatter
from mxcubecore import queue_entry
from mxcubecore import (
queue_entry,
removeLoggingHandlers,
)
from mxcubecore.utils.conversion import make_table

from mxcubeweb.logging_handler import MX3LoggingHandler
from mxcubeweb.core.util.adapterutils import (
get_adapter_cls_from_hardware_object,
)
from mxcubeweb.core.adapter.adapter_base import AdapterBase
from mxcubeweb.core.components.beamline import Beamline
from mxcubeweb.core.components.chat import Chat
from mxcubeweb.core.components.component_base import import_component
from mxcubeweb.core.components.harvester import Harvester
from mxcubeweb.core.components.lims import Lims
from mxcubeweb.core.components.chat import Chat
from mxcubeweb.core.components.queue import Queue
from mxcubeweb.core.components.samplechanger import SampleChanger
from mxcubeweb.core.components.beamline import Beamline
from mxcubeweb.core.components.sampleview import SampleView
from mxcubeweb.core.components.queue import Queue
from mxcubeweb.core.components.workflow import Workflow
from mxcubeweb.core.models.configmodels import UIComponentModel
from mxcubeweb.core.components.harvester import Harvester

from mxcubeweb.core.util.adapterutils import get_adapter_cls_from_hardware_object
from mxcubeweb.logging_handler import MX3LoggingHandler

removeLoggingHandlers()

Expand Down Expand Up @@ -88,9 +87,7 @@ def init(app):
:return: None
"""
from mxcubeweb.core.adapter.beamline_adapter import (
BeamlineAdapter,
)
from mxcubeweb.core.adapter.beamline_adapter import BeamlineAdapter

fname = os.path.dirname(__file__)
HWR.add_hardware_objects_dirs([os.path.join(fname, "HardwareObjects")])
Expand Down
11 changes: 7 additions & 4 deletions mxcubeweb/config.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
import logging
import os
import sys
import logging
import ruamel.yaml

from pydantic.v1 import BaseModel, ValidationError
import ruamel.yaml
from pydantic.v1 import (
BaseModel,
ValidationError,
)

from mxcubeweb.core.models.configmodels import (
UIPropertiesListModel,
AppConfigModel,
FlaskConfigModel,
MXCUBEAppConfigModel,
UIPropertiesListModel,
)


Expand Down
7 changes: 3 additions & 4 deletions mxcubeweb/core/adapter/actuator_adapter.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
from mxcubeweb.core.adapter.adapter_base import ActuatorAdapterBase
from mxcubeweb.core.util.adapterutils import export
from mxcubeweb.core.util.networkutils import RateLimited

from mxcubeweb.core.models.adaptermodels import (
HOActuatorValueChangeModel,
FloatValueModel,
HOActuatorValueChangeModel,
)
from mxcubeweb.core.util.adapterutils import export
from mxcubeweb.core.util.networkutils import RateLimited


class ActuatorAdapter(ActuatorAdapterBase):
Expand Down
18 changes: 11 additions & 7 deletions mxcubeweb/core/adapter/adapter_base.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
import inspect
import logging
import traceback
import typing
import logging
from typing import Any

from pydantic.v1 import ValidationError, Field, create_model
import gevent
from pydantic.v1 import (
Field,
ValidationError,
create_model,
)

from typing import Any

from mxcubeweb.core.util.adapterutils import (
get_adapter_cls_from_hardware_object,
from mxcubeweb.core.models.adaptermodels import (
HOActuatorModel,
HOModel,
)
from mxcubeweb.core.models.adaptermodels import HOModel, HOActuatorModel
from mxcubeweb.core.util.adapterutils import get_adapter_cls_from_hardware_object


class AdapterBase:
Expand Down
2 changes: 1 addition & 1 deletion mxcubeweb/core/adapter/beam_adapter.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from mxcubeweb.core.adapter.adapter_base import ActuatorAdapterBase
from mxcubeweb.core.util.adapterutils import export
from mxcubeweb.core.models.adaptermodels import (
HOBeamModel,
HOBeamValueModel,
)
from mxcubeweb.core.util.adapterutils import export


class BeamAdapter(ActuatorAdapterBase):
Expand Down
3 changes: 1 addition & 2 deletions mxcubeweb/core/adapter/beamline_action_adapter.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import logging

from enum import Enum

from mxcubeweb.core.adapter.adapter_base import ActuatorAdapterBase
from mxcubeweb.core.models.adaptermodels import (
NStateModel,
HOActuatorValueChangeModel,
NStateModel,
StrValueModel,
)

Expand Down
3 changes: 2 additions & 1 deletion mxcubeweb/core/adapter/energy_adapter.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from mxcubecore import HardwareRepository as HWR

from mxcubeweb.core.adapter.actuator_adapter import ActuatorAdapter
from mxcubeweb.core.adapter.wavelength_adapter import WavelengthAdapter
from mxcubecore import HardwareRepository as HWR


class EnergyAdapter(ActuatorAdapter):
Expand Down
5 changes: 2 additions & 3 deletions mxcubeweb/core/adapter/motor_adapter.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
from mxcubeweb.core.adapter.adapter_base import ActuatorAdapterBase
from mxcubeweb.core.util.networkutils import RateLimited

from mxcubeweb.core.models.adaptermodels import (
HOActuatorValueChangeModel,
FloatValueModel,
HOActuatorValueChangeModel,
)
from mxcubeweb.core.util.networkutils import RateLimited


class MotorAdapter(ActuatorAdapterBase):
Expand Down
4 changes: 2 additions & 2 deletions mxcubeweb/core/adapter/nstate_adapter.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
from enum import Enum
import logging
from enum import Enum

from mxcubeweb.core.adapter.adapter_base import ActuatorAdapterBase
from mxcubeweb.core.models.adaptermodels import (
NStateModel,
HOActuatorValueChangeModel,
NStateModel,
StrValueModel,
)

Expand Down
3 changes: 1 addition & 2 deletions mxcubeweb/core/adapter/wavelength_adapter.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
from mxcubeweb.core.adapter.adapter_base import ActuatorAdapterBase
from mxcubeweb.core.util.networkutils import RateLimited

from mxcubeweb.core.models.adaptermodels import (
FloatValueModel,
HOActuatorValueChangeModel,
)
from mxcubeweb.core.util.networkutils import RateLimited


class WavelengthAdapter(ActuatorAdapterBase):
Expand Down
9 changes: 6 additions & 3 deletions mxcubeweb/core/components/harvester.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
# -*- coding: utf-8 -*-
from __future__ import annotations

import logging

from mxcubecore import HardwareRepository as HWR
from mxcubecore.HardwareObjects.abstract.sample_changer import Crims

from mxcubeweb.core.components.component_base import ComponentBase
from mxcubeweb.core.components.queue import COLLECTED, UNCOLLECTED

from mxcubecore.HardwareObjects.abstract.sample_changer import Crims
from mxcubeweb.core.components.queue import (
COLLECTED,
UNCOLLECTED,
)


# TO CONSIDER:
Expand Down
12 changes: 5 additions & 7 deletions mxcubeweb/core/components/lims.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,20 @@
# -*- coding: utf-8 -*-
import sys
import logging
import copy
import io
import json
import logging
import math
import re
import json
import sys

from flask import session
from flask_login import current_user
from mxcubecore import HardwareRepository as HWR
from mxcubecore.model import queue_model_objects as qmo

from mxcubeweb.core.components.component_base import ComponentBase
from mxcubeweb.core.util import fsutils

from flask import session
from flask_login import current_user


VALID_SAMPLE_NAME_REGEXP = re.compile("^[a-zA-Z0-9:+_-]+$")


Expand Down
22 changes: 10 additions & 12 deletions mxcubeweb/core/components/queue.py
Original file line number Diff line number Diff line change
@@ -1,27 +1,25 @@
# -*- coding: utf-8 -*-
import os
import json
import itertools
import json
import logging
import os
import re
from functools import reduce

from mock import Mock

from mxcubecore import HardwareRepository as HWR

from mxcubecore.model import queue_model_objects as qmo
from mxcubecore.model import queue_model_enumerables as qme

from mxcubecore import queue_entry as qe
from mxcubecore.queue_entry.base_queue_entry import QUEUE_ENTRY_STATUS

from mxcubecore.HardwareObjects.Gphl import GphlQueueEntry
from mxcubecore.model import queue_model_enumerables as qme
from mxcubecore.model import queue_model_objects as qmo
from mxcubecore.queue_entry.base_queue_entry import QUEUE_ENTRY_STATUS

from mxcubeweb.core.components.component_base import ComponentBase
from mxcubeweb.core.util.convertutils import str_to_camel, str_to_snake
from mxcubeweb.core.models.generic import SimpleNameValue

from functools import reduce
from mxcubeweb.core.util.convertutils import (
str_to_camel,
str_to_snake,
)

# Important: same constants as in constants.js
QUEUE_PAUSED = "QueuePaused"
Expand Down
11 changes: 7 additions & 4 deletions mxcubeweb/core/components/samplechanger.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
# -*- coding: utf-8 -*-
import logging
import time
import gevent

from mxcubecore import queue_entry
import gevent
from mxcubecore import HardwareRepository as HWR
from mxcubecore import queue_entry

from mxcubeweb.core.components.component_base import ComponentBase
from mxcubeweb.core.components.queue import COLLECTED, UNCOLLECTED
from mxcubeweb.core.components.queue import (
COLLECTED,
UNCOLLECTED,
)


# TO CONSIDER:
Expand Down Expand Up @@ -414,8 +417,8 @@ def _gripper_changed(self):

# Disabling C901 function is too complex (19)
def queue_mount_sample(view, data_model, centring_done_cb, async_result): # noqa: C901
from mxcubeweb.routes import signals
from mxcubeweb.app import MXCUBEApplication as mxcube
from mxcubeweb.routes import signals

HWR.beamline.sample_view.clear_all()
logging.getLogger("user_level_log").info("Loading sample ...")
Expand Down
Loading

0 comments on commit 88e3c7f

Please sign in to comment.