Commits

Ronny Pfannschmidt committed 8305b03

alter initpkg to leave paths from jython jars alone

  • Participants
  • Parent commits 2f51649

Comments (0)

Files changed (2)

 
 __version__ = '1.3.dev'
 
+def _py_abspath(path):
+    """
+    special version of abspath
+    that will leave paths from jython jars alone
+    """
+    if path.startswith('__pyclasspath__'):
+        return path
+    else:
+        return os.path.abspath(path)
+
 def initpkg(pkgname, exportdefs, attr=dict()):
     """ initialize given package from the export definitions. """
     oldmod = sys.modules.get(pkgname)
     d = {}
     f = getattr(oldmod, '__file__', None)
     if f:
-        f = os.path.abspath(f)
+        f = _py_abspath(f)
     d['__file__'] = f
     if hasattr(oldmod, '__version__'):
         d['__version__'] = oldmod.__version__
     if hasattr(oldmod, '__loader__'):
         d['__loader__'] = oldmod.__loader__
     if hasattr(oldmod, '__path__'):
-        d['__path__'] = [os.path.abspath(p) for p in oldmod.__path__]
+        d['__path__'] = [_py_abspath(p) for p in oldmod.__path__]
     if '__doc__' not in exportdefs and getattr(oldmod, '__doc__', None):
         d['__doc__'] = oldmod.__doc__
     d.update(attr)
     assert not hasattr(newmod, '__loader__')
     assert not hasattr(newmod, '__path__')
 
+
+def test_initpkg_not_changing_jython_paths(monkeypatch):
+    mod = ModuleType('hello')
+    mod.__file__ = '__pyclasspath__/test.py'
+    mod.__path__ = ['__pyclasspath__/fun', 'ichange']
+    monkeypatch.setitem(sys.modules, 'hello', mod)
+    apipkg.initpkg('hello', {})
+    newmod = sys.modules['hello']
+    assert newmod != mod
+    assert newmod.__file__.startswith('__pyclasspath__')
+    unchanged, changed = newmod.__path__
+    assert changed != 'ichange'
+    assert unchanged.startswith('__pyclasspath__')
+
+
 def test_initpkg_defaults(monkeypatch):
     mod = ModuleType('hello')
     monkeypatch.setitem(sys.modules, 'hello', mod)