Skip to content

Commit fa6dbc4

Browse files
s0undt3chelprans
authored andcommitted
Allow grabbing the version information programmatically.
Yes, we could use `pkg_resources`, but that imposes a serious slowdown, see pypa/setuptools#510 for context.
1 parent eec98b0 commit fa6dbc4

File tree

4 files changed

+28
-14
lines changed

4 files changed

+28
-14
lines changed

.ci/package-version.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,17 @@
66

77

88
def main():
9-
setup_py = os.path.join(os.path.dirname(os.path.dirname(__file__)),
10-
'setup.py')
9+
version_file = os.path.join(os.path.dirname(os.path.dirname(__file__)),
10+
'asyncpg', '__init__.py')
1111

12-
with open(setup_py, 'r') as f:
12+
with open(version_file, 'r') as f:
1313
for line in f:
14-
if line.startswith('VERSION ='):
14+
if line.startswith('__version__ ='):
1515
_, _, version = line.partition('=')
1616
print(version.strip(" \n'\""))
1717
return 0
1818

19-
print('could not find package version in setup.py', file=sys.stderr)
19+
print('could not find package version in asyncpg/__init__.py', file=sys.stderr)
2020
return 1
2121

2222

asyncpg/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,5 @@
1414

1515
__all__ = ('connect', 'create_pool', 'Record', 'Connection') + \
1616
exceptions.__all__ # NOQA
17+
18+
__version__ = '0.12.0'

docs/conf.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,21 @@
22

33
import alabaster
44
import os
5-
import re
65
import sys
76

87
sys.path.insert(0, os.path.abspath('..'))
98

10-
with open(os.path.abspath('../setup.py'), 'rt') as f:
11-
_m = re.search(
12-
r'''VERSION\s*=\s*(?P<q>'|")(?P<ver>[\d\.]+)(?P=q)''', f.read())
13-
if not _m:
14-
raise RuntimeError('unable to read the version from setup.py')
15-
version = _m.group('ver')
16-
9+
version_file = os.path.join(os.path.dirname(os.path.dirname(__file__)),
10+
'asyncpg', '__init__.py')
11+
12+
with open(version_file, 'r') as f:
13+
for line in f:
14+
if line.startswith('__version__ ='):
15+
_, _, version = line.partition('=')
16+
version = version.strip(" \n'\"")
17+
break
18+
else:
19+
raise RuntimeError('unable to read the version from asyncpg/__init__.py')
1720

1821
# -- General configuration ------------------------------------------------
1922

setup.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
if sys.version_info < (3, 5):
1919
raise RuntimeError('asyncpg requires Python 3.5 or greater')
2020

21-
VERSION = '0.12.0'
2221
CFLAGS = ['-O2']
2322
LDFLAGS = []
2423

@@ -181,6 +180,16 @@ def _patch_cfile(self, cfile):
181180
readme = f.read()
182181

183182

183+
with open(os.path.join(os.path.dirname(__file__), 'asyncpg', '__init__.py')) as f:
184+
for line in f:
185+
if line.startswith('__version__ ='):
186+
_, _, version = line.partition('=')
187+
VERSION = version.strip(" \n'\"")
188+
break
189+
else:
190+
raise RuntimeError('unable to read the version from asyncpg/__init__.py')
191+
192+
184193
setuptools.setup(
185194
name='asyncpg',
186195
version=VERSION,

0 commit comments

Comments
 (0)