From 20f9f6ecad6d1f4fc1f6a51a2bb5b80a6ab18bcb Mon Sep 17 00:00:00 2001 From: shenxianpeng Date: Thu, 18 Sep 2025 20:19:00 +0300 Subject: [PATCH 1/3] fix: move clang-tools to dependencies section --- cpp_linter_hooks/util.py | 7 +++---- pyproject.toml | 4 +++- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/cpp_linter_hooks/util.py b/cpp_linter_hooks/util.py index 7e652d0..7556d02 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 dependencies + dependencies = data.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"] From 8c366346a4c43eada4305477d7ebe03cc98ca941 Mon Sep 17 00:00:00 2001 From: shenxianpeng Date: Thu, 18 Sep 2025 20:22:23 +0300 Subject: [PATCH 2/3] test: update test_util.py --- tests/test_util.py | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/tests/test_util.py b/tests/test_util.py index 0c73714..6ff8b35 100644 --- a/tests/test_util.py +++ b/tests/test_util.py @@ -25,13 +25,11 @@ def test_get_version_from_dependency_success(): """Test get_version_from_dependency with valid pyproject.toml.""" mock_toml_content = { - "build-system": { - "requires": [ - "clang-format==20.1.7", - "clang-tidy==20.1.0", - "other-package==1.0.0", - ] - }, + "dependencies": [ + "clang-format==20.1.7", + "clang-tidy==20.1.0", + "other-package==1.0.0", + ], "project": {}, } From a212c74913dd22e3e10b67eace91ed07d330bc08 Mon Sep 17 00:00:00 2001 From: shenxianpeng Date: Thu, 18 Sep 2025 20:25:52 +0300 Subject: [PATCH 3/3] test: update test_util.py --- cpp_linter_hooks/util.py | 4 ++-- tests/test_util.py | 15 ++++++++------- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/cpp_linter_hooks/util.py b/cpp_linter_hooks/util.py index 7556d02..8969d7b 100644 --- a/cpp_linter_hooks/util.py +++ b/cpp_linter_hooks/util.py @@ -20,8 +20,8 @@ def get_version_from_dependency(tool: str) -> Optional[str]: return None with open(pyproject_path, "rb") as f: data = tomllib.load(f) - # Check dependencies - dependencies = data.get("dependencies", []) + # Check [project].dependencies + dependencies = data.get("project", {}).get("dependencies", []) for dep in dependencies: if dep.startswith(f"{tool}=="): return dep.split("==")[1] diff --git a/tests/test_util.py b/tests/test_util.py index 6ff8b35..9ce5b21 100644 --- a/tests/test_util.py +++ b/tests/test_util.py @@ -25,12 +25,13 @@ def test_get_version_from_dependency_success(): """Test get_version_from_dependency with valid pyproject.toml.""" mock_toml_content = { - "dependencies": [ - "clang-format==20.1.7", - "clang-tidy==20.1.0", - "other-package==1.0.0", - ], - "project": {}, + "project": { + "dependencies": [ + "clang-format==20.1.7", + "clang-tidy==20.1.0", + "other-package==1.0.0", + ] + } } with ( @@ -55,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),