Skip to content

Commit

Permalink
perf: Avoid use of glob for fetching python executable
Browse files Browse the repository at this point in the history
glob on env/**/bin is slowest operation in terms of overhead on CLI.
  • Loading branch information
ankush committed Feb 23, 2024
1 parent 7c64aa3 commit 8db23dd
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions bench/utils/bench.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,21 @@

@lru_cache(maxsize=None)
def get_env_cmd(cmd: str, bench_path: str = ".") -> str:
# this supports envs' generated by patched virtualenv or venv (which may cause an extra 'local' folder to be created)
exact_location = os.path.abspath(
os.path.join(bench_path, "env", "bin", cmd.strip("*"))
)
if os.path.exists(exact_location):
return exact_location

# this supports envs' generated by patched virtualenv or venv (which may cause an extra 'local' folder to be created)
existing_python_bins = glob(
os.path.join(bench_path, "env", "**", "bin", cmd), recursive=True
)

if existing_python_bins:
return os.path.abspath(existing_python_bins[0])

cmd = cmd.strip("*")
return os.path.abspath(os.path.join(bench_path, "env", "bin", cmd))
return exact_location


def get_venv_path(verbose=False, python="python3"):
Expand Down

0 comments on commit 8db23dd

Please sign in to comment.