From cc34fd2f244ac13f93aeb9d38e624b63f3102a55 Mon Sep 17 00:00:00 2001 From: William Jamieson Date: Wed, 27 Nov 2024 11:31:25 -0500 Subject: [PATCH 1/4] Switch to using ruff over a collection of tools for linting --- .pre-commit-config.yaml | 20 +------------------- docs/conf.py | 12 ++++++------ pyproject.toml | 19 ++++++++++++++----- src/rad/integration.py | 7 +------ tests/test_integration.py | 7 +------ tests/test_schemas.py | 7 ++++--- 6 files changed, 27 insertions(+), 45 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 8953ba1a..e16aba9f 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -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 @@ -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 @@ -33,30 +32,13 @@ 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"] diff --git a/docs/conf.py b/docs/conf.py index 5d9752fa..9f810d01 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -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. diff --git a/pyproject.toml b/pyproject.toml index 950d19c6..f9508910 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -93,11 +93,6 @@ 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" @@ -105,6 +100,20 @@ force-exclude = "^/(\n (\n \\.eggs\n | \\.git\n | \\.pytest_cache\n [tool.ruff] line-length = 130 +[tool.ruff.lint] +extend-select = [ + "UP", # PyUpgrade + "I", # isort + "B", # BugBear + "S", # Bandit + "RUF", # ruff 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" diff --git a/src/rad/integration.py b/src/rad/integration.py index 1eca43d3..e4439281 100644 --- a/src/rad/integration.py +++ b/src/rad/integration.py @@ -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(): """ diff --git a/tests/test_integration.py b/tests/test_integration.py index bb9fa60f..9a6d2fe6 100644 --- a/tests/test_integration.py +++ b/tests/test_integration.py @@ -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 diff --git a/tests/test_schemas.py b/tests/test_schemas.py index dce7814a..173ff010 100644 --- a/tests/test_schemas.py +++ b/tests/test_schemas.py @@ -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: @@ -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) @@ -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": From bdddcd881bb82f614e7eacc55f4d63b66ef03a73 Mon Sep 17 00:00:00 2001 From: William Jamieson Date: Wed, 27 Nov 2024 11:32:55 -0500 Subject: [PATCH 2/4] Use built in ruff code formatter over black to lower number of tools in use --- .pre-commit-config.yaml | 8 ++------ pyproject.toml | 4 ---- scripts/insert_next_release.py | 1 + scripts/set_release_date.py | 1 + 4 files changed, 4 insertions(+), 10 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index e16aba9f..98f52fa6 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -36,9 +36,5 @@ repos: rev: 'v0.8.0' hooks: - id: ruff - args: ["--fix"] - -- repo: https://github.com/psf/black - rev: 24.10.0 - hooks: - - id: black + args: ["--fix", "--show-fixes"] + - id: ruff-format diff --git a/pyproject.toml b/pyproject.toml index f9508910..fb0dcaa5 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -93,10 +93,6 @@ 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.black] -line-length = 130 -force-exclude = "^/(\n (\n \\.eggs\n | \\.git\n | \\.pytest_cache\n | \\.tox\n )/\n)\n" - [tool.ruff] line-length = 130 diff --git a/scripts/insert_next_release.py b/scripts/insert_next_release.py index 5c3d9db4..c352b106 100755 --- a/scripts/insert_next_release.py +++ b/scripts/insert_next_release.py @@ -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 diff --git a/scripts/set_release_date.py b/scripts/set_release_date.py index 5c5c4897..3ce7dbb9 100755 --- a/scripts/set_release_date.py +++ b/scripts/set_release_date.py @@ -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 From 06cd7a8e36e1b464024d5ba758aa6eb8a9ca9755 Mon Sep 17 00:00:00 2001 From: William Jamieson Date: Wed, 27 Nov 2024 11:35:39 -0500 Subject: [PATCH 3/4] Update pytest config --- pyproject.toml | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index fb0dcaa5..35c8c6a0 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -57,7 +57,6 @@ rad = "rad.integration:get_resource_mappings" requires = [ "setuptools >=61", "setuptools_scm[toml] >=3.4", - "wheel", ] build-backend = "setuptools.build_meta" @@ -81,13 +80,21 @@ 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" From b5428c346682db2214e19843cbc2ce03a1e20909 Mon Sep 17 00:00:00 2001 From: William Jamieson Date: Wed, 27 Nov 2024 13:45:11 -0500 Subject: [PATCH 4/4] Add NPY check to sync with romancal --- docs/conf.py | 2 +- pyproject.toml | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/conf.py b/docs/conf.py index 9f810d01..57387507 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -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 diff --git a/pyproject.toml b/pyproject.toml index 35c8c6a0..0b622e40 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -110,6 +110,7 @@ extend-select = [ "B", # BugBear "S", # Bandit "RUF", # ruff specific + "NPY", # numpy specific ] [tool.ruff.lint.per-file-ignores]