Skip to content

Commit aa60dc8

Browse files
florislaFloris Lambrechts
authored and
Floris Lambrechts
committed
Make __version__ a module-level attribute
By moving __version__ to __init__.py, it becomes an attribute of the module. This is recommended in PEP 396 and a common practice in many contemporary packages. This enables the following: >>> import mypackage >>> print(mypackage.__version__) '5.2.0'
1 parent 8aa151e commit aa60dc8

File tree

3 files changed

+5
-2
lines changed

3 files changed

+5
-2
lines changed

mypackage/__init__.py

+4
Original file line numberDiff line numberDiff line change
@@ -1 +1,5 @@
1+
2+
from .__version__ import VERSION
3+
__version__ = '.'.join(map(str, VERSION))
4+
15
from .core import *

mypackage/__version__.py

-2
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,3 @@
44
# 88 YY 88 dP 88 dP""""Yb YboodP 88 Yb dP""""Yb YboodP 888888
55

66
VERSION = (5, 2, 0)
7-
8-
__version__ = '.'.join(map(str, VERSION))

setup.py

+1
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
if not VERSION:
5151
with open(os.path.join(here, NAME, '__version__.py')) as f:
5252
exec(f.read(), about)
53+
about['__version__'] = '.'.join(map(str, about['VERSION']))
5354
else:
5455
about['__version__'] = VERSION
5556

0 commit comments

Comments
 (0)