Skip to content

Commit a10f27e

Browse files
fix typos and auto-obtain version from pkg_ressources
1 parent 4d840c3 commit a10f27e

File tree

3 files changed

+11
-2
lines changed

3 files changed

+11
-2
lines changed

CHANGELOG

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
obtain the current version number of a package from install metadata
1212
its used by default with the package name
1313
- add an eagerloading option and eagerload automatically
14-
if bpython is used
14+
if bpython is used (workaround for their monkeypatching)
1515

1616
1.2
1717
----------------------------------------

apipkg.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ def initpkg(pkgname, exportdefs, attr=dict(), eager=False):
4848
d['__file__'] = f
4949
if hasattr(oldmod, '__version__'):
5050
d['__version__'] = oldmod.__version__
51+
elif distribution_version(pkgname) is not None:
52+
d['__version__'] = distribution_version(pkgname)
5153
if hasattr(oldmod, '__loader__'):
5254
d['__loader__'] = oldmod.__loader__
5355
if hasattr(oldmod, '__path__'):
@@ -59,7 +61,7 @@ def initpkg(pkgname, exportdefs, attr=dict(), eager=False):
5961
oldmod.__dict__.update(d)
6062
mod = ApiModule(pkgname, exportdefs, implprefix=pkgname, attr=d)
6163
sys.modules[pkgname] = mod
62-
# eaerload in bypthon to avoid their monkeypatching breaking packages
64+
# eagerload in bypthon to avoid their monkeypatching breaking packages
6365
if 'bpython' in sys.modules or eager:
6466
for module in sys.modules.values():
6567
if isinstance(module, ApiModule):

test_apipkg.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -543,3 +543,10 @@ def test_eagerload_on_bython(monkeypatch):
543543
apipkg.initpkg(
544544
'apipkg.testmodule.example.lazy',
545545
{'test': 'apipkg.does_not_exist'})
546+
547+
548+
def test_autoset_version_attribute_from_distribution(monkeypatch):
549+
monkeypatch.setitem(sys.modules, 'setuptools', None)
550+
apipkg.initpkg('setuptools', {})
551+
552+
assert sys.modules['setuptools'].__version__

0 commit comments

Comments
 (0)