Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DM-48788: Enable ruff format #1152

Merged
merged 9 commits into from
Feb 7, 2025
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
16 changes: 0 additions & 16 deletions .github/workflows/lint.yaml

This file was deleted.

19 changes: 4 additions & 15 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,14 @@ repos:
- "--unsafe"
- id: end-of-file-fixer
- id: trailing-whitespace
- repo: https://github.com/psf/black-pre-commit-mirror
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)
- id: check-toml
- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version.
rev: v0.9.3
rev: v0.9.5
hooks:
- id: ruff
args: [--fix]
- id: ruff-format
- repo: https://github.com/numpy/numpydoc
rev: "v1.8.0"
hooks:
Expand Down
17 changes: 14 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ target-version = ["py311"]
[tool.isort]
profile = "black"
line_length = 110
known_first_party = ["lsst"]

[tool.lsst_versions]
write_to = "python/lsst/daf/butler/version.py"
Expand Down Expand Up @@ -194,23 +195,33 @@ select = [
"W", # pycodestyle
"D", # pydocstyle
"UP", # pyupgrade
"I", # isort
"RUF022", # sort __all__
]
# Commented out to suppress "unused noqa" in jenkins which has older ruff not
# generating E721.
#extend-select = [
# "RUF100", # Warn about unused noqa
#]
extend-select = [
"RUF100", # Warn about unused noqa
]

[tool.ruff.lint.per-file-ignores]
# parserYacc docstrings can not be fixed. Docstrings are used to define grammar.
"python/lsst/daf/butler/registry/queries/expressions/parser/parserYacc.py" = ["D401", "D403"]

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

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

[tool.ruff.lint.pydocstyle]
convention = "numpy"

[tool.ruff.format]
docstring-code-format = true
# Formatter does not know about indenting.
docstring-code-line-length = 69

[tool.numpydoc_validation]
checks = [
"all", # All except the rules listed below.
Expand Down
11 changes: 7 additions & 4 deletions python/lsst/daf/butler/_butler.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,8 +272,10 @@ def from_config(
"/path/to/repo",
run="u/alice/DM-50000/a",
collections=[
"u/alice/DM-50000/a", "u/bob/DM-49998", "HSC/defaults"
]
"u/alice/DM-50000/a",
"u/bob/DM-49998",
"HSC/defaults",
],
)

This butler will `put` new datasets to the run ``u/alice/DM-50000/a``.
Expand Down Expand Up @@ -1422,8 +1424,9 @@ def export(
with butler.export("exports.yaml") as export:
# Export all flats, but none of the dimension element rows
# (i.e. data ID information) associated with them.
export.saveDatasets(butler.registry.queryDatasets("flat"),
elements=())
export.saveDatasets(
butler.registry.queryDatasets("flat"), elements=()
)
# Export all datasets that start with "deepCoadd_" and all of
# their associated data ID information.
export.saveDatasets(butler.registry.queryDatasets("deepCoadd_*"))
Expand Down
1 change: 1 addition & 0 deletions python/lsst/daf/butler/_butler_config.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/>.

"""Configuration classes specific to the Butler."""

from __future__ import annotations

__all__ = ("ButlerConfig",)
Expand Down
3 changes: 2 additions & 1 deletion python/lsst/daf/butler/_butler_repo_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,10 @@
from typing import Any, ClassVar

import yaml
from lsst.resources import ResourcePath
from pydantic import TypeAdapter, ValidationError

from lsst.resources import ResourcePath

from ._config import Config
from ._utilities.thread_safe_cache import ThreadSafeCache

Expand Down
1 change: 1 addition & 0 deletions python/lsst/daf/butler/_column_type_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@

import astropy.time
import sqlalchemy

from lsst.daf.relation import ColumnTag, sql

from . import ddl
Expand Down
3 changes: 2 additions & 1 deletion python/lsst/daf/butler/_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,10 @@
from typing import IO, TYPE_CHECKING, Any, ClassVar, cast

import yaml
from yaml.representer import Representer

from lsst.resources import ResourcePath, ResourcePathExpression
from lsst.utils import doImportType
from yaml.representer import Representer

yaml.add_representer(defaultdict, Representer.represent_dict)

Expand Down
2 changes: 1 addition & 1 deletion python/lsst/daf/butler/_config_support.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

from __future__ import annotations

__all__ = ("LookupKey", "processLookupConfigs", "processLookupConfigList")
__all__ = ("LookupKey", "processLookupConfigList", "processLookupConfigs")

import logging
import re
Expand Down
3 changes: 2 additions & 1 deletion python/lsst/daf/butler/_dataset_ref.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,10 @@
)

import pydantic
from lsst.utils.classes import immutable
from pydantic import StrictStr

from lsst.utils.classes import immutable

from ._config_support import LookupKey
from ._dataset_type import DatasetType, SerializedDatasetType
from ._named import NamedKeyDict
Expand Down
1 change: 1 addition & 0 deletions python/lsst/daf/butler/_deferredDatasetHandle.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 containing classes used with deferring dataset loading."""

from __future__ import annotations

__all__ = ("DeferredDatasetHandle",)
Expand Down
11 changes: 6 additions & 5 deletions python/lsst/daf/butler/_exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,21 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.

"""Specialized Butler exceptions."""

__all__ = (
"ButlerUserError",
"CalibrationLookupError",
"CollectionCycleError",
"CollectionTypeError",
"DataIdValueError",
"DatasetNotFoundError",
"DimensionNameError",
"DatasetTypeNotSupportedError",
"DimensionNameError",
"EmptyQueryResultError",
"InconsistentDataIdError",
"InvalidQueryError",
"MissingDatasetTypeError",
"MissingCollectionError",
"MissingDatasetTypeError",
"ValidationError",
)

Expand Down Expand Up @@ -228,9 +229,9 @@ class UnknownButlerUserError(ButlerUserError):
UnknownButlerUserError,
)
_USER_ERROR_MAPPING = {e.error_type: e for e in _USER_ERROR_TYPES}
assert len(_USER_ERROR_MAPPING) == len(
_USER_ERROR_TYPES
), "Subclasses of ButlerUserError must have unique 'error_type' property"
assert len(_USER_ERROR_MAPPING) == len(_USER_ERROR_TYPES), (
"Subclasses of ButlerUserError must have unique 'error_type' property"
)


def create_butler_user_error(error_type: str, message: str) -> ButlerUserError:
Expand Down
9 changes: 4 additions & 5 deletions python/lsst/daf/butler/_formatter.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@
from __future__ import annotations

__all__ = (
"FileIntegrityError",
"Formatter",
"FormatterV2",
"FormatterV1inV2",
"FormatterFactory",
"FormatterParameter",
"FormatterNotImplementedError",
"FileIntegrityError",
"FormatterParameter",
"FormatterV1inV2",
"FormatterV2",
)

import contextlib
Expand Down Expand Up @@ -742,7 +742,6 @@ def read_from_possibly_cached_local_file(
self.name(),
),
):

if self.can_read_from_local_file:
result = self.read_from_local_file(
local_uri.ospath, component=component, expected_size=expected_size
Expand Down
4 changes: 2 additions & 2 deletions python/lsst/daf/butler/_named.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@
from __future__ import annotations

__all__ = (
"NameLookupMapping",
"NameMappingSetView",
"NamedKeyDict",
"NamedKeyMapping",
"NamedValueAbstractSet",
"NamedValueMutableSet",
"NamedValueSet",
"NameLookupMapping",
"NameMappingSetView",
)

import contextlib
Expand Down
3 changes: 2 additions & 1 deletion python/lsst/daf/butler/_quantum.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,14 @@

from __future__ import annotations

__all__ = ("Quantum", "SerializedQuantum", "DimensionRecordsAccumulator")
__all__ = ("DimensionRecordsAccumulator", "Quantum", "SerializedQuantum")

import sys
from collections.abc import Iterable, Mapping, MutableMapping, Sequence
from typing import Any

import pydantic

from lsst.utils import doImportType

from ._dataset_ref import DatasetRef, SerializedDatasetRef
Expand Down
1 change: 1 addition & 0 deletions python/lsst/daf/butler/_quantum_backed.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
from typing import TYPE_CHECKING, Any

import pydantic

from lsst.resources import ResourcePath, ResourcePathExpression

from ._butler_config import ButlerConfig
Expand Down
2 changes: 1 addition & 1 deletion python/lsst/daf/butler/_storage_class.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

from __future__ import annotations

__all__ = ("StorageClass", "StorageClassFactory", "StorageClassConfig")
__all__ = ("StorageClass", "StorageClassConfig", "StorageClassFactory")

import builtins
import itertools
Expand Down
2 changes: 1 addition & 1 deletion python/lsst/daf/butler/_topology.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@
from __future__ import annotations

__all__ = (
"TopologicalSpace",
"TopologicalFamily",
"TopologicalRelationshipEndpoint",
"TopologicalSpace",
)

import enum
Expand Down
13 changes: 7 additions & 6 deletions python/lsst/daf/butler/arrow_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@
from __future__ import annotations

__all__ = (
"ToArrow",
"RegionArrowType",
"DateTimeArrowScalar",
"DateTimeArrowType",
"RegionArrowScalar",
"TimespanArrowType",
"RegionArrowType",
"TimespanArrowScalar",
"DateTimeArrowType",
"DateTimeArrowScalar",
"UUIDArrowType",
"TimespanArrowType",
"ToArrow",
"UUIDArrowScalar",
"UUIDArrowType",
)

import uuid
Expand All @@ -45,6 +45,7 @@

import astropy.time
import pyarrow as pa

from lsst.sphgeom import Region

from ._timespan import Timespan
Expand Down
3 changes: 2 additions & 1 deletion python/lsst/daf/butler/cli/butler.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
from __future__ import annotations

__all__ = (
"LoaderCLI",
"ButlerCLI",
"LoaderCLI",
"cli",
"main",
)
Expand All @@ -47,6 +47,7 @@

import click
import yaml

from lsst.resources import ResourcePath
from lsst.utils import doImport
from lsst.utils.introspection import get_full_type_name
Expand Down
2 changes: 1 addition & 1 deletion python/lsst/daf/butler/cli/cliLog.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
from __future__ import annotations

__all__ = (
"PrecisionLogFormatter",
"CliLog",
"PrecisionLogFormatter",
)

import datetime
Expand Down
2 changes: 1 addition & 1 deletion python/lsst/daf/butler/cli/opt/arguments.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@
__all__ = (
"collection_argument",
"collections_argument",
"destination_argument",
"dimensions_argument",
"directory_argument",
"element_argument",
"glob_argument",
"locations_argument",
"repo_argument",
"destination_argument",
)


Expand Down
Loading
Loading