[PATCH] D50388: Respect PYTHONPATH

David Greene via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Aug 7 07:43:59 PDT 2018


greened created this revision.
greened added reviewers: hans, modocache, delcypher, ddunbar.
Herald added a subscriber: llvm-commits.

If a user has PYTHONPATH set in the environment, append new entries to it rather than blindly setting PYTHONPATH to a fixed string.  This allows tests to, for example, find psutil if it is in PYTHONPATH.  Without this change, lit will detect psutil but then various tests will fail because PYTHONPATH has been overwritten and psutil cannot be found.


Repository:
  rL LLVM

https://reviews.llvm.org/D50388

Files:
  utils/lit/tests/Inputs/shtest-timeout/lit.cfg
  utils/lit/tests/lit.cfg


Index: utils/lit/tests/lit.cfg
===================================================================
--- utils/lit/tests/lit.cfg
+++ utils/lit/tests/lit.cfg
@@ -34,7 +34,14 @@
 else:
   lit_path = src_root
 
-config.environment['PYTHONPATH'] = lit_path # Required because some tests import the lit module
+# Required because some tests import the lit module
+pythonpath_list = [lit_path]
+if 'PYTHONPATH' in os.environ:
+    pythonpath_list.append(os.environ['PYTHONPATH'])
+if 'PYTHONPATH' in config.environment:
+    pythonpath_list.append(config.environment['PYTHONPATH'])
+config.environment['PYTHONPATH'] = os.pathsep.join(pythonpath_list)
+
 config.substitutions.append(('%{src_root}', src_root))
 config.substitutions.append(('%{inputs}', os.path.join(
             src_root, 'tests', 'Inputs')))
Index: utils/lit/tests/Inputs/shtest-timeout/lit.cfg
===================================================================
--- utils/lit/tests/Inputs/shtest-timeout/lit.cfg
+++ utils/lit/tests/Inputs/shtest-timeout/lit.cfg
@@ -28,5 +28,12 @@
 config.test_exec_root = config.test_source_root
 config.target_triple = '(unused)'
 src_root = os.path.join(config.test_source_root, '..')
-config.environment['PYTHONPATH'] = src_root
+
+pythonpath_list = [src_root]
+if 'PYTHONPATH' in os.environ:
+    pythonpath_list.append(os.environ['PYTHONPATH'])
+if 'PYTHONPATH' in config.environment:
+    pythonpath_list.append(config.environment['PYTHONPATH'])
+config.environment['PYTHONPATH'] = os.pathsep.join(pythonpath_list)
+
 config.substitutions.append(('%{python}', sys.executable))


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D50388.159508.patch
Type: text/x-patch
Size: 1578 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180807/ed3b54d9/attachment.bin>


More information about the llvm-commits mailing list