Skip to content

Commit

Permalink
Clean up linting and tool configs (#1547)
Browse files Browse the repository at this point in the history
  • Loading branch information
WilliamJamieson authored Dec 16, 2024
1 parent e250097 commit 603f285
Show file tree
Hide file tree
Showing 87 changed files with 431 additions and 375 deletions.
28 changes: 2 additions & 26 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,37 +21,13 @@ repos:
- repo: https://github.com/pre-commit/pygrep-hooks
rev: v1.10.0
hooks:
- id: python-check-blanket-noqa
- id: python-check-mock-methods
- id: rst-directive-colons
- id: rst-inline-touching-normal
- id: text-unicode-replacement-char

- repo: https://github.com/asottile/pyupgrade
rev: 'v3.19.0'
hooks:
- id: pyupgrade
args: ["--py38-plus"]

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: 'v0.8.0'
hooks:
- id: ruff
args: ["--fix"]

- repo: https://github.com/pycqa/isort
rev: 5.13.2
hooks:
- id: isort

- repo: https://github.com/psf/black
rev: 24.10.0
hooks:
- id: black

- repo: https://github.com/PyCQA/bandit
rev: 1.7.10
hooks:
- id: bandit
args: ["-c", "pyproject.toml"]
additional_dependencies: ["bandit[toml]"]
args: ["--fix", "--show-fixes"]
- id: ruff-format
15 changes: 1 addition & 14 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,12 @@
import importlib
import os
import sys
import tomllib
from distutils.version import LooseVersion
from pathlib import Path

import sphinx
import stsci_rtd_theme

if sys.version_info < (3, 11):
import tomli as tomllib
else:
import tomllib

from sphinx.ext.autodoc import AttributeDocumenter

from romancal.stpipe import RomanStep
Expand Down Expand Up @@ -106,14 +101,6 @@ def check_sphinx_version(expected_version):

intersphinx_disabled_reftypes = ["*"]

if sys.version_info[0] == 2:
intersphinx_mapping["python"] = ("http://docs.python.org/2/", None)
intersphinx_mapping["pythonloc"] = (
"http://docs.python.org/",
os.path.abspath(
os.path.join(os.path.dirname(__file__), "local/python2_local_links.inv")
),
)

# Add any Sphinx extension module names here, as strings. They can be
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
Expand Down
3 changes: 2 additions & 1 deletion docs/exts/numfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ def doctree_resolved(app, doctree, docname):
if app.builder.name != "latex" and app.config.number_figures:
for cap in figure_info.traverse(caption):
cap[0] = Text(
"%s %d: %s" % (app.config.figure_caption_prefix, i, cap[0])
"%s %d: %s" # noqa: UP031
% (app.config.figure_caption_prefix, i, cap[0])
)

for id in figure_info["ids"]:
Expand Down
58 changes: 29 additions & 29 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,18 @@ classifiers = [
dependencies = [
"asdf >=3.3.0",
"asdf-astropy >=0.5.0",
"astropy >=5.3.0",
"astropy >=6.0.0",
"crds >=11.16.16",
"gwcs >=0.21.0",
# "gwcs >=0.21.0",
"gwcs @ git+https://github.com/spacetelescope/gwcs.git@master",
"jsonschema >=4.8",
"numpy >=1.24",
"photutils >=1.13.0",
"pyparsing >=2.4.7",
"requests >=2.26",
# "roman_datamodels>=0.22.0,<0.23.0",
"roman_datamodels @ git+https://github.com/spacetelescope/roman_datamodels.git",
"scipy >=1.11",
"scipy >=1.14.1",
# "stcal>=1.10.0,<1.11.0",
"stcal @ git+https://github.com/spacetelescope/stcal.git@main",
# "stpipe >=0.7.0,<0.8.0",
Expand Down Expand Up @@ -57,7 +58,6 @@ docs = [
"sphinx-rtd-theme",
"stsci-rtd-theme",
"sphinx-autobuild",
"tomli; python_version <=\"3.11\"",
]
test = [
"ci-watson >=0.5.0",
Expand Down Expand Up @@ -121,7 +121,7 @@ zip-safe = false
]

[tool.pytest.ini_options]
minversion = 4.6
minversion = 6.0
norecursedirs = [
"docs/_build",
"romancal/scripts",
Expand All @@ -139,9 +139,14 @@ doctest_plus = "enabled"
doctest_rst = "enabled"
text_file_format = "rst"
log_cli_level = "info"
xfail_strict = true
addopts = [
"--color=yes", # color test output
"--doctest-rst", # enable doctests
"--doctest-ignore-import-errors",
"--color=yes",
"--strict-config", # fail on unknown config options
"--strict-markers", # fail on unknown markers
"-ra", # Show summary of all failures/errorsproduct_names
]
markers = [
"soctests: run only the SOC tests in the suite.",
Expand Down Expand Up @@ -173,30 +178,19 @@ exclude_lines = [
"if __name__ == \"__main__\":",
]

[tool.bandit]
skips = [
"B101",
"B307",
"B404",
"B603",
]
exclude_dirs = [
"romancal/regtest/scripts",
]

[tool.isort]
profile = "black"
filter_files = true
line_length = 88

[tool.black]
line-length = 88
force-exclude = "^/(\n (\n \\.eggs\n | \\.git\n | \\.pytest_cache\n | \\.tox\n )/\n)\n"

[tool.ruff]
line-length = 88


[tool.ruff.lint]
extend-select = [
"UP", # PyUpgrade
"I", # isort
"B", # BugBear
"S", # Bandit
"RUF", # ruff specific
"NPY", # Numpy lint
]
exclude = [
"jdocs",
".tox",
Expand All @@ -206,14 +200,20 @@ exclude = [
ignore = [
"E741", # ambiguous variable name
]
extend-select = [
"NPY",
]

[tool.ruff.lint.extend-per-file-ignores]
"romancal/associations/__init__.py" = [
"E402",
]
"romancal/**/tests/**.py" = [
"S101" # Bandit: Use of assert detected (fine in test files)
]
"romancal/**/test/**.py" = [
"S101" # Bandit: Use of assert detected (fine in test files)
]
"romancal/regtest/**.py" = [
"S101" # Bandit: Use of assert detected (fine in test files)
]

[tool.cibuildwheel.macos]
archs = [
Expand Down
8 changes: 7 additions & 1 deletion romancal/assign_wcs/assign_wcs_step.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
"""

from __future__ import annotations

import logging
from typing import TYPE_CHECKING

import gwcs.coordinate_frames as cf
from astropy import coordinates as coord
Expand All @@ -16,6 +19,9 @@
from . import pointing
from .utils import add_s_region, wcs_bbox_from_shape

if TYPE_CHECKING:
from typing import ClassVar

log = logging.getLogger(__name__)
log.setLevel(logging.DEBUG)

Expand All @@ -28,7 +34,7 @@ class AssignWcsStep(RomanStep):

class_alias = "assign_wcs"

reference_file_types = ["distortion"]
reference_file_types: ClassVar = ["distortion"]

def process(self, input):
reference_file_names = {}
Expand Down
13 changes: 6 additions & 7 deletions romancal/assign_wcs/utils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import functools
import logging
from typing import List, Tuple, Union

import numpy as np
from astropy.coordinates import SkyCoord
Expand Down Expand Up @@ -44,8 +43,8 @@ def wcs_from_footprints(
pscale=None,
rotation=None,
shape=None,
ref_pixel: Tuple[float, float] = None,
ref_coord: Tuple[float, float] = None,
ref_pixel: tuple[float, float] | None = None,
ref_coord: tuple[float, float] | None = None,
):
"""
Create a WCS from a list of input data models.
Expand Down Expand Up @@ -217,9 +216,9 @@ def wcs_from_footprints(

def compute_scale(
wcs: WCS,
fiducial: Union[tuple, np.ndarray],
disp_axis: int = None,
pscale_ratio: float = None,
fiducial: tuple | np.ndarray,
disp_axis: int | None = None,
pscale_ratio: float | None = None,
) -> float:
"""Compute scaling transform.
Expand Down Expand Up @@ -282,7 +281,7 @@ def compute_scale(

def calc_rotation_matrix(
roll_ref: float, v3i_yang: float, vparity: int = 1
) -> List[float]:
) -> list[float]:
"""Calculate the rotation matrix.
Parameters
Expand Down
2 changes: 1 addition & 1 deletion romancal/associations/association.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
""" Main module for associations """
"""Main module for associations"""

import json
import logging
Expand Down
8 changes: 6 additions & 2 deletions romancal/associations/association_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,9 @@ def load(cls, serialized):
asn = loader(serialized)
except Exception as err:
logger.debug(f'Error unserializing: "{err}"')
raise AssociationNotValidError(f'Container is not JSON: "{serialized}"')
raise AssociationNotValidError(
f'Container is not JSON: "{serialized}"'
) from err

return asn

Expand Down Expand Up @@ -132,7 +134,9 @@ def load(cls, serialized):
asn = yaml_lib.safe_load(serialized)
except Exception as err:
logger.debug(f'Error unserializing: "{err}"')
raise AssociationNotValidError(f'Container is not YAML: "{serialized}"')
raise AssociationNotValidError(
f'Container is not YAML: "{serialized}"'
) from err
return asn

@staticmethod
Expand Down
15 changes: 7 additions & 8 deletions romancal/associations/lib/constraint.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
"""Constraints
"""
"""Constraints"""

import abc
import collections
Expand Down Expand Up @@ -139,7 +138,7 @@ def __iter__(self):
yield self

def __repr__(self):
result = f"{self.__class__.__name__}({str(self.__dict__)})"
result = f"{self.__class__.__name__}({self.__dict__!s})"
return result

def __str__(self):
Expand Down Expand Up @@ -600,7 +599,7 @@ class Constraint:
'value': 'a_value',
'name': 'simple',
'matched': False})
""" # noqa: E501
"""

def __init__(
self,
Expand Down Expand Up @@ -639,8 +638,8 @@ def __init__(
self.constraints = [init]
else:
raise TypeError(
"Invalid initialization value type {}.\nValid types are"
" `SimpleConstraint`, `Constraint`,\nor subclass.".format(type(init))
f"Invalid initialization value type {type(init)}.\nValid types are"
" `SimpleConstraint`, `Constraint`,\nor subclass."
)

# Give some defaults real meaning.
Expand All @@ -664,10 +663,10 @@ def dup_names(
and all the constraints that define that name.
"""
attrs = self.get_all_attr("name")
constraints, names = zip(*attrs)
constraints, names = zip(*attrs, strict=False)
dups = [name for name, count in collections.Counter(names).items() if count > 1]
result = collections.defaultdict(list)
for name, constraint in zip(names, constraints):
for name, constraint in zip(names, constraints, strict=False):
if name in dups:
result[name].append(constraint)

Expand Down
2 changes: 1 addition & 1 deletion romancal/associations/lib/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

from functools import wraps

__all__ = ["memoize", "singleton", "memoize_attr_check"]
__all__ = ["memoize", "memoize_attr_check", "singleton"]


def _make_key(args, kwargs):
Expand Down
6 changes: 3 additions & 3 deletions romancal/associations/lib/diff.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
""""Diff and compare associations"""
""" "Diff and compare associations"""

import logging
import re
Expand Down Expand Up @@ -267,9 +267,9 @@ def compare_membership(left, right):
)
)

for left_idx, left_product in enumerate(products_left):
for left_product in products_left:
left_product_name = components(left_product["name"])
for right_idx, right_product in enumerate(products_right):
for right_product in products_right:
if components(right_product["name"]) != left_product_name:
continue
try:
Expand Down
Loading

0 comments on commit 603f285

Please sign in to comment.