Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions polymath_code_standard/checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
# SPDX-License-Identifier: Apache-2.0
import argparse
import functools
import importlib.resources
import os
import subprocess
import sys
Expand All @@ -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]:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
# SPDX-FileCopyrightText: 2026 Polymath Robotics, Inc.
# SPDX-License-Identifier: Apache-2.0
import argparse
import importlib.resources
import os
import re
import shutil
import subprocess
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')

Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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] = {
Expand Down
6 changes: 5 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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*"]
Expand Down
9 changes: 7 additions & 2 deletions tests/test_cpp.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
14 changes: 7 additions & 7 deletions tests/test_licenses.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -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()

Expand Down Expand Up @@ -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()
Loading