Skip to content

Commit 8c45bb1

Browse files
authored
fix: move clang-tools to project dependencies section (#118)
1 parent d56ca2a commit 8c45bb1

File tree

3 files changed

+10
-10
lines changed

3 files changed

+10
-10
lines changed

cpp_linter_hooks/util.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,9 @@ def get_version_from_dependency(tool: str) -> Optional[str]:
2020
return None
2121
with open(pyproject_path, "rb") as f:
2222
data = tomllib.load(f)
23-
# Check build-system.requires
24-
build_system = data.get("build-system", {})
25-
requires = build_system.get("requires", [])
26-
for dep in requires:
23+
# Check [project].dependencies
24+
dependencies = data.get("project", {}).get("dependencies", [])
25+
for dep in dependencies:
2726
if dep.startswith(f"{tool}=="):
2827
return dep.split("==")[1]
2928
return None

pyproject.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[build-system]
2-
requires = ["setuptools>=45", "setuptools-scm", "clang-format==21.1.0", "clang-tidy==21.1.0"]
2+
requires = ["setuptools>=45", "setuptools-scm"]
33
build-backend = "setuptools.build_meta"
44

55
requires-python = ">=3.9"
@@ -34,6 +34,8 @@ classifiers = [
3434
dependencies = [
3535
"tomli>=1.1.0; python_version < '3.11'",
3636
"setuptools>=45.0.0", # Required for pkg_resources in clang-tidy
37+
"clang-format==21.1.0",
38+
"clang-tidy==21.1.0",
3739
]
3840
dynamic = ["version"]
3941

tests/test_util.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,13 @@
2525
def test_get_version_from_dependency_success():
2626
"""Test get_version_from_dependency with valid pyproject.toml."""
2727
mock_toml_content = {
28-
"build-system": {
29-
"requires": [
28+
"project": {
29+
"dependencies": [
3030
"clang-format==20.1.7",
3131
"clang-tidy==20.1.0",
3232
"other-package==1.0.0",
3333
]
34-
},
35-
"project": {},
34+
}
3635
}
3736

3837
with (
@@ -57,7 +56,7 @@ def test_get_version_from_dependency_missing_file():
5756
@pytest.mark.benchmark
5857
def test_get_version_from_dependency_missing_dependency():
5958
"""Test get_version_from_dependency with missing dependency."""
60-
mock_toml_content = {"build-system": {"requires": ["other-package==1.0.0"]}}
59+
mock_toml_content = {"project": {"dependencies": ["other-package==1.0.0"]}}
6160

6261
with (
6362
patch("pathlib.Path.exists", return_value=True),

0 commit comments

Comments
 (0)