1
0
mirror of https://github.com/esphome/esphome.git synced 2025-06-19 23:05:41 +01:00

clang-format and clang-tidy scripts: More robust algorithm to find correct executable ()

* More robust algorithm to find correct executable

* Revise message wording

* Add clang-tidy and clang-format to requirements.txt.
Add to message explaining install process.

* Extracted get_binary to helpers.py. Use execptions for clean exit.

* Add parameter types

* clang-{tidy,format} in requirements_test.txt
clean up script exit

* Kill processes on ^C

* Move clang-tidy and clang-format into requirements_dev.txt
This commit is contained in:
Clyde Stubbs
2024-01-03 16:00:52 +11:00
committed by GitHub
parent ae52164d9c
commit a2e152ad12
6 changed files with 78 additions and 46 deletions

@ -153,3 +153,39 @@ def load_idedata(environment):
temp_idedata.write_text(json.dumps(data, indent=2) + "\n")
return data
def get_binary(name: str, version: str) -> str:
binary_file = f"{name}-{version}"
try:
result = subprocess.check_output([binary_file, "-version"])
if result.returncode == 0:
return binary_file
except Exception:
pass
binary_file = name
try:
result = subprocess.run(
[binary_file, "-version"], text=True, capture_output=True
)
if result.returncode == 0 and (f"version {version}") in result.stdout:
return binary_file
raise FileNotFoundError(f"{name} not found")
except FileNotFoundError as ex:
print(
f"""
Oops. It looks like {name} is not installed. It should be available under venv/bin
and in PATH after running in turn:
script/setup
source venv/bin/activate.
Please confirm you can run "{name} -version" or "{name}-{version} -version"
in your terminal and install
{name} (v{version}) if necessary.
Note you can also upload your code as a pull request on GitHub and see the CI check
output to apply {name}
"""
)
raise