Skip to content

Commit

Permalink
Ruff autofixes + enable ruff UP in pre-commit
Browse files Browse the repository at this point in the history
  • Loading branch information
fritzm committed Nov 4, 2023
1 parent c1dc3e7 commit 824568f
Show file tree
Hide file tree
Showing 52 changed files with 165 additions and 166 deletions.
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ select = [
"F", # pyflakes
"N", # pep8-naming
"W", # pycodestyle
"UP", # pyupgrade
]
target-version = "py311"
extend-select = [
Expand Down
3 changes: 2 additions & 1 deletion src/lsst/cmservice/cli/commands.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import json
from typing import Any, Sequence, TypeVar
from collections.abc import Sequence
from typing import Any, TypeVar

import click
import structlog
Expand Down
2 changes: 1 addition & 1 deletion src/lsst/cmservice/cli/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def convert( # pylint: disable=inconsistent-return-statements
keyvalue_pairs = value.rstrip(";").split(";")
result_dict = {}
for pair in keyvalue_pairs:
key, values = [item.strip() for item in pair.split("=")]
key, values = (item.strip() for item in pair.split("="))
converted_values = []
for value_ in values.split(","):
value_ = value_.strip()
Expand Down
4 changes: 2 additions & 2 deletions src/lsst/cmservice/common/bash.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ async def check_stamp_file(
"""
if not os.path.exists(stamp_file):
return None
with open(stamp_file, "rt", encoding="utf-8") as fin:
with open(stamp_file, encoding="utf-8") as fin:
fields = yaml.safe_load(fin)
status = StatusEnum[fields["status"]]
return status
Expand Down Expand Up @@ -102,7 +102,7 @@ async def write_bash_script(
except OSError:
pass

with open(script_url, "wt", encoding="utf-8") as fout:
with open(script_url, "w", encoding="utf-8") as fout:
if prepend:
fout.write(f"{prepend}\n")
if fake:
Expand Down
2 changes: 1 addition & 1 deletion src/lsst/cmservice/common/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import contextlib
import os
import sys
from typing import Iterator
from collections.abc import Iterator


@contextlib.contextmanager
Expand Down
21 changes: 11 additions & 10 deletions src/lsst/cmservice/db/campaign.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import annotations

from typing import TYPE_CHECKING, Any, Iterable, List, Optional
from collections.abc import Iterable
from typing import TYPE_CHECKING, Any

from sqlalchemy import JSON
from sqlalchemy.ext.asyncio import async_scoped_session
Expand Down Expand Up @@ -45,15 +46,15 @@ class Campaign(Base, ElementMixin):
status: Mapped[StatusEnum] = mapped_column(default=StatusEnum.waiting)
superseded: Mapped[bool] = mapped_column(default=False)
handler: Mapped[str | None] = mapped_column()
data: Mapped[Optional[dict | list]] = mapped_column(type_=JSON)
child_config: Mapped[Optional[dict | list]] = mapped_column(type_=JSON)
collections: Mapped[Optional[dict | list]] = mapped_column(type_=JSON)
spec_aliases: Mapped[Optional[dict | list]] = mapped_column(type_=JSON)

spec_block_: Mapped["SpecBlock"] = relationship("SpecBlock", viewonly=True)
parent_: Mapped["Production"] = relationship("Production", viewonly=True)
s_: Mapped[List["Step"]] = relationship("Step", viewonly=True)
scripts_: Mapped[List["Script"]] = relationship("Script", viewonly=True)
data: Mapped[dict | list | None] = mapped_column(type_=JSON)
child_config: Mapped[dict | list | None] = mapped_column(type_=JSON)
collections: Mapped[dict | list | None] = mapped_column(type_=JSON)
spec_aliases: Mapped[dict | list | None] = mapped_column(type_=JSON)

spec_block_: Mapped[SpecBlock] = relationship("SpecBlock", viewonly=True)
parent_: Mapped[Production] = relationship("Production", viewonly=True)
s_: Mapped[list[Step]] = relationship("Step", viewonly=True)
scripts_: Mapped[list[Script]] = relationship("Script", viewonly=True)

@hybrid_property
def db_id(self) -> DbId:
Expand Down
8 changes: 4 additions & 4 deletions src/lsst/cmservice/db/element.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from __future__ import annotations

from typing import TYPE_CHECKING, Any, List
from typing import TYPE_CHECKING, Any

from sqlalchemy.ext.asyncio import async_scoped_session

Expand Down Expand Up @@ -33,7 +33,7 @@ async def get_scripts(
script_name: str | None = None,
remaining_only: bool = False,
skip_superseded: bool = True,
) -> List["Script"]:
) -> list[Script]:
"""Return the `Script`s associated to an element
Parameters
Expand Down Expand Up @@ -73,7 +73,7 @@ async def get_jobs(
session: async_scoped_session,
remaining_only: bool = False,
skip_superseded: bool = True,
) -> List["Job"]:
) -> list[Job]:
"""Return the `Job`s associated to an element
Parameters
Expand Down Expand Up @@ -175,7 +175,7 @@ async def rescue_job(
async def mark_job_rescued(
self,
session: async_scoped_session,
) -> List["Job"]:
) -> list[Job]:
"""Mark jobs as `rescued` once one of their siblings is `accepted`
Parameters
Expand Down
15 changes: 8 additions & 7 deletions src/lsst/cmservice/db/group.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from typing import TYPE_CHECKING, Any, Iterable, List, Optional
from collections.abc import Iterable
from typing import TYPE_CHECKING, Any

from sqlalchemy import JSON
from sqlalchemy.ext.asyncio import async_scoped_session
Expand Down Expand Up @@ -41,10 +42,10 @@ class Group(Base, ElementMixin):
status: Mapped[StatusEnum] = mapped_column(default=StatusEnum.waiting) # Status flag
superseded: Mapped[bool] = mapped_column(default=False) # Has this been supersede
handler: Mapped[str | None] = mapped_column()
data: Mapped[Optional[dict | list]] = mapped_column(type_=JSON)
child_config: Mapped[Optional[dict | list]] = mapped_column(type_=JSON)
collections: Mapped[Optional[dict | list]] = mapped_column(type_=JSON)
spec_aliases: Mapped[Optional[dict | list]] = mapped_column(type_=JSON)
data: Mapped[dict | list | None] = mapped_column(type_=JSON)
child_config: Mapped[dict | list | None] = mapped_column(type_=JSON)
collections: Mapped[dict | list | None] = mapped_column(type_=JSON)
spec_aliases: Mapped[dict | list | None] = mapped_column(type_=JSON)

spec_block_: Mapped["SpecBlock"] = relationship("SpecBlock", viewonly=True)
c_: Mapped["Campaign"] = relationship(
Expand All @@ -63,8 +64,8 @@ class Group(Base, ElementMixin):
)

parent_: Mapped["Step"] = relationship("Step", viewonly=True)
scripts_: Mapped[List["Script"]] = relationship("Script", viewonly=True)
jobs_: Mapped[List["Job"]] = relationship("Job", viewonly=True)
scripts_: Mapped[list["Script"]] = relationship("Script", viewonly=True)
jobs_: Mapped[list["Job"]] = relationship("Job", viewonly=True)

@hybrid_property
def db_id(self) -> DbId:
Expand Down
36 changes: 18 additions & 18 deletions src/lsst/cmservice/db/job.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from __future__ import annotations

from typing import TYPE_CHECKING, Any, List, Optional
from typing import TYPE_CHECKING, Any

from sqlalchemy import JSON
from sqlalchemy.ext.asyncio import async_scoped_session
Expand Down Expand Up @@ -47,29 +47,29 @@ class Job(Base, ElementMixin):
status: Mapped[StatusEnum] = mapped_column(default=StatusEnum.waiting)
superseded: Mapped[bool] = mapped_column(default=False)
handler: Mapped[str | None] = mapped_column()
data: Mapped[Optional[dict | list]] = mapped_column(type_=JSON)
child_config: Mapped[Optional[dict | list]] = mapped_column(type_=JSON)
collections: Mapped[Optional[dict | list]] = mapped_column(type_=JSON)
spec_aliases: Mapped[Optional[dict | list]] = mapped_column(type_=JSON)
wms_job_id: Mapped[Optional[int]] = mapped_column()
stamp_url: Mapped[Optional[str]] = mapped_column()

spec_block_: Mapped["SpecBlock"] = relationship("SpecBlock", viewonly=True)
s_: Mapped["Step"] = relationship(
data: Mapped[dict | list | None] = mapped_column(type_=JSON)
child_config: Mapped[dict | list | None] = mapped_column(type_=JSON)
collections: Mapped[dict | list | None] = mapped_column(type_=JSON)
spec_aliases: Mapped[dict | list | None] = mapped_column(type_=JSON)
wms_job_id: Mapped[int | None] = mapped_column()
stamp_url: Mapped[str | None] = mapped_column()

spec_block_: Mapped[SpecBlock] = relationship("SpecBlock", viewonly=True)
s_: Mapped[Step] = relationship(
"Step",
primaryjoin="Job.parent_id==Group.id",
secondary="join(Group, Step)",
secondaryjoin="Group.parent_id==Step.id",
viewonly=True,
)
c_: Mapped["Campaign"] = relationship(
c_: Mapped[Campaign] = relationship(
"Campaign",
primaryjoin="Job.parent_id==Group.id",
secondary="join(Group, Step).join(Campaign)",
secondaryjoin="and_(Group.parent_id==Step.id, Step.parent_id==Campaign.id) ",
viewonly=True,
)
p_: Mapped["Production"] = relationship(
p_: Mapped[Production] = relationship(
"Production",
primaryjoin="Job.parent_id==Group.id",
secondary="join(Group, Step).join(Campaign).join(Production)",
Expand All @@ -80,18 +80,18 @@ class Job(Base, ElementMixin):
") ",
viewonly=True,
)
parent_: Mapped["Group"] = relationship("Group", viewonly=True)
scripts_: Mapped[List["Script"]] = relationship("Script", viewonly=True)
tasks_: Mapped[List["TaskSet"]] = relationship("TaskSet", viewonly=True)
products_: Mapped[List["ProductSet"]] = relationship("ProductSet", viewonly=True)
errors_: Mapped[List["PipetaskError"]] = relationship(
parent_: Mapped[Group] = relationship("Group", viewonly=True)
scripts_: Mapped[list[Script]] = relationship("Script", viewonly=True)
tasks_: Mapped[list[TaskSet]] = relationship("TaskSet", viewonly=True)
products_: Mapped[list[ProductSet]] = relationship("ProductSet", viewonly=True)
errors_: Mapped[list[PipetaskError]] = relationship(
"PipetaskError",
primaryjoin="Job.id==TaskSet.job_id",
secondary="join(TaskSet, PipetaskError)",
secondaryjoin="PipetaskError.task_id==TaskSet.id",
viewonly=True,
)
wms_reports_: Mapped[List["WmsTaskReport"]] = relationship("WmsTaskReport", viewonly=True)
wms_reports_: Mapped[list[WmsTaskReport]] = relationship("WmsTaskReport", viewonly=True)

@hybrid_property
def db_id(self) -> DbId:
Expand Down
4 changes: 2 additions & 2 deletions src/lsst/cmservice/db/pipetask_error.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import TYPE_CHECKING, Optional
from typing import TYPE_CHECKING

from sqlalchemy import JSON
from sqlalchemy.orm import Mapped, mapped_column, relationship
Expand Down Expand Up @@ -26,7 +26,7 @@ class PipetaskError(Base, RowMixin):
task_id: Mapped[int] = mapped_column(ForeignKey("task_set.id", ondelete="CASCADE"), index=True)
quanta: Mapped[str] = mapped_column()
diagnostic_message: Mapped[str] = mapped_column()
data_id: Mapped[Optional[dict | list]] = mapped_column(type_=JSON)
data_id: Mapped[dict | list | None] = mapped_column(type_=JSON)

job_: Mapped["Job"] = relationship(
"Job",
Expand Down
4 changes: 2 additions & 2 deletions src/lsst/cmservice/db/pipetask_error_type.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import re
from typing import TYPE_CHECKING, List
from typing import TYPE_CHECKING

from sqlalchemy.orm import Mapped, mapped_column, relationship

Expand All @@ -23,7 +23,7 @@ class PipetaskErrorType(Base, RowMixin):
task_name: Mapped[str] = mapped_column()
diagnostic_message: Mapped[str] = mapped_column(unique=True)

errors_: Mapped[List["PipetaskError"]] = relationship("PipetaskError", viewonly=True)
errors_: Mapped[list["PipetaskError"]] = relationship("PipetaskError", viewonly=True)

def __repr__(self) -> str:
s = f"Id={self.id}\n"
Expand Down
5 changes: 3 additions & 2 deletions src/lsst/cmservice/db/production.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from typing import TYPE_CHECKING, Iterable, List
from collections.abc import Iterable
from typing import TYPE_CHECKING

from sqlalchemy.ext.asyncio import async_scoped_session
from sqlalchemy.ext.hybrid import hybrid_property
Expand All @@ -21,7 +22,7 @@ class Production(Base, RowMixin):
id: Mapped[int] = mapped_column(primary_key=True)
name: Mapped[str] = mapped_column(index=True, unique=True)

c_: Mapped[List["Campaign"]] = relationship("Campaign", viewonly=True)
c_: Mapped[list["Campaign"]] = relationship("Campaign", viewonly=True)

@hybrid_property
def db_id(self) -> DbId:
Expand Down
12 changes: 6 additions & 6 deletions src/lsst/cmservice/db/queue.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from __future__ import annotations

from datetime import datetime, timedelta
from typing import TYPE_CHECKING, Any, Optional
from typing import TYPE_CHECKING, Any

import pause
from sqlalchemy import JSON, DateTime
Expand Down Expand Up @@ -34,7 +34,7 @@ class Queue(Base, NodeMixin):
time_updated: Mapped[datetime] = mapped_column(type_=DateTime)
time_finished: Mapped[datetime | None] = mapped_column(type_=DateTime, default=None)
interval: Mapped[float] = mapped_column(default=300.0)
options: Mapped[Optional[dict | list]] = mapped_column(type_=JSON)
options: Mapped[dict | list | None] = mapped_column(type_=JSON)

element_level: Mapped[LevelEnum] = mapped_column()
element_id: Mapped[int] = mapped_column()
Expand All @@ -43,10 +43,10 @@ class Queue(Base, NodeMixin):
g_id: Mapped[int | None] = mapped_column(ForeignKey("group.id", ondelete="CASCADE"), index=True)
j_id: Mapped[int | None] = mapped_column(ForeignKey("job.id", ondelete="CASCADE"), index=True)

c_: Mapped["Campaign"] = relationship("Campaign", viewonly=True)
s_: Mapped["Step"] = relationship("Step", viewonly=True)
g_: Mapped["Group"] = relationship("Group", viewonly=True)
j_: Mapped["Job"] = relationship("Job", viewonly=True)
c_: Mapped[Campaign] = relationship("Campaign", viewonly=True)
s_: Mapped[Step] = relationship("Step", viewonly=True)
g_: Mapped[Group] = relationship("Group", viewonly=True)
j_: Mapped[Job] = relationship("Job", viewonly=True)

@hybrid_property
def element_db_id(self) -> DbId:
Expand Down
3 changes: 2 additions & 1 deletion src/lsst/cmservice/db/row.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import annotations

from typing import TYPE_CHECKING, Any, Sequence, TypeVar
from collections.abc import Sequence
from typing import TYPE_CHECKING, Any, TypeVar

from fastapi import HTTPException
from sqlalchemy import select
Expand Down
23 changes: 12 additions & 11 deletions src/lsst/cmservice/db/script.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import annotations

from typing import TYPE_CHECKING, Any, List, Optional, Sequence
from collections.abc import Sequence
from typing import TYPE_CHECKING, Any

from sqlalchemy import JSON, and_, select
from sqlalchemy.ext.asyncio import async_scoped_session
Expand Down Expand Up @@ -50,20 +51,20 @@ class Script(Base, NodeMixin):
method: Mapped[ScriptMethod] = mapped_column(default=ScriptMethod.default)
superseded: Mapped[bool] = mapped_column(default=False) # Has this been supersede
handler: Mapped[str | None] = mapped_column()
data: Mapped[Optional[dict | list]] = mapped_column(type_=JSON)
child_config: Mapped[Optional[dict | list]] = mapped_column(type_=JSON)
collections: Mapped[Optional[dict | list]] = mapped_column(type_=JSON)
data: Mapped[dict | list | None] = mapped_column(type_=JSON)
child_config: Mapped[dict | list | None] = mapped_column(type_=JSON)
collections: Mapped[dict | list | None] = mapped_column(type_=JSON)
script_url: Mapped[str | None] = mapped_column()
stamp_url: Mapped[str | None] = mapped_column()
log_url: Mapped[str | None] = mapped_column()

spec_block_: Mapped["SpecBlock"] = relationship("SpecBlock", viewonly=True)
c_: Mapped["Campaign"] = relationship("Campaign", viewonly=True)
s_: Mapped["Step"] = relationship("Step", viewonly=True)
g_: Mapped["Group"] = relationship("Group", viewonly=True)
j_: Mapped["Job"] = relationship("Job", viewonly=True)
errors_: Mapped[List["ScriptError"]] = relationship("ScriptError", viewonly=True)
prereqs_: Mapped[List["ScriptDependency"]] = relationship(
spec_block_: Mapped[SpecBlock] = relationship("SpecBlock", viewonly=True)
c_: Mapped[Campaign] = relationship("Campaign", viewonly=True)
s_: Mapped[Step] = relationship("Step", viewonly=True)
g_: Mapped[Group] = relationship("Group", viewonly=True)
j_: Mapped[Job] = relationship("Job", viewonly=True)
errors_: Mapped[list[ScriptError]] = relationship("ScriptError", viewonly=True)
prereqs_: Mapped[list[ScriptDependency]] = relationship(
"ScriptDependency",
foreign_keys="ScriptDependency.depend_id",
viewonly=True,
Expand Down
4 changes: 2 additions & 2 deletions src/lsst/cmservice/db/script_dependency.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ class ScriptDependency(Base, RowMixin):
prereq_id: Mapped[int] = mapped_column(ForeignKey("script.id", ondelete="CASCADE"), index=True)
depend_id: Mapped[int] = mapped_column(ForeignKey("script.id", ondelete="CASCADE"), index=True)

prereq_: Mapped["Script"] = relationship("Script", viewonly=True, foreign_keys=[prereq_id])
depend_: Mapped["Script"] = relationship("Script", back_populates="prereqs_", foreign_keys=[depend_id])
prereq_: Mapped[Script] = relationship("Script", viewonly=True, foreign_keys=[prereq_id])
depend_: Mapped[Script] = relationship("Script", back_populates="prereqs_", foreign_keys=[depend_id])

def __repr__(self) -> str:
return f"ScriptDependency {self.prereq_id}: {self.depend_id}"
Expand Down
8 changes: 4 additions & 4 deletions src/lsst/cmservice/db/script_template.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from __future__ import annotations

import os
from typing import TYPE_CHECKING, Any, Optional
from typing import TYPE_CHECKING, Any

import yaml
from sqlalchemy import JSON
Expand All @@ -28,9 +28,9 @@ class ScriptTemplate(Base, RowMixin):
spec_id: Mapped[int] = mapped_column(ForeignKey("specification.id", ondelete="CASCADE"), index=True)
name: Mapped[str] = mapped_column(index=True)
fullname: Mapped[str] = mapped_column(unique=True)
data: Mapped[Optional[dict | list]] = mapped_column(type_=JSON)
data: Mapped[dict | list | None] = mapped_column(type_=JSON)

spec_: Mapped["Specification"] = relationship("Specification", viewonly=True)
spec_: Mapped[Specification] = relationship("Specification", viewonly=True)

def __repr__(self) -> str:
return f"ScriptTemplate {self.id}: {self.fullname} {self.data}"
Expand Down Expand Up @@ -84,7 +84,7 @@ async def load( # pylint: disable=too-many-arguments
Newly created `ScriptTemplate`
"""
full_file_path = os.path.abspath(os.path.expandvars(file_path))
with open(full_file_path, "r", encoding="utf-8") as fin:
with open(full_file_path, encoding="utf-8") as fin:
data = yaml.safe_load(fin)

new_row = await cls.create_row(session, name=name, spec_id=spec_id, spec_name=spec_name, data=data)
Expand Down
Loading

0 comments on commit 824568f

Please sign in to comment.