Skip to content

Commit

Permalink
make printing the found binary conditional on ENV
Browse files Browse the repository at this point in the history
  • Loading branch information
renefritze committed Jan 10, 2024
1 parent ba761b1 commit ae8a82e
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,8 @@ This repository extends the great work of several other projects:
* The CI build process is controlled by [cibuildwheel](https://github.com/pypa/cibuildwheel) which makes building wheels across a number of platforms a pleasant experience (!)

We are grateful for the generous provisioning with CI resources that GitHub currently offers to Open Source projects.

## Troubleshooting

To see which clang-tidy binary the package is using
you can set `CLANG_TIDY_WHEEL_VERBOSE` to `1` in your environment.
4 changes: 3 additions & 1 deletion clang_tidy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from pathlib import Path
import functools
import pkg_resources
import os


@functools.lru_cache(maxsize=None)
Expand All @@ -11,7 +12,8 @@ def _get_executable(name:str) -> Path:
for s in ("", ".exe", ".bin", ".dmg")]
for exe in possibles:
if exe.exists():
print(f'Resource filename: {exe} ')
if os.environ.get("CLANG_TIDY_WHEEL_VERBOSE", None):
print(f'Found binary: {exe} ')
return exe

raise FileNotFoundError(f"No executable found for {name} at\n{possibles}")
Expand Down
13 changes: 12 additions & 1 deletion test/test_executable.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,14 @@ def ensure_tidy_from_wheel(monkeypatch):
monkeypatch.delitem(sys.modules, "clang_tidy", raising=False)


def test_executable_file():
def test_executable_file(capsys):
import clang_tidy

clang_tidy._get_executable.cache_clear()
exe = clang_tidy._get_executable("clang-tidy")
assert os.path.exists(exe)
assert os.access(exe, os.X_OK)
assert capsys.readouterr().out == ""


def _test_code(code: str):
Expand All @@ -40,6 +42,15 @@ def _test_code(code: str):
os.remove(compilation_unit)


def test_verbose_output(capsys, monkeypatch):
import clang_tidy
monkeypatch.setenv("CLANG_TIDY_WHEEL_VERBOSE", "1")
# need to clear cache to make sure the function is run again
clang_tidy._get_executable.cache_clear()
clang_tidy._get_executable("clang-tidy")
assert capsys.readouterr().out


@pytest.mark.skipif(
os.environ.get("CI", None) and "linux" in sys.platform,
reason="https://github.com/ssciwr/clang-tidy-wheel/issues/30",
Expand Down

0 comments on commit ae8a82e

Please sign in to comment.