Skip to content

Commit

Permalink
Merge pull request #500 from lsst/tickets/DM-48788
Browse files Browse the repository at this point in the history
DM-48788: Use ruff format
  • Loading branch information
timj authored Feb 8, 2025
2 parents 7eb4f6d + da78b1a commit a7ddd3f
Show file tree
Hide file tree
Showing 16 changed files with 47 additions and 49 deletions.
16 changes: 0 additions & 16 deletions .github/workflows/lint.yaml

This file was deleted.

16 changes: 2 additions & 14 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
11 changes: 11 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -85,13 +86,23 @@ select = [
"W", # pycodestyle
"D", # pydocstyle
"UP", # pyupgrade
"I", # isort
"RUF022", # sort __all__
]
extend-select = [
"RUF100", # Warn about unused noqa
]

[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
3 changes: 2 additions & 1 deletion python/lsst/obs/base/_fitsRawFormatterBase.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion python/lsst/obs/base/_instrument.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

from __future__ import annotations

__all__ = ("Instrument", "makeExposureRecordFromObsInfo", "loadCamera")
__all__ = ("Instrument", "loadCamera", "makeExposureRecordFromObsInfo")

import logging
import os.path
Expand All @@ -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,
Expand All @@ -52,6 +53,7 @@

if TYPE_CHECKING:
from astro_metadata_translator import MetadataTranslator, ObservationInfo

from lsst.daf.butler import Registry

from .filters import FilterDefinitionCollection
Expand Down
1 change: 1 addition & 0 deletions python/lsst/obs/base/cli/cmd/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.

import click

from lsst.daf.butler.cli.opt import (
config_file_option,
config_option,
Expand Down
1 change: 1 addition & 0 deletions python/lsst/obs/base/cli/doc/butlerCmdDocGen.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"""

import click

from lsst.utils import doImport

from .. import cmd
Expand Down
9 changes: 5 additions & 4 deletions python/lsst/obs/base/ingest.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.


__all__ = ("RawIngestTask", "RawIngestConfig", "makeTransferChoiceField")
__all__ = ("RawIngestConfig", "RawIngestTask", "makeTransferChoiceField")

import json
import re
Expand All @@ -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,
Expand Down Expand Up @@ -1242,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
Expand Down
7 changes: 4 additions & 3 deletions python/lsst/obs/base/instrument_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@
from __future__ import annotations

__all__ = [
"CuratedCalibration",
"DummyCam",
"DummyCamYamlWcsFormatter",
"InstrumentTestData",
"InstrumentTests",
"DummyCamYamlWcsFormatter",
"CuratedCalibration",
]

import abc
Expand All @@ -41,14 +41,15 @@
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
from lsst.obs.base import FilterDefinition, FilterDefinitionCollection, Instrument
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

Expand Down
1 change: 1 addition & 0 deletions python/lsst/obs/base/makeRawVisitInfoViaObsInfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion python/lsst/obs/base/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import logging

import numpy as np

from lsst.afw.cameraGeom.utils import calcRawCcdBBox
from lsst.afw.image import Exposure

Expand All @@ -48,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(...)
Expand Down
6 changes: 3 additions & 3 deletions python/lsst/obs/base/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
)

Expand Down Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions python/lsst/obs/base/yamlCamera.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
1 change: 1 addition & 0 deletions tests/test_butlerFits.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 4 additions & 3 deletions tests/test_fitsRawFormatter.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,17 @@
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
import lsst.daf.butler
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 (
Expand Down
3 changes: 2 additions & 1 deletion tests/test_makeRawVisitInfoViaObsInfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit a7ddd3f

Please sign in to comment.