Skip to content

Commit 583e9c3

Browse files
authored
fix: change resolve_install to public and include package data (#138)
* fix(pyproject.toml): add include-package-data to true * fix: include pyproject.toml * chore: Update pre-commit.yml add types * fix: update resolve_install to public
1 parent 8d893fa commit 583e9c3

File tree

6 files changed

+24
-19
lines changed

6 files changed

+24
-19
lines changed

.github/workflows/pre-commit.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ on:
44
push:
55
branches: main
66
pull_request:
7+
types: [opened, synchronize, reopened, edited]
78
branches: main
89
workflow_dispatch:
910

cpp_linter_hooks/clang_format.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from argparse import ArgumentParser
44
from typing import Tuple
55

6-
from cpp_linter_hooks.util import _resolve_install, DEFAULT_CLANG_FORMAT_VERSION
6+
from cpp_linter_hooks.util import resolve_install, DEFAULT_CLANG_FORMAT_VERSION
77

88

99
parser = ArgumentParser()
@@ -16,7 +16,7 @@
1616
def run_clang_format(args=None) -> Tuple[int, str]:
1717
hook_args, other_args = parser.parse_known_args(args)
1818
if hook_args.version:
19-
_resolve_install("clang-format", hook_args.version)
19+
resolve_install("clang-format", hook_args.version)
2020
command = ["clang-format", "-i"]
2121

2222
# Add verbose flag if requested

cpp_linter_hooks/clang_tidy.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from argparse import ArgumentParser
33
from typing import Tuple
44

5-
from cpp_linter_hooks.util import _resolve_install, DEFAULT_CLANG_TIDY_VERSION
5+
from cpp_linter_hooks.util import resolve_install, DEFAULT_CLANG_TIDY_VERSION
66

77

88
parser = ArgumentParser()
@@ -12,7 +12,7 @@
1212
def run_clang_tidy(args=None) -> Tuple[int, str]:
1313
hook_args, other_args = parser.parse_known_args(args)
1414
if hook_args.version:
15-
_resolve_install("clang-tidy", hook_args.version)
15+
resolve_install("clang-tidy", hook_args.version)
1616
command = ["clang-tidy"] + other_args
1717

1818
retval = 0

cpp_linter_hooks/util.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ def _install_tool(tool: str, version: str) -> Optional[Path]:
7272
return None
7373

7474

75-
def _resolve_install(tool: str, version: Optional[str]) -> Optional[Path]:
75+
def resolve_install(tool: str, version: Optional[str]) -> Optional[Path]:
7676
"""Resolve the installation of a tool, checking for version and installing if necessary."""
7777
user_version = _resolve_version(
7878
CLANG_FORMAT_VERSIONS if tool == "clang-format" else CLANG_TIDY_VERSIONS,

pyproject.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,10 @@ dev = [
5959
[tool.setuptools]
6060
zip-safe = false
6161
packages = ["cpp_linter_hooks"]
62+
include-package-data = true
63+
64+
[tool.setuptools.package-data]
65+
cpp_linter_hooks = ["../pyproject.toml"]
6266

6367
[tool.setuptools_scm]
6468
# It would be nice to include the commit hash in the version, but that

tests/test_util.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
get_version_from_dependency,
99
_resolve_version,
1010
_install_tool,
11-
_resolve_install,
11+
resolve_install,
1212
DEFAULT_CLANG_FORMAT_VERSION,
1313
DEFAULT_CLANG_TIDY_VERSION,
1414
)
@@ -159,22 +159,22 @@ def test_install_tool_success_but_not_found():
159159
assert result is None
160160

161161

162-
# Tests for _resolve_install
162+
# Tests for resolve_install
163163
@pytest.mark.benchmark
164164
def test_resolve_install_tool_already_installed_correct_version():
165-
"""Test _resolve_install when tool is already installed with correct version."""
165+
"""Test resolve_install when tool is already installed with correct version."""
166166
mock_path = "/usr/bin/clang-format"
167167

168168
with (
169169
patch("shutil.which", return_value=mock_path),
170170
):
171-
result = _resolve_install("clang-format", "20.1.7")
171+
result = resolve_install("clang-format", "20.1.7")
172172
assert Path(result) == Path(mock_path)
173173

174174

175175
@pytest.mark.benchmark
176176
def test_resolve_install_tool_version_mismatch():
177-
"""Test _resolve_install when tool has wrong version."""
177+
"""Test resolve_install when tool has wrong version."""
178178
mock_path = "/usr/bin/clang-format"
179179

180180
with (
@@ -183,39 +183,39 @@ def test_resolve_install_tool_version_mismatch():
183183
"cpp_linter_hooks.util._install_tool", return_value=Path(mock_path)
184184
) as mock_install,
185185
):
186-
result = _resolve_install("clang-format", "20.1.7")
186+
result = resolve_install("clang-format", "20.1.7")
187187
assert result == Path(mock_path)
188188

189189
mock_install.assert_called_once_with("clang-format", "20.1.7")
190190

191191

192192
@pytest.mark.benchmark
193193
def test_resolve_install_tool_not_installed():
194-
"""Test _resolve_install when tool is not installed."""
194+
"""Test resolve_install when tool is not installed."""
195195
with (
196196
patch("shutil.which", return_value=None),
197197
patch(
198198
"cpp_linter_hooks.util._install_tool",
199199
return_value=Path("/usr/bin/clang-format"),
200200
) as mock_install,
201201
):
202-
result = _resolve_install("clang-format", "20.1.7")
202+
result = resolve_install("clang-format", "20.1.7")
203203
assert result == Path("/usr/bin/clang-format")
204204

205205
mock_install.assert_called_once_with("clang-format", "20.1.7")
206206

207207

208208
@pytest.mark.benchmark
209209
def test_resolve_install_no_version_specified():
210-
"""Test _resolve_install when no version is specified."""
210+
"""Test resolve_install when no version is specified."""
211211
with (
212212
patch("shutil.which", return_value=None),
213213
patch(
214214
"cpp_linter_hooks.util._install_tool",
215215
return_value=Path("/usr/bin/clang-format"),
216216
) as mock_install,
217217
):
218-
result = _resolve_install("clang-format", None)
218+
result = resolve_install("clang-format", None)
219219
assert result == Path("/usr/bin/clang-format")
220220

221221
mock_install.assert_called_once_with(
@@ -225,15 +225,15 @@ def test_resolve_install_no_version_specified():
225225

226226
@pytest.mark.benchmark
227227
def test_resolve_install_invalid_version():
228-
"""Test _resolve_install with invalid version."""
228+
"""Test resolve_install with invalid version."""
229229
with (
230230
patch("shutil.which", return_value=None),
231231
patch(
232232
"cpp_linter_hooks.util._install_tool",
233233
return_value=Path("/usr/bin/clang-format"),
234234
) as mock_install,
235235
):
236-
result = _resolve_install("clang-format", "invalid.version")
236+
result = resolve_install("clang-format", "invalid.version")
237237
assert result == Path("/usr/bin/clang-format")
238238

239239
# Should fallback to default version
@@ -263,7 +263,7 @@ def test_version_lists_not_empty():
263263

264264
@pytest.mark.benchmark
265265
def test_resolve_install_with_none_default_version():
266-
"""Test _resolve_install when DEFAULT versions are None."""
266+
"""Test resolve_install when DEFAULT versions are None."""
267267
with (
268268
patch("shutil.which", return_value=None),
269269
patch("cpp_linter_hooks.util.DEFAULT_CLANG_FORMAT_VERSION", None),
@@ -273,7 +273,7 @@ def test_resolve_install_with_none_default_version():
273273
return_value=Path("/usr/bin/clang-format"),
274274
) as mock_install,
275275
):
276-
result = _resolve_install("clang-format", None)
276+
result = resolve_install("clang-format", None)
277277
assert result == Path("/usr/bin/clang-format")
278278

279279
# Should fallback to hardcoded version when DEFAULT is None

0 commit comments

Comments
 (0)