Skip to content

Commit

Permalink
Enforce modern coding style with pyupgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
fabcor-maxiv committed Feb 13, 2025
1 parent 7785179 commit bf455af
Show file tree
Hide file tree
Showing 37 changed files with 67 additions and 114 deletions.
6 changes: 6 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,12 @@ repos:
hooks:
- id: isort

- repo: https://github.com/asottile/pyupgrade
rev: v3.19.1
hooks:
- id: pyupgrade
args: [--py310-plus]

- repo: https://github.com/psf/black-pre-commit-mirror
rev: 25.1.0
hooks:
Expand Down
2 changes: 1 addition & 1 deletion mxcubeweb/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
import sys # noqa: E402
import traceback # noqa: E402
from pathlib import Path # noqa: E402
from unittest import mock # noqa: E402

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

from mxcubeweb.app import MXCUBEApplication as mxcube # noqa: E402
Expand Down
2 changes: 1 addition & 1 deletion mxcubeweb/core/adapter/actuator_adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def __init__(self, ho, *args):
Args:
(object): Hardware object.
"""
super(ActuatorAdapter, self).__init__(ho, *args)
super().__init__(ho, *args)
self._event_rate = 4

@RateLimited(self._event_rate)
Expand Down
4 changes: 2 additions & 2 deletions mxcubeweb/core/adapter/adapter_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ def __init__(self, ho, *args):
(object): Hardware object to mediate for.
(str): The name of the object.
"""
super(ActuatorAdapterBase, self).__init__(ho, *args)
super().__init__(ho, *args)

self._unique = False

Expand Down Expand Up @@ -425,7 +425,7 @@ def _dict_repr(self):
Returns:
(dict): The dictionary.
"""
data = super(ActuatorAdapterBase, self)._dict_repr()
data = super()._dict_repr()

try:
data.update({"value": self.get_value(), "limits": self.limits()})
Expand Down
2 changes: 1 addition & 1 deletion mxcubeweb/core/adapter/beam_adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

class BeamAdapter(ActuatorAdapterBase):
def __init__(self, ho, *args):
super(BeamAdapter, self).__init__(ho, *args)
super().__init__(ho, *args)

def limits(self):
return -1, -1
Expand Down
1 change: 0 additions & 1 deletion mxcubeweb/core/adapter/beamline_adapter.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
import logging

import pydantic
Expand Down
2 changes: 1 addition & 1 deletion mxcubeweb/core/adapter/data_publisher_adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def __init__(self, ho, *args):
Args:
(object): Hardware object.
"""
super(DataPublisherAdapter, self).__init__(ho, *args)
super().__init__(ho, *args)
self._all_data_list = []
self._current_data_list = []
self._current_info = {}
Expand Down
2 changes: 1 addition & 1 deletion mxcubeweb/core/adapter/detector_adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ def __init__(self, ho, *args):
Args:
(object): Hardware object.
"""
super(DetectorAdapter, self).__init__(ho, *args)
super().__init__(ho, *args)
ho.connect("stateChanged", self._state_change)

def _state_change(self, *args, **kwargs):
Expand Down
2 changes: 1 addition & 1 deletion mxcubeweb/core/adapter/diffractometer_adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def __init__(self, ho, *args):
Args:
(object): Hardware object.
"""
super(DiffractometerAdapter, self).__init__(ho, *args)
super().__init__(ho, *args)
ho.connect("stateChanged", self._state_change)
ho.connect("valueChanged", self._state_change)
ho.connect("phaseChanged", self._diffractometer_phase_changed)
Expand Down
2 changes: 1 addition & 1 deletion mxcubeweb/core/adapter/energy_adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def __init__(self, *args):
Args:
(object): Hardware object.
"""
super(EnergyAdapter, self).__init__(*args)
super().__init__(*args)
self._add_adapter("wavelength", self._ho, WavelengthAdapter)
self._type = "ENERGY"

Expand Down
6 changes: 3 additions & 3 deletions mxcubeweb/core/adapter/flux_adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def __init__(self, ho, *args, **kwargs):
Args:
(object): Hardware object.
"""
super(FluxAdapter, self).__init__(ho, *args, **kwargs)
super().__init__(ho, *args, **kwargs)

self._read_only = ho.read_only

Expand All @@ -23,7 +23,7 @@ def __init__(self, ho, *args, **kwargs):

@RateLimited(6)
def _value_change(self, value, **kwargs):
value = "{:.2E}".format(Decimal(self._ho.get_value()))
value = f"{Decimal(self._ho.get_value()):.2E}"
self.value_change(value, **kwargs)

def _set_value(self, value=None):
Expand All @@ -37,7 +37,7 @@ def _get_value(self):
"""
try:
# value = self._ho.current_flux
value = "{:.2E}".format(Decimal(self._ho.get_value()))
value = f"{Decimal(self._ho.get_value()):.2E}"
except Exception:
value = "0"

Expand Down
2 changes: 1 addition & 1 deletion mxcubeweb/core/adapter/motor_adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def __init__(self, ho, *args):
Args:
(object): Hardware object.
"""
super(MotorAdapter, self).__init__(ho, *args)
super().__init__(ho, *args)
ho.connect("valueChanged", self._value_change)
ho.connect("stateChanged", self.state_change)

Expand Down
2 changes: 1 addition & 1 deletion mxcubeweb/core/adapter/nstate_adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def __init__(self, ho, *args):
Args:
(object): Hardware object.
"""
super(NStateAdapter, self).__init__(ho, *args)
super().__init__(ho, *args)
self._value_change_model = HOActuatorValueChangeModel

ho.connect("valueChanged", self._value_change)
Expand Down
2 changes: 1 addition & 1 deletion mxcubeweb/core/adapter/wavelength_adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def __init__(self, ho, *args):
Args:
(object): Hardware object.
"""
super(WavelengthAdapter, self).__init__(ho, *args)
super().__init__(ho, *args)
self._type = "MOTOR"

try:
Expand Down
1 change: 0 additions & 1 deletion mxcubeweb/core/components/beamline.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
import logging

from mxcubecore import HardwareRepository as HWR
Expand Down
1 change: 0 additions & 1 deletion mxcubeweb/core/components/component_base.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
import importlib
import logging

Expand Down
1 change: 0 additions & 1 deletion mxcubeweb/core/components/harvester.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
from __future__ import annotations

import logging
Expand Down
1 change: 0 additions & 1 deletion mxcubeweb/core/components/lims.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
import logging
import math
import re
Expand Down
5 changes: 2 additions & 3 deletions mxcubeweb/core/components/queue.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
# -*- coding: utf-8 -*-
import itertools
import json
import logging
import os
import re
from functools import reduce
from unittest.mock import Mock

from mock import Mock
from mxcubecore import HardwareRepository as HWR
from mxcubecore import queue_entry as qe
from mxcubecore.HardwareObjects.Gphl import GphlQueueEntry
Expand Down Expand Up @@ -259,7 +258,7 @@ def get_queue_state(self):
current = self.app.sample_changer.get_current_sample().get("sampleID", "")
except Exception as ex:
logging.getLogger("MX3.HWR").warning(
"Error retrieving current sample, {0}".format(ex.message)
f"Error retrieving current sample, {ex.message}"
)
current = ""

Expand Down
3 changes: 1 addition & 2 deletions mxcubeweb/core/components/samplechanger.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
import logging

import gevent
Expand Down Expand Up @@ -202,7 +201,7 @@ def mount_sample_clean_up(self, sample):
current_queue = self.app.queue.queue_to_dict()

if sample["location"] != "Manual":
msg = "Mounting sample: %s (%s)" % (
msg = "Mounting sample: {} ({})".format(
sample["location"],
sample.get("sampleName", ""),
)
Expand Down
3 changes: 1 addition & 2 deletions mxcubeweb/core/components/sampleview.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
import logging
from io import StringIO

Expand Down Expand Up @@ -433,7 +432,7 @@ def reject_centring(self):
self.centring_remove_current_point()

def move_to_beam(self, x, y):
msg = "Moving point x: %s, y: %s to beam" % (x, y)
msg = f"Moving point x: {x}, y: {y} to beam"
logging.getLogger("user_level_log").info(msg)

HWR.beamline.diffractometer.move_to_beam(x, y)
Expand Down
5 changes: 2 additions & 3 deletions mxcubeweb/core/components/user/database.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import datetime
import typing

from flask_security import SQLAlchemySessionUserDatastore
from sqlalchemy import create_engine
Expand Down Expand Up @@ -38,12 +37,12 @@ class UserDatastore(SQLAlchemySessionUserDatastore):
def __init__(
self,
*args,
message_model=typing.Type["Message"], # noqa: F821
message_model=type["Message"], # noqa: F821
**kwargs,
):
SQLAlchemySessionUserDatastore.__init__(self, *args, **kwargs)
self._message_model = message_model
self._messages_users_model = typing.Type["MessagesUsers"] # noqa: F821
self._messages_users_model = type["MessagesUsers"] # noqa: F821

def create_message(self, message, from_username, from_nickname, from_host):
return self.put(
Expand Down
5 changes: 2 additions & 3 deletions mxcubeweb/core/components/user/usermanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,7 @@ def update_operator(self, new_login=False):

def is_inhouse_user(self, user_id):
user_id_list = [
"%s%s" % (code, number)
for (code, number) in HWR.beamline.session.in_house_users
f"{code}{number}" for (code, number) in HWR.beamline.session.in_house_users
]

return user_id in user_id_list
Expand Down Expand Up @@ -312,7 +311,7 @@ def login_info(self):
"useSSO": self.app.CONFIG.sso.USE_SSO,
}

res["selectedProposal"] = "%s%s" % (
res["selectedProposal"] = "{}{}".format(
HWR.beamline.session.proposal_code,
HWR.beamline.session.proposal_number,
)
Expand Down
1 change: 0 additions & 1 deletion mxcubeweb/core/components/workflow.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
import base64

from mxcubecore import HardwareRepository as HWR
Expand Down
15 changes: 4 additions & 11 deletions mxcubeweb/core/models/adaptermodels.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,3 @@
# -*- coding: utf-8 -*-
from typing import (
List,
Tuple,
Union,
)

from pydantic.v1 import (
BaseModel,
Field,
Expand All @@ -22,7 +15,7 @@ class HOModel(BaseModel):
description="True if the object can only be read (not manipluated)",
)
attributes: dict = Field({}, description="Data attributes")
commands: Union[dict, list] = Field({}, description="Available methods")
commands: dict | list = Field({}, description="Available methods")

# pyflakes are a bit picky with F821 (Undefined name),
# not even sure "forbid" should ba considered as an undefined name
Expand All @@ -32,7 +25,7 @@ class Config:

class HOActuatorModel(HOModel):
value: float = Field(0, description="Value of actuator (position)")
limits: Tuple[float, float] = Field((-1, -1), description="Limits (min max)")
limits: tuple[float, float] = Field((-1, -1), description="Limits (min max)")


class NStateModel(HOActuatorModel):
Expand All @@ -49,9 +42,9 @@ class HOActuatorValueChangeModel(BaseModel):


class HOBeamRawValueModel(BaseModel):
apertureList: List[str] = Field([0], description="List of available apertures")
apertureList: list[str] = Field([0], description="List of available apertures")
currentAperture: str = Field(0, description="Current aperture label")
position: Tuple[float, float] = Field((0, 0), description="Beam position on OAV")
position: tuple[float, float] = Field((0, 0), description="Beam position on OAV")
shape: str = Field("ellipse", descrption="Beam shape")
size_x: float = Field(
0.01,
Expand Down
Loading

0 comments on commit bf455af

Please sign in to comment.