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
7 changes: 3 additions & 4 deletions cpp_linter_hooks/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -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"]

Expand Down
9 changes: 4 additions & 5 deletions tests/test_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand All @@ -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),
Expand Down
Loading