File tree Expand file tree Collapse file tree 2 files changed +27
-2
lines changed Expand file tree Collapse file tree 2 files changed +27
-2
lines changed Original file line number Diff line number Diff line change 11
11
12
12
__version__ = '1.3.dev'
13
13
14
+ def _py_abspath (path ):
15
+ """
16
+ special version of abspath
17
+ that will leave paths from jython jars alone
18
+ """
19
+ if path .startswith ('__pyclasspath__' ):
20
+ return path
21
+ else :
22
+ return os .path .abspath (path )
23
+
14
24
def initpkg (pkgname , exportdefs , attr = dict ()):
15
25
""" initialize given package from the export definitions. """
16
26
oldmod = sys .modules .get (pkgname )
17
27
d = {}
18
28
f = getattr (oldmod , '__file__' , None )
19
29
if f :
20
- f = os . path . abspath (f )
30
+ f = _py_abspath (f )
21
31
d ['__file__' ] = f
22
32
if hasattr (oldmod , '__version__' ):
23
33
d ['__version__' ] = oldmod .__version__
24
34
if hasattr (oldmod , '__loader__' ):
25
35
d ['__loader__' ] = oldmod .__loader__
26
36
if hasattr (oldmod , '__path__' ):
27
- d ['__path__' ] = [os . path . abspath (p ) for p in oldmod .__path__ ]
37
+ d ['__path__' ] = [_py_abspath (p ) for p in oldmod .__path__ ]
28
38
if '__doc__' not in exportdefs and getattr (oldmod , '__doc__' , None ):
29
39
d ['__doc__' ] = oldmod .__doc__
30
40
d .update (attr )
Original file line number Diff line number Diff line change @@ -253,6 +253,21 @@ def test_initpkg_not_transfers_not_existing_attrs(monkeypatch):
253
253
assert not hasattr (newmod , '__loader__' )
254
254
assert not hasattr (newmod , '__path__' )
255
255
256
+
257
+ def test_initpkg_not_changing_jython_paths (monkeypatch ):
258
+ mod = ModuleType ('hello' )
259
+ mod .__file__ = '__pyclasspath__/test.py'
260
+ mod .__path__ = ['__pyclasspath__/fun' , 'ichange' ]
261
+ monkeypatch .setitem (sys .modules , 'hello' , mod )
262
+ apipkg .initpkg ('hello' , {})
263
+ newmod = sys .modules ['hello' ]
264
+ assert newmod != mod
265
+ assert newmod .__file__ .startswith ('__pyclasspath__' )
266
+ unchanged , changed = newmod .__path__
267
+ assert changed != 'ichange'
268
+ assert unchanged .startswith ('__pyclasspath__' )
269
+
270
+
256
271
def test_initpkg_defaults (monkeypatch ):
257
272
mod = ModuleType ('hello' )
258
273
monkeypatch .setitem (sys .modules , 'hello' , mod )
You can’t perform that action at this time.
0 commit comments