Skip to content

Commit

Permalink
Merge pull request #468 from lsst/tickets/DM-48788
Browse files Browse the repository at this point in the history
DM-48788: Switch to ruff format
  • Loading branch information
timj authored Feb 7, 2025
2 parents f992f36 + e6d62a5 commit e484a58
Show file tree
Hide file tree
Showing 57 changed files with 143 additions and 112 deletions.
18 changes: 3 additions & 15 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,13 @@ repos:
- id: end-of-file-fixer
- id: trailing-whitespace
- id: check-toml
- repo: https://github.com/psf/black
rev: 25.1.0
hooks:
- id: black
# It is recommended to specify the latest version of Python
# supported by your project here, or alternatively use
# pre-commit's default_language_version, see
# https://pre-commit.com/#top_level-default_language_version
language_version: python3.11
- repo: https://github.com/pycqa/isort
rev: 6.0.0
hooks:
- id: isort
name: isort (python)
- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version.
rev: v0.9.3
rev: v0.9.4
hooks:
- id: ruff
args: [--fix]
- id: ruff-format
- repo: https://github.com/numpy/numpydoc
rev: "v1.8.0"
hooks:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import numpy as np

import lsst.afw.image as afwImage
import lsst.afw.table as afwTable
import lsst.pex.config as pexConfig
import lsst.pipe.base as pipeBase
import numpy as np
from lsst.geom import Point2I
from lsst.pipe.base import connectionTypes

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
from collections.abc import Mapping

import numpy as np

import lsst.afw.image as afwImage
import lsst.afw.table as afwTable
import lsst.pex.config as pexConfig
import lsst.pipe.base as pipeBase
import numpy as np
from lsst.geom import Point2I
from lsst.pipe.base import connectionTypes

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
from collections.abc import Mapping

import numpy as np

import lsst.afw.image as afwImage
import lsst.afw.math as afwMath
import lsst.afw.table as afwTable
import lsst.pex.config as pexConfig
import lsst.pipe.base as pipeBase
import numpy as np
from lsst.geom import Point2I
from lsst.pipe.base import connectionTypes

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
from collections.abc import Mapping

import numpy as np

import lsst.afw.image as afwImage
import lsst.afw.math as afwMath
import lsst.afw.table as afwTable
import lsst.pex.config as pexConfig
import lsst.pipe.base as pipeBase
import numpy as np
from lsst.geom import Point2I
from lsst.pipe.base import connectionTypes

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import math
from collections.abc import Mapping

import numpy as np

import lsst.afw.image as afwImage
import lsst.afw.math as afwMath
import lsst.afw.table as afwTable
import lsst.pex.config as pexConfig
import lsst.pipe.base as pipeBase
import numpy as np
from lsst.geom import Point2I
from lsst.pipe.base import connectionTypes

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import math
from collections.abc import Mapping

import numpy as np

import lsst.afw.image as afwImage
import lsst.afw.math as afwMath
import lsst.afw.table as afwTable
import lsst.pex.config as pexConfig
import lsst.pipe.base as pipeBase
import numpy as np
from lsst.geom import Point2I
from lsst.pipe.base import connectionTypes

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import math
from collections.abc import Mapping

import numpy as np

import lsst.afw.image as afwImage
import lsst.afw.math as afwMath
import lsst.afw.table as afwTable
import lsst.pex.config as pexConfig
import lsst.pipe.base as pipeBase
import numpy as np
from lsst.geom import Point2I
from lsst.pipe.base import connectionTypes

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@
import operator
from collections.abc import Mapping

import numpy as np

import lsst.afw.image as afwImage
import lsst.afw.math as afwMath
import lsst.afw.table as afwTable
import lsst.pex.config as pexConfig
import lsst.pipe.base as pipeBase
import numpy as np
from lsst.geom import Point2I
from lsst.pipe.base import connectionTypes

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@
import operator
from collections.abc import Mapping

import numpy as np

import lsst.afw.image as afwImage
import lsst.afw.math as afwMath
import lsst.afw.table as afwTable
import lsst.pex.config as pexConfig
import lsst.pipe.base as pipeBase
import numpy as np
from lsst.geom import Point2I
from lsst.pipe.base import connectionTypes

Expand Down
3 changes: 2 additions & 1 deletion doc/_static/pipe_base/PipelineTask_Examples/apertureTask.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import numpy as np

import lsst.afw.image as afwImage
import lsst.afw.table as afwTable
import lsst.pex.config as pexConfig
import lsst.pipe.base as pipeBase
import numpy as np
from lsst.geom import Point2I
from lsst.pipe.base import connectionTypes # noqa: F401

Expand Down
7 changes: 7 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ target-version = ["py311"]
[tool.isort]
profile = "black"
line_length = 110
known_first_party = ["lsst"]

[tool.lsst_versions]
write_to = "python/lsst/pipe/base/version.py"
Expand Down Expand Up @@ -167,8 +168,14 @@ select = [
"N", # pep8-naming
"W", # pycodestyle
"D", # pydocstyle
"I", # isort
"RUF022", # sort __all__
"UP", # pyupgrade
]

[tool.ruff.lint.isort]
known-first-party = ["lsst"]

[tool.ruff.lint.pycodestyle]
max-doc-length = 79

Expand Down
8 changes: 4 additions & 4 deletions python/lsst/pipe/base/_datasetQueryConstraints.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,9 @@ class DatasetQueryConstraintVariant(Iterable, Protocol):
`fromExpression` class method given a valid string.
"""

ALL: "type[_ALL]"
OFF: "type[_OFF]"
LIST: "type[_LIST]"
ALL: type[_ALL]
OFF: type[_OFF]
LIST: type[_LIST]

@classmethod
def __subclasshook__(cls, subclass):
Expand All @@ -77,7 +77,7 @@ def __subclasshook__(cls, subclass):
return False

@classmethod
def fromExpression(cls, expression: str) -> "DatasetQueryConstraintVariant":
def fromExpression(cls, expression: str) -> DatasetQueryConstraintVariant:
"""Select and return the correct Variant that corresponds to the input
expression.
Expand Down
1 change: 1 addition & 0 deletions python/lsst/pipe/base/_dataset_handle.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
from typing import Any, cast

from frozendict import frozendict

from lsst.daf.butler import (
DataCoordinate,
DataId,
Expand Down
4 changes: 2 additions & 2 deletions python/lsst/pipe/base/_instrument.py
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ def formatCollectionTimestamp(timestamp: str | datetime.datetime) -> str:
if not isinstance(timestamp, datetime.datetime):
raise TypeError(f"Unexpected date/time object: {timestamp!r}.")
if timestamp.tzinfo is not None:
timestamp = timestamp.astimezone(datetime.timezone.utc)
timestamp = timestamp.astimezone(datetime.UTC)
return f"{timestamp:%Y%m%dT%H%M%S}Z"

@staticmethod
Expand All @@ -415,7 +415,7 @@ def makeCollectionTimestamp() -> str:
formatted : `str`
Standardized string form of the current time.
"""
return Instrument.formatCollectionTimestamp(datetime.datetime.now(tz=datetime.timezone.utc))
return Instrument.formatCollectionTimestamp(datetime.datetime.now(tz=datetime.UTC))

def makeDefaultRawIngestRunName(self) -> str:
"""Make the default instrument-specific run collection string for raw
Expand Down
1 change: 1 addition & 0 deletions python/lsst/pipe/base/_quantumContext.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
from typing import Any

import astropy.units as u

from lsst.daf.butler import (
DataCoordinate,
DatasetProvenance,
Expand Down
10 changes: 5 additions & 5 deletions python/lsst/pipe/base/_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,14 @@
from ._task_metadata import GetSetDictMetadata, NestedMetadataDict

__all__ = (
"QuantumSuccessCaveats",
"UnprocessableDataError",
"AlgorithmError",
"AnnotatedPartialOutputsError",
"InvalidQuantumError",
"NoWorkFound",
"UpstreamFailureNoWorkFound",
"QuantumSuccessCaveats",
"RepeatableQuantumError",
"AlgorithmError",
"InvalidQuantumError",
"UnprocessableDataError",
"UpstreamFailureNoWorkFound",
)


Expand Down
4 changes: 2 additions & 2 deletions python/lsst/pipe/base/_task_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@
# along with this program. If not, see <https://www.gnu.org/licenses/>.

__all__ = [
"TaskMetadata",
"SetDictMetadata",
"GetDictMetadata",
"GetSetDictMetadata",
"NestedMetadataDict",
"SetDictMetadata",
"TaskMetadata",
]

import itertools
Expand Down
10 changes: 5 additions & 5 deletions python/lsst/pipe/base/automatic_connection_constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,16 @@

__all__ = (
"CONFIG_INIT_OUTPUT_CONNECTION_NAME",
"CONFIG_INIT_OUTPUT_TEMPLATE",
"CONFIG_INIT_OUTPUT_STORAGE_CLASS",
"PACKAGES_INIT_OUTPUT_NAME",
"PACKAGES_INIT_OUTPUT_STORAGE_CLASS",
"CONFIG_INIT_OUTPUT_TEMPLATE",
"LOG_OUTPUT_CONNECTION_NAME",
"LOG_OUTPUT_TEMPLATE",
"LOG_OUTPUT_STORAGE_CLASS",
"LOG_OUTPUT_TEMPLATE",
"METADATA_OUTPUT_CONNECTION_NAME",
"METADATA_OUTPUT_TEMPLATE",
"METADATA_OUTPUT_STORAGE_CLASS",
"METADATA_OUTPUT_TEMPLATE",
"PACKAGES_INIT_OUTPUT_NAME",
"PACKAGES_INIT_OUTPUT_STORAGE_CLASS",
)


Expand Down
4 changes: 2 additions & 2 deletions python/lsst/pipe/base/caching_limited_butler.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@
__all__ = ["CachingLimitedButler"]

import logging
from collections.abc import Set
from typing import Any, Iterable
from collections.abc import Iterable, Set
from typing import Any

from lsst.daf.butler import (
DatasetId,
Expand Down
1 change: 1 addition & 0 deletions python/lsst/pipe/base/cli/cmd/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
from typing import Any

import click

from lsst.daf.butler.cli.opt import (
dataset_type_option,
options_file_option,
Expand Down
1 change: 1 addition & 0 deletions python/lsst/pipe/base/configOverrides.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.

"""Module which defines ConfigOverrides class and related methods."""

from __future__ import annotations

__all__ = ["ConfigOverrides"]
Expand Down
2 changes: 1 addition & 1 deletion python/lsst/pipe/base/connectionTypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
`PipelineTaskConnections` class.
"""

__all__ = ["InitInput", "InitOutput", "Input", "PrerequisiteInput", "Output", "BaseConnection"]
__all__ = ["BaseConnection", "InitInput", "InitOutput", "Input", "Output", "PrerequisiteInput"]

import dataclasses
from collections.abc import Callable, Iterable, Sequence
Expand Down
7 changes: 4 additions & 3 deletions python/lsst/pipe/base/connections.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@
"InputQuantizedConnection",
"OutputQuantizedConnection",
"PipelineTaskConnections",
"QuantizedConnection",
"ScalarError",
"iterConnections",
"ScalarError",
"QuantizedConnection",
"iterConnections",
]

import dataclasses
Expand Down Expand Up @@ -334,7 +334,8 @@ def __call__(cls, *, config: PipelineTaskConfig | None = None) -> PipelineTaskCo
# by looping over the keys of the defaultTemplates dict specified at
# class declaration time.
templateValues = {
name: getattr(config.connections, name) for name in cls.defaultTemplates # type: ignore
name: getattr(config.connections, name)
for name in cls.defaultTemplates # type: ignore
}

# We now assemble a mapping of all connection instances keyed by
Expand Down
3 changes: 2 additions & 1 deletion python/lsst/pipe/base/execution_reports.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@
from __future__ import annotations

__all__ = (
"DatasetTypeExecutionReport",
"QuantumGraphExecutionReport",
"TaskExecutionReport",
"DatasetTypeExecutionReport",
"lookup_quantum_data_id",
)

Expand All @@ -36,6 +36,7 @@

import networkx
import yaml

from lsst.daf.butler import Butler, DataCoordinate, DatasetRef, Quantum
from lsst.resources import ResourcePathExpression

Expand Down
2 changes: 1 addition & 1 deletion python/lsst/pipe/base/graph/_implDetails.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from __future__ import annotations

__all__ = ("_DatasetTracker", "DatasetTypeName")
__all__ = ("DatasetTypeName", "_DatasetTracker")

from collections import defaultdict
from typing import NewType
Expand Down
2 changes: 1 addition & 1 deletion python/lsst/pipe/base/graph/_loadHelpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ def _readBytes(self, start: int, stop: int) -> bytes:
self._resourceHandle.seek(start)
return self._resourceHandle.read(stop - start)

def __enter__(self) -> "LoadHelper":
def __enter__(self) -> LoadHelper:
if isinstance(self.uri, BinaryIO | BytesIO | BufferedRandom):
self._resourceHandle = self.uri
else:
Expand Down
Loading

0 comments on commit e484a58

Please sign in to comment.