Skip to content

Commit

Permalink
BUG: Apply ASV_PYTHONPATH to discovery
Browse files Browse the repository at this point in the history
  • Loading branch information
HaoZeke committed Jan 23, 2025
1 parent 2b7ab92 commit 507fda6
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions asv/benchmark.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,25 @@ def main():
mode = sys.argv[1]
args = sys.argv[2:]

env = os.environ.copy()
# --- Modify sys.path for the current interpreter ---
if 'ASV_PYTHONPATH' in env:
new_paths = env['ASV_PYTHONPATH'].split(os.pathsep)
for path in reversed(new_paths): # Add to the front to prioritize
if path not in sys.path:
sys.path.insert(0, path)
# Remove ASV_PYTHONPATH from env, as it's no longer needed after sys.path update
env.pop('ASV_PYTHONPATH')
else:
# Clean up sys.path if PYTHONPATH was set but ASV_PYTHONPATH is not
if 'PYTHONPATH' in env:
old_paths = env['PYTHONPATH'].split(os.pathsep)
for path in old_paths:
if path in sys.path:
sys.path.remove(path)

env.pop('PYTHONPATH')

if mode in commands:
commands[mode](args)
sys.exit(0)
Expand Down

0 comments on commit 507fda6

Please sign in to comment.