Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 8 additions & 46 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,53 +45,15 @@ repos:
name: Formatting the pyproject.toml file
additional_dependencies: ["tox>=4.9"]

# Automatic source code formatting
- repo: https://github.com/psf/black
rev: 24.3.0 # Released 2024-03-15
# Format and lint using Ruff
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.14.0
hooks:
- id: black
name: Formatting Python scripts according to Black
args: [--safe, --quiet]

# Automatically sort imports
- repo: https://github.com/PyCQA/isort
rev: 5.13.2 # Released 2023-12-13
hooks:
- id: isort
name: Tidying Python imports via Isort
args: [
#'-a', 'from __future__ import annotations', # 3.7-3.11
"--rm",
"from __future__ import absolute_import", # -3.0
"--rm",
"from __future__ import division", # -3.0
"--rm",
"from __future__ import generator_stop", # -3.7
"--rm",
"from __future__ import generators", # -2.3
"--rm",
"from __future__ import nested_scopes", # -2.2
"--rm",
"from __future__ import print_function", # -3.0
"--rm",
"from __future__ import unicode_literals", # -3.0
"--rm",
"from __future__ import with_statement", # -2.6
]

# Linting
- repo: https://github.com/PyCQA/flake8
# Release history: https://flake8.pycqa.org/en/latest/release-notes/index.html
rev: 7.0.0 # Released 2024-01-05
hooks:
- id: flake8
name: Running Flake8 linter on Python files
additional_dependencies: [
# Added Flake8-pyproject plugin for .toml compatibility
"Flake8-pyproject==1.2.3", # Released 2023-03-21
# flake8-comprehensions URL: https://github.com/adamchainz/flake8-comprehensions
"flake8-comprehensions==3.14.0", # Released 2023-07-10
]
- id: ruff
name: Running Ruff linter
args: ["--fix"]
- id: ruff-format
name: Running Ruff formatter

# Type checking
- repo: https://github.com/pre-commit/mirrors-mypy
Expand Down
63 changes: 18 additions & 45 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -121,53 +121,26 @@ zip-safe = false
[tool.setuptools.packages.find]
where = ["src", "tests"]

[tool.isort]
profile = "black"

[tool.flake8]
# Flake8-pyproject allows TOML file settings to be read into Flake8
# URL: https://pypi.org/project/Flake8-pyproject/
select = [
[tool.ruff]
line-length = 88
lint.extend-ignore = ["E203", "E266", "E501", "E731", "E741"]
lint.select = [
"C4",
"E401",
"E711",
"E712",
"E713",
"E714",
"E721",
"E722",
"E901",
"F401",
"F402",
"F403",
"F405",
"F541",
"F631",
"F632",
"F633",
"F811",
"F812",
"F821",
"F822",
"F841",
"F901",
"W191",
"W291",
"W292",
"W293",
"W602",
"W603",
"W604",
"W605",
"W606",
]
ignore = [
"E203",
"E266",
"E501",
"W503",
"E4", "E7", "E9",
"F",
"I",
"W6",
]
max-line-length = "88"
fix = true

[tool.ruff.lint.isort]
known-first-party = ["murfey"]
combine-as-imports = true

[tool.ruff.format]
quote-style="double"
indent-style="space"
line-ending="auto"

[tool.pyproject-fmt]
inputs = "pyproject.toml"
Expand Down
2 changes: 0 additions & 2 deletions src/murfey/cli/generate_route_manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ def is_implicitly_resolved(value: str) -> bool:


def find_routers(name: str) -> dict[str, APIRouter]:

def _extract_routers_from_module(module: ModuleType):
routers = {}
for name, obj in inspect.getmembers(module):
Expand Down Expand Up @@ -115,7 +114,6 @@ def _extract_routers_from_module(module: ModuleType):


def get_route_manifest(routers: dict[str, APIRouter]):

manifest = {}

for router_name, router in routers.items():
Expand Down
1 change: 0 additions & 1 deletion src/murfey/cli/inject_spa_processing.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,6 @@ def run():
/ str(ppath.stem + "_motion_corrected.mrc")
)
if proc_params:

detached_ids = [c.id for c in collected_ids]

if not mrc_out.parent.exists():
Expand Down
3 changes: 1 addition & 2 deletions src/murfey/cli/spa_ispyb_messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@
DataCollectionGroup,
ProcessingJob,
)
from sqlmodel import Session as MurfeySession
from sqlmodel import create_engine, select
from sqlmodel import Session as MurfeySession, create_engine, select

from murfey.client.contexts.spa import _get_xml_list_index
from murfey.server.feedback import _murfey_id, _register
Expand Down
88 changes: 0 additions & 88 deletions src/murfey/cli/transfer.py

This file was deleted.

3 changes: 0 additions & 3 deletions src/murfey/client/contexts/clem.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ def _get_image_elements(root: ET.Element) -> List[ET.Element]:
def _find_elements_recursively(
node: ET.Element,
) -> Generator[ET.Element, None, None]:

# Find items labelled "Element" under current node
elem_list = node.findall("./Children/Element")
if len(elem_list) < 1: # Try alternative path for top-level of XML tree
Expand Down Expand Up @@ -103,7 +102,6 @@ def post_transfer(
environment: Optional[MurfeyInstanceEnvironment] = None,
**kwargs,
) -> bool:

super().post_transfer(transferred_file, environment=environment, **kwargs)

# Process files generated by "auto-save" acquisition mode
Expand Down Expand Up @@ -188,7 +186,6 @@ def post_transfer(

# Process XLIF files
if transferred_file.suffix == ".xlif":

# Skip processing of "_histo" histogram XLIF files
if transferred_file.stem.endswith("_histo"):
logger.debug(
Expand Down
1 change: 0 additions & 1 deletion src/murfey/client/tui/progress.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ def _get_pulse_segments(
def __rich_console__(
self, console: Console, options: ConsoleOptions
) -> RenderResult:

width = min(self.width or options.max_width, options.max_width)
ascii = options.ascii_only
if self.pulse:
Expand Down
3 changes: 1 addition & 2 deletions src/murfey/client/tui/screens.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,6 @@ def __init__(
self._context = SPAModularContext

def compose(self):

machine_data = capture_get(
base_url=str(self.app._environment.url.geturl()),
router_name="session_control.router",
Expand Down Expand Up @@ -1013,7 +1012,7 @@ def compose(self):
name_root += st
if dest_num:
dest = str(
dest_path.parent / f"{name_root}{dest_num+1}"
dest_path.parent / f"{name_root}{dest_num + 1}"
)
else:
dest = str(dest_path.parent / f"{name_root}2")
Expand Down
8 changes: 3 additions & 5 deletions src/murfey/server/api/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@
from murfey.server.murfey_db import murfey_db, url
from murfey.util.api import url_path_for
from murfey.util.config import get_security_config
from murfey.util.db import MurfeyUser as User
from murfey.util.db import Session as MurfeySession
from murfey.util.db import MurfeyUser as User, Session as MurfeySession

# Set up logger
logger = getLogger("murfey.server.api.auth")
Expand Down Expand Up @@ -147,7 +146,7 @@ def validate_session_against_visit(session_id: int, visit: str):


async def validate_instrument_token(
token: Annotated[str, Depends(instrument_oauth2_scheme)]
token: Annotated[str, Depends(instrument_oauth2_scheme)],
):
"""
Used by the backend routers to check the incoming instrument server token.
Expand Down Expand Up @@ -334,7 +333,6 @@ def validate_user(username: str, password: str) -> bool:


def create_access_token(data: dict, token: str = "") -> str:

# If authenticating with password, auth URL needs a 'mint_session_token' endpoint
if security_config.auth_type == "password":
if auth_url and data.get("session"):
Expand Down Expand Up @@ -420,6 +418,6 @@ async def mint_session_token(session_id: MurfeySessionIDFrontend, db=murfey_db):

@router.get("/validate_token")
async def simple_token_validation(
token: Annotated[str, Depends(validate_instrument_token)]
token: Annotated[str, Depends(validate_instrument_token)],
):
return {"valid": True}
8 changes: 4 additions & 4 deletions src/murfey/server/api/bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ def parse_cygwin_request(
raise ValueError(f"{request_path!r} is not a valid request path")

try:
url = f'{find_cygwin_mirror()}{quote(request_path, safe="/")}'
url = f"{find_cygwin_mirror()}{quote(request_path, safe='/')}"
except Exception:
raise HTTPException(
status_code=503, detail="Could not identify a suitable Cygwin mirror"
Expand Down Expand Up @@ -533,7 +533,7 @@ def get_msys2_environment_index(
raise ValueError(f"{system!r} is not a valid msys2 environment")

# Construct URL to main MSYS repo and get response
arch_url = f'{msys2_url}/{quote(system, safe="/")}'
arch_url = f"{msys2_url}/{quote(system, safe='/')}"
response = http_session.get(arch_url)

# Parse and rewrite package index content
Expand Down Expand Up @@ -579,7 +579,7 @@ def get_msys2_package_index(

# Construct URL to main MSYS repo and get response
package_list_url = (
f'{msys2_url}/{quote(system, safe="/")}/{quote(environment, safe="/")}'
f"{msys2_url}/{quote(system, safe='/')}/{quote(environment, safe='/')}"
)
response = http_session.get(package_list_url)
return Response(
Expand Down Expand Up @@ -617,7 +617,7 @@ def get_msys2_package_file(
raise ValueError(f"{package!r} is not a valid package name")

# Construct URL to main MSYS repo and get response
package_url = f'{msys2_url}/{quote(system, safe="/")}/{quote(environment, safe="/")}/{quote(package, safe="/")}'
package_url = f"{msys2_url}/{quote(system, safe='/')}/{quote(environment, safe='/')}/{quote(package, safe='/')}"
response = http_session.get(package_url)
if response.status_code != 200:
raise HTTPException(status_code=response.status_code)
Expand Down
3 changes: 1 addition & 2 deletions src/murfey/server/api/clem.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
CLEMImageStack,
CLEMLIFFile,
CLEMTIFFFile,
Session as MurfeySession,
)
from murfey.util.db import Session as MurfeySession

# Set up logger
logger = getLogger("murfey.server.api.clem")
Expand Down Expand Up @@ -409,7 +409,6 @@ def register_clem_metadata(
associated_stacks: list[Path] = [],
db: Session = murfey_db,
):

# Return database entry if it already exists
try:
clem_metadata: CLEMImageMetadata = get_db_entry(
Expand Down
Loading