Skip to content

Commit 7bb0bac

Browse files
merge
2 parents 8263534 + 14e0303 commit 7bb0bac

File tree

3 files changed

+28
-3
lines changed

3 files changed

+28
-3
lines changed

apipkg.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,30 @@
1111

1212
__version__ = '1.3.dev'
1313

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+
1424
def initpkg(pkgname, exportdefs, attr=dict()):
1525
""" initialize given package from the export definitions. """
1626
oldmod = sys.modules.get(pkgname)
1727
d = {}
1828
f = getattr(oldmod, '__file__', None)
1929
if f:
20-
f = os.path.abspath(f)
30+
f = _py_abspath(f)
2131
d['__file__'] = f
2232
if hasattr(oldmod, '__version__'):
2333
d['__version__'] = oldmod.__version__
2434
if hasattr(oldmod, '__loader__'):
2535
d['__loader__'] = oldmod.__loader__
2636
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__]
2838
if '__doc__' not in exportdefs and getattr(oldmod, '__doc__', None):
2939
d['__doc__'] = oldmod.__doc__
3040
d.update(attr)

test_apipkg.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,21 @@ def test_initpkg_not_transfers_not_existing_attrs(monkeypatch):
253253
assert not hasattr(newmod, '__loader__')
254254
assert not hasattr(newmod, '__path__')
255255

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+
256271
def test_initpkg_defaults(monkeypatch):
257272
mod = ModuleType('hello')
258273
monkeypatch.setitem(sys.modules, 'hello', mod)

tox.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[tox]
2-
envlist=py27,py26,py25,py24,py31
2+
envlist=py27,py26,py25,py24,py31,py32,jython
33

44
[tox:hudson]
55
sdistsrc={distshare}/apipkg-*

0 commit comments

Comments
 (0)