Skip to content

Commit

Permalink
Lint - line length
Browse files Browse the repository at this point in the history
  • Loading branch information
marcus-oscarsson committed Oct 12, 2023
1 parent 1b78cc9 commit b053038
Show file tree
Hide file tree
Showing 34 changed files with 479 additions and 157 deletions.
6 changes: 5 additions & 1 deletion mxcube3/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,11 @@ def parse_args(argv):
"-el",
"--enabled-loggers",
dest="enabled_logger_list",
help="Which loggers to use, default is to use all loggers ([exception_logger, hwr_logger, mx3_hwr_logger, user_logger, queue_logger])",
help=(
"Which loggers to use, default is to use all loggers"
" ([exception_logger, hwr_logger, mx3_hwr_logger,"
" user_logger, queue_logger])"
),
default=[
"exception_logger",
"hwr_logger",
Expand Down
37 changes: 30 additions & 7 deletions mxcube3/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@
from mxcubecore.utils.conversion import make_table

from mxcube3.logging_handler import MX3LoggingHandler
from mxcube3.core.util.adapterutils import get_adapter_cls_from_hardware_object
from mxcube3.core.util.adapterutils import (
get_adapter_cls_from_hardware_object,
)
from mxcube3.core.adapter.adapter_base import AdapterBase
from mxcube3.core.components.component_base import import_component
from mxcube3.core.components.lims import Lims
Expand Down Expand Up @@ -85,7 +87,9 @@ def init(app):
:return: None
"""
from mxcube3.core.adapter.beamline_adapter import BeamlineAdapter
from mxcube3.core.adapter.beamline_adapter import (
BeamlineAdapter,
)

fname = os.path.dirname(__file__)
HWR.add_hardware_objects_dirs([os.path.join(fname, "HardwareObjects")])
Expand Down Expand Up @@ -256,7 +260,13 @@ def __init__(self):

@staticmethod
def init(
server, allow_remote, ra_timeout, log_fpath, log_level, enabled_logger_list, cfg
server,
allow_remote,
ra_timeout,
log_fpath,
log_level,
enabled_logger_list,
cfg,
):
"""
Initializes application wide variables, sample video stream, and applies
Expand Down Expand Up @@ -438,16 +448,26 @@ def init_state_storage():
def get_ui_properties():
# Add type information to each component retrieved from the beamline adapter
# (either via config or via mxcubecore.beamline)
for _item_name, item_data in MXCUBEApplication.CONFIG.app.ui_properties.items():
for (
_item_name,
item_data,
) in MXCUBEApplication.CONFIG.app.ui_properties.items():
for component_data in item_data.components:
try:
mxcore = MXCUBEApplication.mxcubecore
adapter = mxcore.get_adapter(component_data.attribute)
adapter_cls_name = type(adapter).__name__
value_type = adapter.adapter_type
except AttributeError:
msg = f"{component_data.attribute} not accessible via Beamline object. "
msg += f"Verify that beamline.{component_data.attribute} is valid and/or "
msg = (
f"{component_data.attribute} not accessible"
" via Beamline object. "
)
msg += (
"Verify that"
f" beamline.{component_data.attribute} is"
" valid and/or "
)
msg += f"{component_data.attribute} accessible via get_role "
msg += "check ui.yaml configuration file. "
msg += "(attribute will NOT be avilable in UI)"
Expand All @@ -465,7 +485,10 @@ def get_ui_properties():

return {
key: value.dict()
for (key, value) in MXCUBEApplication.CONFIG.app.ui_properties.items()
for (
key,
value,
) in MXCUBEApplication.CONFIG.app.ui_properties.items()
}

@staticmethod
Expand Down
11 changes: 8 additions & 3 deletions mxcube3/core/adapter/adapter_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@

from typing import Any

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


Expand Down Expand Up @@ -232,7 +234,9 @@ def attributes(self):
model["return"].validate({"return": value})
except pydantic.ValidationError:
logging.getLogger("MX3.HWR").exception(
f"Return value of {self._name}.{attribute_name} is of wrong type"
"Return value of"
f" {self._name}.{attribute_name} is of wrong"
" type"
)
_attributes[attribute_name] = {}
else:
Expand Down Expand Up @@ -425,7 +429,8 @@ def _dict_repr(self):
f"Could not get dictionary representation of {self._ho.name()}"
)
logging.getLogger("MX3.HWR").error(
f"Check status of {self._ho.name()}, object is offline, in fault or returns unexpected value !"
f"Check status of {self._ho.name()}, object is"
" offline, in fault or returns unexpected value !"
)

self._available = False
Expand Down
17 changes: 14 additions & 3 deletions mxcube3/core/adapter/beam_adapter.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
from mxcube3.core.adapter.adapter_base import ActuatorAdapterBase
from mxcube3.core.util.adapterutils import export
from mxcube3.core.models.adaptermodels import HOBeamModel, HOBeamValueModel
from mxcube3.core.models.adaptermodels import (
HOBeamModel,
HOBeamValueModel,
)


class BeamAdapter(ActuatorAdapterBase):
Expand Down Expand Up @@ -29,7 +32,12 @@ def _get_aperture(self) -> tuple:
def _get_value(self) -> HOBeamValueModel:
beam_ho = self._ho

beam_info_dict = {"position": [], "shape": "", "size_x": 0, "size_y": 0}
beam_info_dict = {
"position": [],
"shape": "",
"size_x": 0,
"size_y": 0,
}
sx, sy, shape, _label = beam_ho.get_value()

if beam_ho is not None:
Expand All @@ -45,7 +53,10 @@ def _get_value(self) -> HOBeamValueModel:
aperture_list, current_aperture = self._get_aperture()

beam_info_dict.update(
{"apertureList": aperture_list, "currentAperture": current_aperture}
{
"apertureList": aperture_list,
"currentAperture": current_aperture,
}
)

return HOBeamValueModel(**{"value": beam_info_dict})
Expand Down
8 changes: 4 additions & 4 deletions mxcube3/core/adapter/wavelength_adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ def _get_value(self) -> FloatValueModel:
"""
try:
return FloatValueModel(**{"value": self._ho.get_wavelength()})
except (AttributeError, TypeError):
raise ValueError("Could not get value")
except (AttributeError, TypeError) as ex:
raise ValueError("Could not get value") from ex

def state(self):
"""
Expand All @@ -87,8 +87,8 @@ def limits(self):
"""
try:
return self._ho.get_wavelength_limits()
except (AttributeError, TypeError):
raise ValueError("Could not get limits")
except (AttributeError, TypeError) as ex:
raise ValueError("Could not get limits") from ex

def read_only(self):
"""
Expand Down
39 changes: 29 additions & 10 deletions mxcube3/core/components/beamline.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,19 @@ def init_signals(self):
+ HWR.beamline.beamline_actions.get_annotated_commands()
)
for cmd in cmds:
cmd.connect("commandBeginWaitReply", signals.beamline_action_start)
cmd.connect("commandReplyArrived", signals.beamline_action_done)
cmd.connect(
"commandBeginWaitReply",
signals.beamline_action_start,
)
cmd.connect(
"commandReplyArrived",
signals.beamline_action_done,
)
cmd.connect("commandReady", signals.beamline_action_done)
cmd.connect("commandFailed", signals.beamline_action_failed)
cmd.connect(
"commandFailed",
signals.beamline_action_failed,
)
else:
logging.getLogger("MX3.HWR").error(
"beamline_actions hardware object is not defined"
Expand Down Expand Up @@ -269,18 +278,20 @@ def beamline_run_action(self, name, params):
try:
cmd.emit("commandBeginWaitReply", name)
logging.getLogger("user_level_log").info(
"Starting %s(%s)", cmd.name(), ", ".join(map(str, params))
"Starting %s(%s)",
cmd.name(),
", ".join(map(str, params)),
)
cmd(*params)
except Exception:
except Exception as ex:
err = str(sys.exc_info()[1])
raise Exception(str(err))
raise Exception(str(err)) from ex
# Annotated command
try:
HWR.beamline.beamline_actions.execute_command(name, params)
except Exception:
except Exception as ex:
msg = "Action cannot run: command '%s' does not exist" % name
raise Exception(msg)
raise Exception(msg) from ex

def get_beam_info(self):
"""
Expand All @@ -291,7 +302,12 @@ def get_beam_info(self):
:rtype: dict
"""
beam = HWR.beamline.beam
beam_info_dict = {"position": [], "shape": "", "size_x": 0, "size_y": 0}
beam_info_dict = {
"position": [],
"shape": "",
"size_x": 0,
"size_y": 0,
}
sx, sy, shape, _label = beam.get_value()

if beam is not None:
Expand All @@ -307,7 +323,10 @@ def get_beam_info(self):
aperture_list, current_aperture = self.get_aperture()

beam_info_dict.update(
{"apertureList": aperture_list, "currentAperture": current_aperture}
{
"apertureList": aperture_list,
"currentAperture": current_aperture,
}
)

return beam_info_dict
Expand Down
6 changes: 5 additions & 1 deletion mxcube3/core/components/gphl_workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@ def submit_parameters(self, params):
def test_workflow_dialog(self, wf):
dialog = {
"properties": {
"name": {"title": "Task name", "type": "string", "minLength": 2},
"name": {
"title": "Task name",
"type": "string",
"minLength": 2,
},
"description": {
"title": "Description",
"type": "string",
Expand Down
11 changes: 8 additions & 3 deletions mxcube3/core/components/lims.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,14 +237,18 @@ def lims_login(self, loginID, password, create_session):
session["proposal_list"].append(dummy)

login_res["proposalList"] = session["proposal_list"]
login_res["status"] = {"code": "ok", "msg": "Successful login"}
login_res["status"] = {
"code": "ok",
"msg": "Successful login",
}
else:
try:
login_res = HWR.beamline.lims.login(
loginID, password, create_session=create_session
)
proposal = HWR.beamline.lims.get_proposal(
login_res["Proposal"]["code"], login_res["Proposal"]["number"]
login_res["Proposal"]["code"],
login_res["Proposal"]["number"],
)

except Exception:
Expand Down Expand Up @@ -430,7 +434,8 @@ def synch_with_lims(self):
] + ":%02d" % int(sample_info["sampleLocation"])
except Exception:
logging.getLogger("MX3.HWR").info(
"[LIMS] Could not parse sample loaction from LIMS, (perhaps not set ?)"
"[LIMS] Could not parse sample loaction from"
" LIMS, (perhaps not set ?)"
)
else:
sample_info["lims_location"] = lims_location
Expand Down
Loading

0 comments on commit b053038

Please sign in to comment.