diff --git a/.github/workflows/pre-commit.yml b/.github/workflows/pre-commit.yml index 01775b0..a856754 100644 --- a/.github/workflows/pre-commit.yml +++ b/.github/workflows/pre-commit.yml @@ -4,6 +4,7 @@ on: push: branches: main pull_request: + types: [opened, synchronize, reopened, edited] branches: main workflow_dispatch: diff --git a/cpp_linter_hooks/clang_format.py b/cpp_linter_hooks/clang_format.py index 0cd0d34..da891e3 100644 --- a/cpp_linter_hooks/clang_format.py +++ b/cpp_linter_hooks/clang_format.py @@ -3,7 +3,7 @@ from argparse import ArgumentParser from typing import Tuple -from cpp_linter_hooks.util import _resolve_install, DEFAULT_CLANG_FORMAT_VERSION +from cpp_linter_hooks.util import resolve_install, DEFAULT_CLANG_FORMAT_VERSION parser = ArgumentParser() @@ -16,7 +16,7 @@ def run_clang_format(args=None) -> Tuple[int, str]: hook_args, other_args = parser.parse_known_args(args) if hook_args.version: - _resolve_install("clang-format", hook_args.version) + resolve_install("clang-format", hook_args.version) command = ["clang-format", "-i"] # Add verbose flag if requested diff --git a/cpp_linter_hooks/clang_tidy.py b/cpp_linter_hooks/clang_tidy.py index f1cb163..1a5c8f0 100644 --- a/cpp_linter_hooks/clang_tidy.py +++ b/cpp_linter_hooks/clang_tidy.py @@ -2,7 +2,7 @@ from argparse import ArgumentParser from typing import Tuple -from cpp_linter_hooks.util import _resolve_install, DEFAULT_CLANG_TIDY_VERSION +from cpp_linter_hooks.util import resolve_install, DEFAULT_CLANG_TIDY_VERSION parser = ArgumentParser() @@ -12,7 +12,7 @@ def run_clang_tidy(args=None) -> Tuple[int, str]: hook_args, other_args = parser.parse_known_args(args) if hook_args.version: - _resolve_install("clang-tidy", hook_args.version) + resolve_install("clang-tidy", hook_args.version) command = ["clang-tidy"] + other_args retval = 0 diff --git a/cpp_linter_hooks/util.py b/cpp_linter_hooks/util.py index 37d431a..ebd48a3 100644 --- a/cpp_linter_hooks/util.py +++ b/cpp_linter_hooks/util.py @@ -72,7 +72,7 @@ def _install_tool(tool: str, version: str) -> Optional[Path]: return None -def _resolve_install(tool: str, version: Optional[str]) -> Optional[Path]: +def resolve_install(tool: str, version: Optional[str]) -> Optional[Path]: """Resolve the installation of a tool, checking for version and installing if necessary.""" user_version = _resolve_version( CLANG_FORMAT_VERSIONS if tool == "clang-format" else CLANG_TIDY_VERSIONS, diff --git a/pyproject.toml b/pyproject.toml index 3ebd612..b3a5982 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -59,6 +59,10 @@ dev = [ [tool.setuptools] zip-safe = false packages = ["cpp_linter_hooks"] +include-package-data = true + +[tool.setuptools.package-data] +cpp_linter_hooks = ["../pyproject.toml"] [tool.setuptools_scm] # It would be nice to include the commit hash in the version, but that diff --git a/tests/test_util.py b/tests/test_util.py index 38d5e6d..8305ba0 100644 --- a/tests/test_util.py +++ b/tests/test_util.py @@ -8,7 +8,7 @@ get_version_from_dependency, _resolve_version, _install_tool, - _resolve_install, + resolve_install, DEFAULT_CLANG_FORMAT_VERSION, DEFAULT_CLANG_TIDY_VERSION, ) @@ -159,22 +159,22 @@ def test_install_tool_success_but_not_found(): assert result is None -# Tests for _resolve_install +# Tests for resolve_install @pytest.mark.benchmark def test_resolve_install_tool_already_installed_correct_version(): - """Test _resolve_install when tool is already installed with correct version.""" + """Test resolve_install when tool is already installed with correct version.""" mock_path = "/usr/bin/clang-format" with ( patch("shutil.which", return_value=mock_path), ): - result = _resolve_install("clang-format", "20.1.7") + result = resolve_install("clang-format", "20.1.7") assert Path(result) == Path(mock_path) @pytest.mark.benchmark def test_resolve_install_tool_version_mismatch(): - """Test _resolve_install when tool has wrong version.""" + """Test resolve_install when tool has wrong version.""" mock_path = "/usr/bin/clang-format" with ( @@ -183,7 +183,7 @@ def test_resolve_install_tool_version_mismatch(): "cpp_linter_hooks.util._install_tool", return_value=Path(mock_path) ) as mock_install, ): - result = _resolve_install("clang-format", "20.1.7") + result = resolve_install("clang-format", "20.1.7") assert result == Path(mock_path) mock_install.assert_called_once_with("clang-format", "20.1.7") @@ -191,7 +191,7 @@ def test_resolve_install_tool_version_mismatch(): @pytest.mark.benchmark def test_resolve_install_tool_not_installed(): - """Test _resolve_install when tool is not installed.""" + """Test resolve_install when tool is not installed.""" with ( patch("shutil.which", return_value=None), patch( @@ -199,7 +199,7 @@ def test_resolve_install_tool_not_installed(): return_value=Path("/usr/bin/clang-format"), ) as mock_install, ): - result = _resolve_install("clang-format", "20.1.7") + result = resolve_install("clang-format", "20.1.7") assert result == Path("/usr/bin/clang-format") mock_install.assert_called_once_with("clang-format", "20.1.7") @@ -207,7 +207,7 @@ def test_resolve_install_tool_not_installed(): @pytest.mark.benchmark def test_resolve_install_no_version_specified(): - """Test _resolve_install when no version is specified.""" + """Test resolve_install when no version is specified.""" with ( patch("shutil.which", return_value=None), patch( @@ -215,7 +215,7 @@ def test_resolve_install_no_version_specified(): return_value=Path("/usr/bin/clang-format"), ) as mock_install, ): - result = _resolve_install("clang-format", None) + result = resolve_install("clang-format", None) assert result == Path("/usr/bin/clang-format") mock_install.assert_called_once_with( @@ -225,7 +225,7 @@ def test_resolve_install_no_version_specified(): @pytest.mark.benchmark def test_resolve_install_invalid_version(): - """Test _resolve_install with invalid version.""" + """Test resolve_install with invalid version.""" with ( patch("shutil.which", return_value=None), patch( @@ -233,7 +233,7 @@ def test_resolve_install_invalid_version(): return_value=Path("/usr/bin/clang-format"), ) as mock_install, ): - result = _resolve_install("clang-format", "invalid.version") + result = resolve_install("clang-format", "invalid.version") assert result == Path("/usr/bin/clang-format") # Should fallback to default version @@ -263,7 +263,7 @@ def test_version_lists_not_empty(): @pytest.mark.benchmark def test_resolve_install_with_none_default_version(): - """Test _resolve_install when DEFAULT versions are None.""" + """Test resolve_install when DEFAULT versions are None.""" with ( patch("shutil.which", return_value=None), patch("cpp_linter_hooks.util.DEFAULT_CLANG_FORMAT_VERSION", None), @@ -273,7 +273,7 @@ def test_resolve_install_with_none_default_version(): return_value=Path("/usr/bin/clang-format"), ) as mock_install, ): - result = _resolve_install("clang-format", None) + result = resolve_install("clang-format", None) assert result == Path("/usr/bin/clang-format") # Should fallback to hardcoded version when DEFAULT is None