adjust to new python pre-commit hooks (#7178)

Co-authored-by: Jesse Hills <3060199+jesserockz@users.noreply.github.com>
This commit is contained in:
tomaszduda23 2024-08-12 06:52:09 +02:00 committed by GitHub
parent 8a076cc906
commit f13cf1f7a0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 29 additions and 15 deletions

View file

@ -115,9 +115,10 @@ def clang_options(idedata):
pids = set() pids = set()
def run_tidy(executable, args, options, tmpdir, queue, lock, failed_files):
def run_tidy(executable, args, options, tmpdir, path_queue, lock, failed_files):
while True: while True:
path = queue.get() path = path_queue.get()
invocation = [executable] invocation = [executable]
if tmpdir is not None: if tmpdir is not None:
@ -139,17 +140,20 @@ def run_tidy(executable, args, options, tmpdir, queue, lock, failed_files):
invocation.append("--") invocation.append("--")
invocation.extend(options) invocation.extend(options)
proc = subprocess.run(invocation, capture_output=True, encoding="utf-8") proc = subprocess.run(
invocation, capture_output=True, encoding="utf-8", check=False
)
if proc.returncode != 0: if proc.returncode != 0:
with lock: with lock:
print_error_for_file(path, proc.stdout) print_error_for_file(path, proc.stdout)
failed_files.append(path) failed_files.append(path)
queue.task_done() path_queue.task_done()
def progress_bar_show(value): def progress_bar_show(value):
if value is None: if value is None:
return "" return ""
return None
def split_list(a, n): def split_list(a, n):
@ -237,7 +241,15 @@ def main():
for _ in range(args.jobs): for _ in range(args.jobs):
t = threading.Thread( t = threading.Thread(
target=run_tidy, target=run_tidy,
args=(executable, args, options, tmpdir, task_queue, lock, failed_files), args=(
executable,
args,
options,
tmpdir,
task_queue,
lock,
failed_files,
),
) )
t.daemon = True t.daemon = True
t.start() t.start()
@ -245,14 +257,14 @@ def main():
# Fill the queue with files. # Fill the queue with files.
with click.progressbar( with click.progressbar(
files, width=30, file=sys.stderr, item_show_func=progress_bar_show files, width=30, file=sys.stderr, item_show_func=progress_bar_show
) as bar: ) as progress_bar:
for name in bar: for name in progress_bar:
task_queue.put(name) task_queue.put(name)
# Wait for all threads to be done. # Wait for all threads to be done.
task_queue.join() task_queue.join()
except FileNotFoundError as ex: except FileNotFoundError:
return 1 return 1
except KeyboardInterrupt: except KeyboardInterrupt:
print() print()
@ -262,7 +274,7 @@ def main():
# Kill subprocesses (and ourselves!) # Kill subprocesses (and ourselves!)
# No simple, clean alternative appears to be available. # No simple, clean alternative appears to be available.
os.kill(0, 9) os.kill(0, 9)
return 2 # Will not execute. return 2 # Will not execute.
if args.fix and failed_files: if args.fix and failed_files:
print("Applying fixes ...") print("Applying fixes ...")
@ -272,7 +284,10 @@ def main():
except FileNotFoundError: except FileNotFoundError:
subprocess.call(["clang-apply-replacements", tmpdir]) subprocess.call(["clang-apply-replacements", tmpdir])
except FileNotFoundError: except FileNotFoundError:
print("Error please install clang-apply-replacements-14 or clang-apply-replacements.\n", file=sys.stderr) print(
"Error please install clang-apply-replacements-14 or clang-apply-replacements.\n",
file=sys.stderr,
)
except: except:
print("Error applying fixes.\n", file=sys.stderr) print("Error applying fixes.\n", file=sys.stderr)
raise raise

View file

@ -159,20 +159,19 @@ def get_binary(name: str, version: str) -> str:
binary_file = f"{name}-{version}" binary_file = f"{name}-{version}"
try: try:
result = subprocess.check_output([binary_file, "-version"]) result = subprocess.check_output([binary_file, "-version"])
if result.returncode == 0: return binary_file
return binary_file except FileNotFoundError:
except Exception:
pass pass
binary_file = name binary_file = name
try: try:
result = subprocess.run( result = subprocess.run(
[binary_file, "-version"], text=True, capture_output=True [binary_file, "-version"], text=True, capture_output=True, check=False
) )
if result.returncode == 0 and (f"version {version}") in result.stdout: if result.returncode == 0 and (f"version {version}") in result.stdout:
return binary_file return binary_file
raise FileNotFoundError(f"{name} not found") raise FileNotFoundError(f"{name} not found")
except FileNotFoundError as ex: except FileNotFoundError:
print( print(
f""" f"""
Oops. It looks like {name} is not installed. It should be available under venv/bin Oops. It looks like {name} is not installed. It should be available under venv/bin