Skip to content
Snippets Groups Projects
Commit 1882e0de authored by Andre Maroneze's avatar Andre Maroneze
Browse files

[analysis-scripts] add support for pyinstaller bundle in source_filter

parent 5d8501d2
No related branches found
No related tags found
No related merge requests found
...@@ -46,24 +46,39 @@ import sys ...@@ -46,24 +46,39 @@ import sys
# warnings about missing commands are disabled during testing # warnings about missing commands are disabled during testing
emit_warns = os.getenv("PTESTS_TESTING") is None emit_warns = os.getenv("PTESTS_TESTING") is None
# Returns a Path to the command binary, or None if it is not found # Cache for get_command
# Emits a warning the first time it looks for a command cached_commands = {}
warned = {}
def resource_path(relative_path):
"""Get absolute path to resource; only used by the pyinstaller standalone distribution"""
base_path = getattr(sys, "_MEIPASS", os.path.dirname(os.path.abspath(__file__)))
return os.path.join(base_path, relative_path)
def get_command(command, env_var_name): def get_command(command, env_var_name):
"""Returns a Path to the command; priority goes to the environment variable,
then in the PATH, then in the resource directory (for a pyinstaller binary)."""
if command in cached_commands:
return cached_commands[command]
p = os.getenv(env_var_name) p = os.getenv(env_var_name)
if not p: if p:
p = Path(p)
else:
p = shutil.which(command) p = shutil.which(command)
if not p: if p:
if emit_warns and command not in warned: p = Path(p)
print( else:
f"info: optional external command '{command}' not found in PATH; \ p = Path(resource_path(command))
if not p.exists():
if emit_warns:
print(
f"info: optional external command '{command}' not found in PATH; \
consider installing it or setting environment variable {env_var_name}" consider installing it or setting environment variable {env_var_name}"
) )
warned[command] = True p = None
return None cached_commands[command] = p
return Path(p) return p
def run_and_check(command_and_args, input_data): def run_and_check(command_and_args, input_data):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment