From cf6faba60d13755a70b5d8c62a25f95e553b0b36 Mon Sep 17 00:00:00 2001 From: Tim Jenness Date: Sat, 8 Feb 2025 14:00:19 -0700 Subject: [PATCH 1/6] Declare lsst as known first party for isort --- pyproject.toml | 1 + python/lsst/obs/base/_fitsRawFormatterBase.py | 3 ++- python/lsst/obs/base/_instrument.py | 2 ++ python/lsst/obs/base/cli/cmd/commands.py | 1 + python/lsst/obs/base/cli/doc/butlerCmdDocGen.py | 1 + python/lsst/obs/base/ingest.py | 1 + python/lsst/obs/base/instrument_tests.py | 3 ++- python/lsst/obs/base/makeRawVisitInfoViaObsInfo.py | 1 + python/lsst/obs/base/tests.py | 1 + python/lsst/obs/base/yamlCamera.py | 5 +++-- tests/test_butlerFits.py | 1 + tests/test_fitsRawFormatter.py | 7 ++++--- tests/test_makeRawVisitInfoViaObsInfo.py | 3 ++- 13 files changed, 22 insertions(+), 8 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index f8eb89a3..f4805d81 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -50,6 +50,7 @@ target-version = ["py311"] [tool.isort] profile = "black" line_length = 110 +known_first_party = ["lsst"] [tool.lsst_versions] write_to = "python/lsst/obs/base/version.py" diff --git a/python/lsst/obs/base/_fitsRawFormatterBase.py b/python/lsst/obs/base/_fitsRawFormatterBase.py index 38cc4146..5d264a2d 100644 --- a/python/lsst/obs/base/_fitsRawFormatterBase.py +++ b/python/lsst/obs/base/_fitsRawFormatterBase.py @@ -25,10 +25,11 @@ from abc import abstractmethod from typing import Any +from astro_metadata_translator import ObservationInfo, fix_header + import lsst.afw.fits import lsst.afw.geom import lsst.afw.image -from astro_metadata_translator import ObservationInfo, fix_header from lsst.daf.butler import FileDescriptor, FormatterNotImplementedError from lsst.resources import ResourcePath from lsst.utils.classes import cached_getter diff --git a/python/lsst/obs/base/_instrument.py b/python/lsst/obs/base/_instrument.py index 9ebf067d..79b0f7fe 100644 --- a/python/lsst/obs/base/_instrument.py +++ b/python/lsst/obs/base/_instrument.py @@ -33,6 +33,7 @@ from typing import TYPE_CHECKING, Any, cast import astropy.time + from lsst.afw.cameraGeom import Camera from lsst.daf.butler import ( Butler, @@ -52,6 +53,7 @@ if TYPE_CHECKING: from astro_metadata_translator import MetadataTranslator, ObservationInfo + from lsst.daf.butler import Registry from .filters import FilterDefinitionCollection diff --git a/python/lsst/obs/base/cli/cmd/commands.py b/python/lsst/obs/base/cli/cmd/commands.py index 682407b2..586301fb 100644 --- a/python/lsst/obs/base/cli/cmd/commands.py +++ b/python/lsst/obs/base/cli/cmd/commands.py @@ -20,6 +20,7 @@ # along with this program. If not, see . import click + from lsst.daf.butler.cli.opt import ( config_file_option, config_option, diff --git a/python/lsst/obs/base/cli/doc/butlerCmdDocGen.py b/python/lsst/obs/base/cli/doc/butlerCmdDocGen.py index 82f783cc..35ec3d4e 100644 --- a/python/lsst/obs/base/cli/doc/butlerCmdDocGen.py +++ b/python/lsst/obs/base/cli/doc/butlerCmdDocGen.py @@ -24,6 +24,7 @@ """ import click + from lsst.utils import doImport from .. import cmd diff --git a/python/lsst/obs/base/ingest.py b/python/lsst/obs/base/ingest.py index 398efa51..1f509d02 100644 --- a/python/lsst/obs/base/ingest.py +++ b/python/lsst/obs/base/ingest.py @@ -32,6 +32,7 @@ from astro_metadata_translator import MetadataTranslator, ObservationInfo, merge_headers from astro_metadata_translator.indexing import process_index_data, process_sidecar_data + from lsst.afw.fits import readMetadata from lsst.daf.butler import ( Butler, diff --git a/python/lsst/obs/base/instrument_tests.py b/python/lsst/obs/base/instrument_tests.py index 6515f0f9..0c1891d2 100644 --- a/python/lsst/obs/base/instrument_tests.py +++ b/python/lsst/obs/base/instrument_tests.py @@ -41,6 +41,8 @@ from functools import lru_cache from typing import TYPE_CHECKING, Any, ClassVar +from pydantic import BaseModel + from lsst.daf.butler import CollectionType, DatasetType, RegistryConfig from lsst.daf.butler.formatters.yaml import YamlFormatter from lsst.daf.butler.registry.sql_registry import SqlRegistry @@ -48,7 +50,6 @@ from lsst.obs.base.yamlCamera import makeCamera from lsst.resources import ResourcePath from lsst.utils.introspection import get_full_type_name -from pydantic import BaseModel from .utils import createInitialSkyWcsFromBoresight diff --git a/python/lsst/obs/base/makeRawVisitInfoViaObsInfo.py b/python/lsst/obs/base/makeRawVisitInfoViaObsInfo.py index 9308dbf6..4f18f2db 100755 --- a/python/lsst/obs/base/makeRawVisitInfoViaObsInfo.py +++ b/python/lsst/obs/base/makeRawVisitInfoViaObsInfo.py @@ -40,6 +40,7 @@ ErfaWarning = None from astro_metadata_translator import MetadataTranslator, ObservationInfo + from lsst.afw.coord import Observatory, Weather from lsst.afw.image import RotType, VisitInfo from lsst.daf.base import DateTime diff --git a/python/lsst/obs/base/tests.py b/python/lsst/obs/base/tests.py index 58f793a1..31a69dc7 100644 --- a/python/lsst/obs/base/tests.py +++ b/python/lsst/obs/base/tests.py @@ -33,6 +33,7 @@ import logging import numpy as np + from lsst.afw.cameraGeom.utils import calcRawCcdBBox from lsst.afw.image import Exposure diff --git a/python/lsst/obs/base/yamlCamera.py b/python/lsst/obs/base/yamlCamera.py index 1da448e2..fa2cc6ad 100755 --- a/python/lsst/obs/base/yamlCamera.py +++ b/python/lsst/obs/base/yamlCamera.py @@ -21,11 +21,12 @@ from functools import lru_cache +import numpy as np +import yaml + import lsst.afw.cameraGeom as cameraGeom import lsst.afw.geom as afwGeom import lsst.geom as geom -import numpy as np -import yaml from lsst.afw.cameraGeom import Amplifier, Camera, ReadoutCorner __all__ = ["makeCamera"] diff --git a/tests/test_butlerFits.py b/tests/test_butlerFits.py index bf970481..d50839c7 100644 --- a/tests/test_butlerFits.py +++ b/tests/test_butlerFits.py @@ -28,6 +28,7 @@ import uuid import astropy.table + import lsst.afw.cameraGeom.testUtils # for test asserts injected into TestCase import lsst.afw.image import lsst.pex.config diff --git a/tests/test_fitsRawFormatter.py b/tests/test_fitsRawFormatter.py index ddb93106..e54f83d1 100644 --- a/tests/test_fitsRawFormatter.py +++ b/tests/test_fitsRawFormatter.py @@ -22,6 +22,10 @@ import unittest import astropy.units as u +from astro_metadata_translator import FitsTranslator, StubTranslator +from astro_metadata_translator.translators.helpers import tracking_from_degree_headers +from astropy.coordinates import Angle + import lsst.afw.geom import lsst.afw.math import lsst.daf.base @@ -29,9 +33,6 @@ import lsst.geom import lsst.resources import lsst.utils.tests -from astro_metadata_translator import FitsTranslator, StubTranslator -from astro_metadata_translator.translators.helpers import tracking_from_degree_headers -from astropy.coordinates import Angle from lsst.afw.cameraGeom import makeUpdatedDetector from lsst.afw.cameraGeom.testUtils import CameraWrapper, DetectorWrapper from lsst.obs.base import ( diff --git a/tests/test_makeRawVisitInfoViaObsInfo.py b/tests/test_makeRawVisitInfoViaObsInfo.py index 634c5bce..c427ef11 100644 --- a/tests/test_makeRawVisitInfoViaObsInfo.py +++ b/tests/test_makeRawVisitInfoViaObsInfo.py @@ -22,10 +22,11 @@ import unittest import astropy.units as u -import lsst.afw.image import numpy as np from astro_metadata_translator import FitsTranslator, ObservationInfo, StubTranslator from astropy.time import Time + +import lsst.afw.image from lsst.daf.base import DateTime from lsst.obs.base import MakeRawVisitInfoViaObsInfo From 97cd452966e67d574583e699ed729d4833d569fa Mon Sep 17 00:00:00 2001 From: Tim Jenness Date: Sat, 8 Feb 2025 14:00:55 -0700 Subject: [PATCH 2/6] Enable ruff isort --- pyproject.toml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/pyproject.toml b/pyproject.toml index f4805d81..90aa0af3 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -86,11 +86,15 @@ select = [ "W", # pycodestyle "D", # pydocstyle "UP", # pyupgrade + "I", # isort ] extend-select = [ "RUF100", # Warn about unused noqa ] +[tool.ruff.lint.isort] +known-first-party = ["lsst"] + [tool.ruff.lint.pycodestyle] max-doc-length = 79 From 9b22d8774e8163bdec59e3b752f30600f930f475 Mon Sep 17 00:00:00 2001 From: Tim Jenness Date: Sat, 8 Feb 2025 14:02:49 -0700 Subject: [PATCH 3/6] Sort __all__ --- pyproject.toml | 1 + python/lsst/obs/base/_instrument.py | 2 +- python/lsst/obs/base/ingest.py | 2 +- python/lsst/obs/base/instrument_tests.py | 4 ++-- python/lsst/obs/base/utils.py | 4 ++-- 5 files changed, 7 insertions(+), 6 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 90aa0af3..dd6f3070 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -87,6 +87,7 @@ select = [ "D", # pydocstyle "UP", # pyupgrade "I", # isort + "RUF022", # sort __all__ ] extend-select = [ "RUF100", # Warn about unused noqa diff --git a/python/lsst/obs/base/_instrument.py b/python/lsst/obs/base/_instrument.py index 79b0f7fe..d2ef92c4 100644 --- a/python/lsst/obs/base/_instrument.py +++ b/python/lsst/obs/base/_instrument.py @@ -21,7 +21,7 @@ from __future__ import annotations -__all__ = ("Instrument", "makeExposureRecordFromObsInfo", "loadCamera") +__all__ = ("Instrument", "loadCamera", "makeExposureRecordFromObsInfo") import logging import os.path diff --git a/python/lsst/obs/base/ingest.py b/python/lsst/obs/base/ingest.py index 1f509d02..fd8b913a 100644 --- a/python/lsst/obs/base/ingest.py +++ b/python/lsst/obs/base/ingest.py @@ -20,7 +20,7 @@ # along with this program. If not, see . -__all__ = ("RawIngestTask", "RawIngestConfig", "makeTransferChoiceField") +__all__ = ("RawIngestConfig", "RawIngestTask", "makeTransferChoiceField") import json import re diff --git a/python/lsst/obs/base/instrument_tests.py b/python/lsst/obs/base/instrument_tests.py index 0c1891d2..66610c18 100644 --- a/python/lsst/obs/base/instrument_tests.py +++ b/python/lsst/obs/base/instrument_tests.py @@ -28,11 +28,11 @@ from __future__ import annotations __all__ = [ + "CuratedCalibration", "DummyCam", + "DummyCamYamlWcsFormatter", "InstrumentTestData", "InstrumentTests", - "DummyCamYamlWcsFormatter", - "CuratedCalibration", ] import abc diff --git a/python/lsst/obs/base/utils.py b/python/lsst/obs/base/utils.py index 0bfd84dd..47f4cab9 100644 --- a/python/lsst/obs/base/utils.py +++ b/python/lsst/obs/base/utils.py @@ -21,10 +21,10 @@ __all__ = ( "InitialSkyWcsError", + "add_provenance_to_fits_header", + "bboxFromIraf", "createInitialSkyWcs", "createInitialSkyWcsFromBoresight", - "bboxFromIraf", - "add_provenance_to_fits_header", "strip_provenance_from_fits_header", ) From 3e1bbbd92424d6282c15867ec6c47afdc33303c7 Mon Sep 17 00:00:00 2001 From: Tim Jenness Date: Sat, 8 Feb 2025 14:06:23 -0700 Subject: [PATCH 4/6] Switch from black/isort to ruff in pre-commit --- .pre-commit-config.yaml | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index e64fecc1..ba8a1bba 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -6,22 +6,10 @@ 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.4 hooks: - id: ruff + args: [--fix] + - id: ruff-format From db405ca6b3167536e62545fad2de9fe81aeae025 Mon Sep 17 00:00:00 2001 From: Tim Jenness Date: Sat, 8 Feb 2025 14:06:40 -0700 Subject: [PATCH 5/6] Use ruff format --- pyproject.toml | 5 +++++ python/lsst/obs/base/ingest.py | 6 +++--- python/lsst/obs/base/tests.py | 4 +++- python/lsst/obs/base/utils.py | 2 +- 4 files changed, 12 insertions(+), 5 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index dd6f3070..65957c04 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -101,3 +101,8 @@ 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 diff --git a/python/lsst/obs/base/ingest.py b/python/lsst/obs/base/ingest.py index fd8b913a..5d88b9b4 100644 --- a/python/lsst/obs/base/ingest.py +++ b/python/lsst/obs/base/ingest.py @@ -1243,9 +1243,9 @@ def ingestFiles( # Determine the instrument so we can work out the dataset type. instrument = exposure.files[0].instrument - assert ( - instrument is not None - ), "file should have been removed from this list by prep if instrument could not be found" + assert instrument is not None, ( + "file should have been removed from this list by prep if instrument could not be found" + ) if raw_definition := getattr(instrument, "raw_definition", None): datasetTypeName, dimensions, storageClass = raw_definition diff --git a/python/lsst/obs/base/tests.py b/python/lsst/obs/base/tests.py index 31a69dc7..97de6c07 100644 --- a/python/lsst/obs/base/tests.py +++ b/python/lsst/obs/base/tests.py @@ -49,7 +49,9 @@ class ObsTests(butler_tests.ButlerGetTests, camera_tests.CameraTests): .. code-block:: python - class TestObs(lsst.obs.base.tests.ObsTests, lsst.utils.tests.TestCase): + class TestObs( + lsst.obs.base.tests.ObsTests, lsst.utils.tests.TestCase + ): def setUp(self): self.setUp_tests(...) self.setUp_butler_get(...) diff --git a/python/lsst/obs/base/utils.py b/python/lsst/obs/base/utils.py index 47f4cab9..eae12f0b 100644 --- a/python/lsst/obs/base/utils.py +++ b/python/lsst/obs/base/utils.py @@ -181,7 +181,7 @@ def _store_str_header( n_remove = n_over + 1 + 3 middle = len(value) // 2 half_remove = n_remove // 2 - value = f"{value[:middle-half_remove]}...{value[middle+half_remove:]}" + value = f"{value[: middle - half_remove]}...{value[middle + half_remove :]}" # Do not forward comment if we have elided. comment = None From da78b1a37defdc5bc9dfba53b183fc6a6ba7797f Mon Sep 17 00:00:00 2001 From: Tim Jenness Date: Sat, 8 Feb 2025 14:06:57 -0700 Subject: [PATCH 6/6] Remove lint action replaced by formatting --- .github/workflows/lint.yaml | 16 ---------------- 1 file changed, 16 deletions(-) delete mode 100644 .github/workflows/lint.yaml diff --git a/.github/workflows/lint.yaml b/.github/workflows/lint.yaml deleted file mode 100644 index 59bae3f1..00000000 --- a/.github/workflows/lint.yaml +++ /dev/null @@ -1,16 +0,0 @@ -name: lint - -on: - push: - branches: - - main - pull_request: - -jobs: - call-workflow: - uses: lsst/rubin_workflows/.github/workflows/lint.yaml@main - ruff: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - uses: chartboost/ruff-action@v1