Skip to content

Commit

Permalink
Clean up linting (#521)
Browse files Browse the repository at this point in the history
  • Loading branch information
WilliamJamieson authored Dec 2, 2024
2 parents 8dfcfbf + b5428c3 commit a90fb37
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 59 deletions.
28 changes: 3 additions & 25 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ repos:
- id: check-yaml
args: ["--unsafe"]
- id: check-toml
- id: check-json
- id: check-merge-conflict
- id: check-symlinks
- id: debug-statements
Expand All @@ -19,8 +20,6 @@ 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
Expand All @@ -33,30 +32,9 @@ repos:
additional_dependencies:
- tomli

- 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: ["-r", "-ll"]
args: ["--fix", "--show-fixes"]
- id: ruff-format
14 changes: 7 additions & 7 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
from importlib_metadata import distribution

try:
numpy.random.seed(int(os.environ["SOURCE_DATE_EPOCH"]))
numpy.random.seed(int(os.environ["SOURCE_DATE_EPOCH"])) # noqa: NPY002
except KeyError:
pass

Expand All @@ -59,12 +59,12 @@
# If your documentation needs a minimal Sphinx version, state it here.
# needs_sphinx = '1.2'

intersphinx_mapping["pypa-packaging"] = ("https://packaging.python.org/en/latest/", None) # noqa: E501, F405
intersphinx_mapping["asdf"] = ("https://asdf.readthedocs.io/en/latest/", None) # noqa: E501, F405
intersphinx_mapping["asdf-standard"] = ("https://asdf-standard.readthedocs.io/en/latest/", None) # noqa: E501, F405
intersphinx_mapping["asdf-astropy"] = ("https://asdf-astropy.readthedocs.io/en/latest/", None) # noqa: E501, F405
intersphinx_mapping["pytest"] = ("https://docs.pytest.org/en/latest/", None) # noqa: E501, F405
intersphinx_mapping["roman_datamodels"] = ("https://roman-datamodels.readthedocs.io/en/latest/", None) # noqa: E501, F405
intersphinx_mapping["pypa-packaging"] = ("https://packaging.python.org/en/latest/", None) # noqa: F405
intersphinx_mapping["asdf"] = ("https://asdf.readthedocs.io/en/latest/", None) # noqa: F405
intersphinx_mapping["asdf-standard"] = ("https://asdf-standard.readthedocs.io/en/latest/", None) # noqa: F405
intersphinx_mapping["asdf-astropy"] = ("https://asdf-astropy.readthedocs.io/en/latest/", None) # noqa: F405
intersphinx_mapping["pytest"] = ("https://docs.pytest.org/en/latest/", None) # noqa: F405
intersphinx_mapping["roman_datamodels"] = ("https://roman-datamodels.readthedocs.io/en/latest/", None) # noqa: F405

# To perform a Sphinx version check that needs to be more specific than
# major.minor, call `check_sphinx_version("x.y.z")` here.
Expand Down
37 changes: 25 additions & 12 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ rad = "rad.integration:get_resource_mappings"
requires = [
"setuptools >=61",
"setuptools_scm[toml] >=3.4",
"wheel",
]
build-backend = "setuptools.build_meta"

Expand All @@ -81,30 +80,44 @@ minversion = 7.0
doctest_plus = true
doctest_rst = true
text_file_format = "rst"
addopts = "--show-capture=no"
log_cli_level = "INFO"
xfail_strict = true
addopts = [
"--color=yes", # color test output
"--doctest-rst", # enable doctests
"--strict-config", # fail on unknown config options
"--strict-markers", # fail on unknown markers
"-ra", # Show summary of all failures/errors
]
testpaths = [
"tests",
"src/rad/resources/schemas",
]
filterwarnings = [
"error::ResourceWarning",
"error",
]
asdf_schema_tests_enabled = "true"
asdf_schema_skip_tests = "src/rad/resources/schemas/rad_schema-1.0.0.yaml"
asdf_schema_root = "src/rad/resources/schemas"

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

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

[tool.ruff]
line-length = 130

[tool.ruff.lint]
extend-select = [
"UP", # PyUpgrade
"I", # isort
"B", # BugBear
"S", # Bandit
"RUF", # ruff specific
"NPY", # numpy specific
]

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

[tool.codespell]
skip = "*.pdf,*.fits,*.asdf,.tox,build,./tags,.git,docs/_build"

Expand Down
1 change: 1 addition & 0 deletions scripts/insert_next_release.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
Insert the next release's changelog header. Prints the version, which
our GitHub Actions workflow uses to generate a commit message.
"""

import re
from pathlib import Path

Expand Down
1 change: 1 addition & 0 deletions scripts/set_release_date.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
Prints the version, which our GitHub Actions workflow uses to
generate a commit message and release tag.
"""

import re
from datetime import date
from pathlib import Path
Expand Down
7 changes: 1 addition & 6 deletions src/rad/integration.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
import sys
import importlib.resources as importlib_resources

from asdf.resource import DirectoryResourceMapping

if sys.version_info < (3, 9):
import importlib_resources
else:
import importlib.resources as importlib_resources


def get_resource_mappings():
"""
Expand Down
7 changes: 1 addition & 6 deletions tests/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,7 @@
Test that the asdf library integration is working properly.
"""

import sys

if sys.version_info < (3, 9):
import importlib_resources
else:
import importlib.resources as importlib_resources
import importlib.resources as importlib_resources

import asdf
import pytest
Expand Down
7 changes: 4 additions & 3 deletions tests/test_schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def callback(node):
"missing properties: " + missing_list + "\n"
"extra properties: " + extra_list
)
assert False, message
raise ValueError(message)

asdf.treeutil.walk(schema, callback)
else:
Expand All @@ -111,7 +111,7 @@ def callback(node):
if not required_names.issubset(property_names):
missing_list = ", ".join(required_names - property_names)
message = "required references names that do not exist: " + missing_list
assert False, message
raise ValueError(message)

asdf.treeutil.walk(schema, callback)

Expand Down Expand Up @@ -279,7 +279,8 @@ def test_varchar_length(uri):
"""
schema = asdf.schema.load_schema(uri)

def callback(node, nvarchars={}):
def callback(node, nvarchars=None):
nvarchars = nvarchars or {}
if not isinstance(node, dict):
return
if node.get("type", "") != "string":
Expand Down

0 comments on commit a90fb37

Please sign in to comment.