fix: move clang tools dependencies to optional by shenxianpeng · Pull Request #92 · cpp-linter/cpp-linter-hooks · GitHub
Skip to content

fix: move clang tools dependencies to optional#92

Merged
shenxianpeng merged 8 commits into
mainfrom
shenxianpeng-patch-1
Jul 16, 2025
Merged

fix: move clang tools dependencies to optional#92
shenxianpeng merged 8 commits into
mainfrom
shenxianpeng-patch-1

Conversation

@shenxianpeng

@shenxianpeng shenxianpeng commented Jul 16, 2025

Copy link
Copy Markdown
Member

Summary by CodeRabbit

  • New Features

    • Improved support for retrieving tool versions from an optional dependencies section, enhancing configuration flexibility.
  • Bug Fixes

    • Updated logic to ensure tool versions are correctly detected from the new optional dependencies group.
    • Added fallback to hardcoded tool versions to guarantee version availability during installation.
  • Tests

    • Adjusted and expanded tests to validate the updated version lookup behavior, including fallback scenarios.
  • Chores

    • Updated dependency configuration to move tool dependencies into an optional group for better project organization.

@shenxianpeng shenxianpeng added the bug Something isn't working label Jul 16, 2025
@coderabbitai

coderabbitai Bot commented Jul 16, 2025

Copy link
Copy Markdown

@shenxianpeng shenxianpeng changed the title fix: Update pyproject.toml to move deps to optional fix: move clang tools deps to optional Jul 16, 2025
@codecov

codecov Bot commented Jul 16, 2025

Copy link
Copy Markdown

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 94.48%. Comparing base (73af16b) to head (b8eb49e).
Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main      #92      +/-   ##
==========================================
- Coverage   95.65%   94.48%   -1.17%     
==========================================
  Files           3        3              
  Lines         138      145       +7     
==========================================
+ Hits          132      137       +5     
- Misses          6        8       +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 73af16b and 789b90b.

📒 Files selected for processing (3)
  • cpp_linter_hooks/util.py (1 hunks)
  • pyproject.toml (1 hunks)
  • tests/test_util.py (3 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
tests/test_util.py (1)
cpp_linter_hooks/util.py (1)
  • get_version_from_dependency (16-30)
🔇 Additional comments (3)
pyproject.toml (1)

47-53: LGTM! Good architectural improvement.

Moving clang tools to optional dependencies is a sound design decision. This allows users to install the core package without the heavyweight clang tools, and the clear comment provides good guidance for maintainers about what belongs in this section.

tests/test_util.py (2)

104-112: LGTM! Test structure updated correctly.

The test data structure properly reflects the new optional-dependencies.tools format.


137-139: LGTM! Missing dependency test updated appropriately.

The test correctly validates the behavior when no matching dependency is found in the tools section.

Comment thread cpp_linter_hooks/util.py
Comment thread tests/test_util.py Outdated
Comment on lines +162 to +184
@pytest.mark.benchmark
def test_get_version_from_dependency_fallback_to_dependencies():
"""Test get_version_from_dependency falls back to project.dependencies."""
mock_toml_content = {
"project": {
"dependencies": [
"clang-format==20.1.7",
"clang-tidy==20.1.0",
"other-package==1.0.0",
]
}
}

with (
patch("pathlib.Path.exists", return_value=True),
patch("cpp_linter_hooks.util.tomllib.load", return_value=mock_toml_content),
):
result = get_version_from_dependency("clang-format")
assert result == "20.1.7"

result = get_version_from_dependency("clang-tidy")
assert result == "20.1.0"

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Verification agent

🧩 Analysis chain

Test expects fallback behavior that's missing in implementation.

This test validates fallback to the old dependencies structure, but the current implementation in cpp_linter_hooks/util.py doesn't include this fallback logic. The test will fail because the function only checks optional-dependencies.tools and returns None if not found there.

This test confirms that fallback functionality should exist but is missing from the implementation. Run this test to verify it fails:


🏁 Script executed:

#!/bin/bash
# Description: Run the specific fallback test to verify it fails due to missing implementation

python -m pytest tests/test_util.py::test_get_version_from_dependency_fallback_to_dependencies -v

Length of output: 9788


🏁 Script executed:

#!/bin/bash
rg -n "def get_version_from_dependency" -A 20 -B 5 cpp_linter_hooks/util.py

Length of output: 1002


Implement fallback to project.dependencies in get_version_from_dependency
The test test_get_version_from_dependency_fallback_to_dependencies fails because the function only looks under project.optional-dependencies.tools and never falls back to project.dependencies. You’ll need to update cpp_linter_hooks/util.py to try the old dependencies list before returning None.

Locations to update:
• cpp_linter_hooks/util.py, inside get_version_from_dependency (around lines 23–30)

Suggested patch:

     # First try project.optional-dependencies.tools
     optional_deps = data.get("project", {}).get("optional-dependencies", {})
     tools_deps = optional_deps.get("tools", [])
     for dep in tools_deps:
         if dep.startswith(f"{tool}=="):
             return dep.split("==")[1]

+    # Fallback to project.dependencies
+    project_deps = data.get("project", {}).get("dependencies", [])
+    for dep in project_deps:
+        if dep.startswith(f"{tool}=="):
+            return dep.split("==")[1]
+
     return None

Committable suggestion skipped: line range outside the PR's diff.

🤖 Prompt for AI Agents
In cpp_linter_hooks/util.py around lines 23 to 30, the function
get_version_from_dependency currently only checks
project.optional-dependencies.tools for the package version and does not fall
back to project.dependencies. Update the function to first attempt to find the
version in project.optional-dependencies.tools, and if not found, then search in
project.dependencies before returning None. This ensures the fallback behavior
tested in tests/test_util.py lines 162 to 184 works correctly.

@codspeed-hq

codspeed-hq Bot commented Jul 16, 2025

Copy link
Copy Markdown

CodSpeed Performance Report

Merging #92 will degrade performances by 10.35%

Comparing shenxianpeng-patch-1 (b8eb49e) with main (73af16b)

🎉 Hooray! pytest-codspeed just leveled up to 4.0.0!

A heads-up, this is a breaking change and it might affect your current performance baseline a bit. But here's the exciting part - it's packed with new, cool features and promises improved result stability 🥳!
Curious about what's new? Visit our releases page to delve into all the awesome details about this new version.

Summary

❌ 1 regressions
✅ 67 untouched benchmarks
🆕 1 new benchmarks

⚠️ Please fix the performance issues or acknowledge them on CodSpeed.

Benchmarks breakdown

Benchmark BASE HEAD Change
test_run_clang_tidy_invalid[args4-1] 757.9 µs 845.3 µs -10.35%
🆕 test_resolve_install_with_none_default_version N/A 1 ms N/A

@sonarqubecloud

Copy link
Copy Markdown

@shenxianpeng shenxianpeng merged commit d3169df into main Jul 16, 2025
15 of 17 checks passed
@shenxianpeng shenxianpeng deleted the shenxianpeng-patch-1 branch July 16, 2025 18:52
@shenxianpeng shenxianpeng changed the title fix: move clang tools deps to optional fix: move clang tools dependencies to optional Jul 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant