diff --git a/cpp_linter_hooks/util.py b/cpp_linter_hooks/util.py index 7e652d0..8969d7b 100644 --- a/cpp_linter_hooks/util.py +++ b/cpp_linter_hooks/util.py @@ -20,10 +20,9 @@ def get_version_from_dependency(tool: str) -> Optional[str]: return None with open(pyproject_path, "rb") as f: data = tomllib.load(f) - # Check build-system.requires - build_system = data.get("build-system", {}) - requires = build_system.get("requires", []) - for dep in requires: + # Check [project].dependencies + dependencies = data.get("project", {}).get("dependencies", []) + for dep in dependencies: if dep.startswith(f"{tool}=="): return dep.split("==")[1] return None diff --git a/pyproject.toml b/pyproject.toml index 2e66bcd..f27e447 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,5 +1,5 @@ [build-system] -requires = ["setuptools>=45", "setuptools-scm", "clang-format==21.1.0", "clang-tidy==21.1.0"] +requires = ["setuptools>=45", "setuptools-scm"] build-backend = "setuptools.build_meta" requires-python = ">=3.9" @@ -34,6 +34,8 @@ classifiers = [ dependencies = [ "tomli>=1.1.0; python_version < '3.11'", "setuptools>=45.0.0", # Required for pkg_resources in clang-tidy + "clang-format==21.1.0", + "clang-tidy==21.1.0", ] dynamic = ["version"] diff --git a/tests/test_util.py b/tests/test_util.py index 0c73714..9ce5b21 100644 --- a/tests/test_util.py +++ b/tests/test_util.py @@ -25,14 +25,13 @@ def test_get_version_from_dependency_success(): """Test get_version_from_dependency with valid pyproject.toml.""" mock_toml_content = { - "build-system": { - "requires": [ + "project": { + "dependencies": [ "clang-format==20.1.7", "clang-tidy==20.1.0", "other-package==1.0.0", ] - }, - "project": {}, + } } with ( @@ -57,7 +56,7 @@ def test_get_version_from_dependency_missing_file(): @pytest.mark.benchmark def test_get_version_from_dependency_missing_dependency(): """Test get_version_from_dependency with missing dependency.""" - mock_toml_content = {"build-system": {"requires": ["other-package==1.0.0"]}} + mock_toml_content = {"project": {"dependencies": ["other-package==1.0.0"]}} with ( patch("pathlib.Path.exists", return_value=True),