Commit 5b2175eb authored by robnagler's avatar robnagler

uniquify paths in PYTHONPATH

When running in a complex environment with lots of installed
packages, PYTHONPATH gets way too long. Instead, just make sure
that paths_on_pythonpath doesn't contain duplicates
parent 0483cca4
...@@ -186,11 +186,12 @@ class test(Command): ...@@ -186,11 +186,12 @@ class test(Command):
orig_pythonpath = os.environ.get('PYTHONPATH', nothing) orig_pythonpath = os.environ.get('PYTHONPATH', nothing)
current_pythonpath = os.environ.get('PYTHONPATH', '') current_pythonpath = os.environ.get('PYTHONPATH', '')
try: try:
prefix = os.pathsep.join(paths) to_join = []
to_join = filter(None, [prefix, current_pythonpath]) for x in list(paths) + current_pythonpath.split(os.pathsep):
new_path = os.pathsep.join(to_join) if x not in to_join:
if new_path: to_join.append(x)
os.environ['PYTHONPATH'] = new_path if to_join:
os.environ['PYTHONPATH'] = os.pathsep.join(to_join)
yield yield
finally: finally:
if orig_pythonpath is nothing: if orig_pythonpath is nothing:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment