Revision: ee123e3d83fc
Author:   Pekka Klärck
Date:     Sat Jan 14 12:57:09 2012
Log: Reverted change to not process PYTHONPATH with Jython and IronPython.

Also added some more documentation why sys.path is modified in the first place.

Update issue 1034
Status: WontFix
Owner: -pekka.klarck
Labels: -Target-2.7
Now PYTHONPATH is processed again with Jython and IronPython.

Although I would like having ROBOTPATH that is supported with all
interpreters instead of processing PYTHONPATH, I don't think that's
worth the effort in near future.
http://code.google.com/p/robotframework/source/detail?r=ee123e3d83fc

Modified:
 /src/robot/pythonpathsetter.py

=======================================
--- /src/robot/pythonpathsetter.py      Fri Jan 13 06:02:08 2012
+++ /src/robot/pythonpathsetter.py      Sat Jan 14 12:57:09 2012
@@ -14,24 +14,37 @@

"""Module that adds directories needed by Robot to sys.path when imported."""

+import os
 import sys
 import fnmatch
 from os.path import abspath, dirname, join

 ROBOTDIR = dirname(abspath(__file__))
-PARENTDIR = dirname(ROBOTDIR)

 def add_path(path, end=False):
     if not end:
+        remove_path(path)
         sys.path.insert(0, path)
-    else:
+    elif not any(fnmatch.fnmatch(p, path) for p in sys.path):
         sys.path.append(path)

 def remove_path(path):
     sys.path = [p for p in sys.path if not fnmatch.fnmatch(p, path)]


-add_path(PARENTDIR)
+# When, for example, runner.py is executed as a script, the directory
+# containing robot module is not added to sys.path automatically but
+# the robot directory itself is. Former is added to allow importing
+# the module and the latter removed to prevent accidentally importing
+# internal modules directly.
+add_path(dirname(ROBOTDIR))
+remove_path(ROBOTDIR)
+
+# Default library search locations.
 add_path(join(ROBOTDIR, 'libraries'))
-add_path('.', end=True) # Jython adds this automatically so let's be consistent
-remove_path(ROBOTDIR)    # Prevent importing internal modules directly
+add_path('.', end=True)
+
+# Support libraries/resources in PYTHONPATH also with Jython and IronPython.
+for item in os.getenv('PYTHONPATH', '').split(os.pathsep):
+    add_path(abspath(item), end=True)
+

Reply via email to