diff --git a/polymath_code_standard/checker.py b/polymath_code_standard/checker.py index 521ee12..af039e3 100644 --- a/polymath_code_standard/checker.py +++ b/polymath_code_standard/checker.py @@ -2,7 +2,6 @@ # SPDX-License-Identifier: Apache-2.0 import argparse import functools -import importlib.resources import os import subprocess import sys @@ -12,9 +11,6 @@ from identify.identify import tags_from_path -# Path to resource files which are config inputs to the various hooks -CONFIG_DIR = importlib.resources.files('polymath_code_standard') / 'config' - @functools.cache def _file_tags(path: str) -> frozenset[str]: diff --git a/polymath_code_standard/checkers/ansible.py b/polymath_code_standard/checkers/ansible/__init__.py similarity index 97% rename from polymath_code_standard/checkers/ansible.py rename to polymath_code_standard/checkers/ansible/__init__.py index 018d25b..2900ffb 100644 --- a/polymath_code_standard/checkers/ansible.py +++ b/polymath_code_standard/checkers/ansible/__init__.py @@ -2,12 +2,16 @@ # SPDX-License-Identifier: Apache-2.0 import argparse import hashlib +import importlib.resources import json from pathlib import Path import yaml -from polymath_code_standard.checker import CONFIG_DIR, CheckerGroup, Result, check_group +from polymath_code_standard.checker import CheckerGroup, Result, check_group + +# Config files bundled alongside this checker +CONFIG_DIR = importlib.resources.files(__package__) # Where a repo declares the collections and roles its playbooks import. REQUIREMENTS = Path('ansible/requirements.yml') diff --git a/polymath_code_standard/config/ansible-lint.yml b/polymath_code_standard/checkers/ansible/ansible-lint.yml similarity index 100% rename from polymath_code_standard/config/ansible-lint.yml rename to polymath_code_standard/checkers/ansible/ansible-lint.yml diff --git a/polymath_code_standard/config/Apache-2.0.txt b/polymath_code_standard/checkers/copyright/Apache-2.0.txt similarity index 100% rename from polymath_code_standard/config/Apache-2.0.txt rename to polymath_code_standard/checkers/copyright/Apache-2.0.txt diff --git a/polymath_code_standard/checkers/copyright.py b/polymath_code_standard/checkers/copyright/__init__.py similarity index 98% rename from polymath_code_standard/checkers/copyright.py rename to polymath_code_standard/checkers/copyright/__init__.py index 732ae28..2c1e6df 100644 --- a/polymath_code_standard/checkers/copyright.py +++ b/polymath_code_standard/checkers/copyright/__init__.py @@ -8,8 +8,8 @@ from pathlib import Path from polymath_code_standard.checker import CheckerGroup, Result, check_group, filter_files +from polymath_code_standard.checkers.copyright.licenses import PROPRIETARY, get_license_full_text, get_license_header from polymath_code_standard.insert_license import COPYRIGHT_ORG_SENTINEL -from polymath_code_standard.licenses import PROPRIETARY, get_license_full_text, get_license_header @check_group diff --git a/polymath_code_standard/config/copyright.txt b/polymath_code_standard/checkers/copyright/copyright.txt similarity index 100% rename from polymath_code_standard/config/copyright.txt rename to polymath_code_standard/checkers/copyright/copyright.txt diff --git a/polymath_code_standard/licenses.py b/polymath_code_standard/checkers/copyright/licenses.py similarity index 98% rename from polymath_code_standard/licenses.py rename to polymath_code_standard/checkers/copyright/licenses.py index 0cbe701..ed9d12c 100644 --- a/polymath_code_standard/licenses.py +++ b/polymath_code_standard/checkers/copyright/licenses.py @@ -21,7 +21,7 @@ from functools import lru_cache from pathlib import Path -_CONFIG_DIR = Path(__file__).parent / 'config' +_CONFIG_DIR = Path(__file__).parent _SPDX_BASE_URL = 'https://raw.githubusercontent.com/spdx/license-list-data/main/json/details/{id}.json' PROPRIETARY = 'proprietary' diff --git a/polymath_code_standard/config/.cpplint.cfg b/polymath_code_standard/checkers/cpp/.cpplint.cfg similarity index 100% rename from polymath_code_standard/config/.cpplint.cfg rename to polymath_code_standard/checkers/cpp/.cpplint.cfg diff --git a/polymath_code_standard/checkers/cpp.py b/polymath_code_standard/checkers/cpp/__init__.py similarity index 95% rename from polymath_code_standard/checkers/cpp.py rename to polymath_code_standard/checkers/cpp/__init__.py index 0bc2737..ba3cdc8 100644 --- a/polymath_code_standard/checkers/cpp.py +++ b/polymath_code_standard/checkers/cpp/__init__.py @@ -1,6 +1,7 @@ # SPDX-FileCopyrightText: 2026 Polymath Robotics, Inc. # SPDX-License-Identifier: Apache-2.0 import argparse +import importlib.resources import os import re import shutil @@ -8,7 +9,10 @@ import tempfile from pathlib import Path -from polymath_code_standard.checker import CONFIG_DIR, CheckerGroup, Result, check_group, tool +from polymath_code_standard.checker import CheckerGroup, Result, check_group, tool + +# Config files bundled alongside this checker +CONFIG_DIR = importlib.resources.files(__package__) _IWYU_RE = re.compile(r'^(.+?):(\d+):\s+Add (#include (?:<[^>]+>|"[^"]+")) for') diff --git a/polymath_code_standard/config/clang-format b/polymath_code_standard/checkers/cpp/clang-format similarity index 100% rename from polymath_code_standard/config/clang-format rename to polymath_code_standard/checkers/cpp/clang-format diff --git a/polymath_code_standard/checkers/python.py b/polymath_code_standard/checkers/python/__init__.py similarity index 84% rename from polymath_code_standard/checkers/python.py rename to polymath_code_standard/checkers/python/__init__.py index 9eaf77b..1426cb3 100644 --- a/polymath_code_standard/checkers/python.py +++ b/polymath_code_standard/checkers/python/__init__.py @@ -1,12 +1,16 @@ # SPDX-FileCopyrightText: 2026 Polymath Robotics, Inc. # SPDX-License-Identifier: Apache-2.0 import argparse +import importlib.resources import os import shutil import tempfile from pathlib import Path -from polymath_code_standard.checker import CONFIG_DIR, CheckerGroup, Result, check_group +from polymath_code_standard.checker import CheckerGroup, Result, check_group + +# Config files bundled alongside this checker +CONFIG_DIR = importlib.resources.files(__package__) @check_group diff --git a/polymath_code_standard/config/ruff.toml b/polymath_code_standard/checkers/python/ruff.toml similarity index 100% rename from polymath_code_standard/config/ruff.toml rename to polymath_code_standard/checkers/python/ruff.toml diff --git a/polymath_code_standard/checkers/xml.py b/polymath_code_standard/checkers/xml/__init__.py similarity index 92% rename from polymath_code_standard/checkers/xml.py rename to polymath_code_standard/checkers/xml/__init__.py index 8f7f63c..ada3314 100644 --- a/polymath_code_standard/checkers/xml.py +++ b/polymath_code_standard/checkers/xml/__init__.py @@ -2,10 +2,14 @@ # SPDX-License-Identifier: Apache-2.0 import argparse import functools +import importlib.resources from lxml import etree -from polymath_code_standard.checker import CONFIG_DIR, CheckerGroup, Result, check_group +from polymath_code_standard.checker import CheckerGroup, Result, check_group + +# Config files bundled alongside this checker +CONFIG_DIR = importlib.resources.files(__package__) # Schemas bundled as package resources; any other URL is fetched from the network. _BUNDLED_SCHEMAS: dict[str, str] = { diff --git a/polymath_code_standard/config/package_format3.xsd b/polymath_code_standard/checkers/xml/package_format3.xsd similarity index 100% rename from polymath_code_standard/config/package_format3.xsd rename to polymath_code_standard/checkers/xml/package_format3.xsd diff --git a/pyproject.toml b/pyproject.toml index 7a876b6..838d305 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -27,7 +27,11 @@ dependencies = [ [tool.setuptools.package-data] -"polymath_code_standard" = ["config/*", "config/.*"] +"polymath_code_standard.checkers.ansible" = ["ansible-lint.yml"] +"polymath_code_standard.checkers.copyright" = ["*.txt"] +"polymath_code_standard.checkers.cpp" = [".cpplint.cfg", "clang-format"] +"polymath_code_standard.checkers.python" = ["ruff.toml"] +"polymath_code_standard.checkers.xml" = ["package_format3.xsd"] [tool.setuptools.packages.find] exclude = ["test_files*", "tests*"] diff --git a/tests/test_cpp.py b/tests/test_cpp.py index dbc7282..9139d40 100644 --- a/tests/test_cpp.py +++ b/tests/test_cpp.py @@ -8,8 +8,13 @@ import pytest -from polymath_code_standard.checker import CONFIG_DIR -from polymath_code_standard.checkers.cpp import _insert_includes, _insertion_point, _parse_iwyu_output, fix_iwyu +from polymath_code_standard.checkers.cpp import ( + CONFIG_DIR, + _insert_includes, + _insertion_point, + _parse_iwyu_output, + fix_iwyu, +) _PROJECT_ROOT = Path(__file__).parent.parent diff --git a/tests/test_licenses.py b/tests/test_licenses.py index 0437c85..e4c9805 100644 --- a/tests/test_licenses.py +++ b/tests/test_licenses.py @@ -7,8 +7,8 @@ import pytest -from polymath_code_standard import licenses -from polymath_code_standard.licenses import get_license_full_text, get_license_header +from polymath_code_standard.checkers.copyright import licenses +from polymath_code_standard.checkers.copyright.licenses import get_license_full_text, get_license_header # --------------------------------------------------------------------------- # Minimal mock SPDX payloads @@ -35,12 +35,12 @@ def _mock_fetch(data: dict): - return patch('polymath_code_standard.licenses._fetch_spdx_json', return_value=data) + return patch('polymath_code_standard.checkers.copyright.licenses._fetch_spdx_json', return_value=data) def _mock_fetch_404(spdx_id: str = 'UNKNOWN-1.0'): exc = urllib.error.HTTPError(url=None, code=404, msg='Not Found', hdrs=None, fp=None) - return patch('polymath_code_standard.licenses._fetch_spdx_json', side_effect=exc) + return patch('polymath_code_standard.checkers.copyright.licenses._fetch_spdx_json', side_effect=exc) @pytest.fixture(autouse=True) @@ -77,7 +77,7 @@ def test_reuse_style_works_for_any_id(self): assert 'SPDX-License-Identifier: GPL-3.0-only' in result def test_reuse_style_does_not_fetch_network(self): - with patch('polymath_code_standard.licenses._fetch_spdx_json') as mock_fetch: + with patch('polymath_code_standard.checkers.copyright.licenses._fetch_spdx_json') as mock_fetch: get_license_header('Apache-2.0', '2024', 'Acme Corp', reuse_style_header=True) mock_fetch.assert_not_called() @@ -178,12 +178,12 @@ def test_unknown_id_raises(self): get_license_full_text('UNKNOWN-1.0', '2024', 'Acme Corp') def test_bundled_apache_uses_canonical_formatting(self): - with patch('polymath_code_standard.licenses._fetch_spdx_json') as mock_fetch: + with patch('polymath_code_standard.checkers.copyright.licenses._fetch_spdx_json') as mock_fetch: result = get_license_full_text('Apache-2.0', '2024', 'Acme Corp') mock_fetch.assert_not_called() assert ' Apache License' in result def test_bundled_takes_precedence_over_spdx(self): - with patch('polymath_code_standard.licenses._fetch_spdx_json') as mock_fetch: + with patch('polymath_code_standard.checkers.copyright.licenses._fetch_spdx_json') as mock_fetch: get_license_full_text('Apache-2.0', '2024', 'Acme Corp') mock_fetch.assert_not_called()