Skip to content

Commit

Permalink
Allow grabbing the version information programmatically.
Browse files Browse the repository at this point in the history
Yes, we could use `pkg_resources`, but that imposes a serious slowdown,
see pypa/setuptools#510 for context.
  • Loading branch information
s0undt3ch authored and elprans committed Sep 27, 2017
1 parent eec98b0 commit fa6dbc4
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 14 deletions.
10 changes: 5 additions & 5 deletions .ci/package-version.py
Expand Up @@ -6,17 +6,17 @@


def main():
setup_py = os.path.join(os.path.dirname(os.path.dirname(__file__)),
'setup.py')
version_file = os.path.join(os.path.dirname(os.path.dirname(__file__)),
'asyncpg', '__init__.py')

with open(setup_py, 'r') as f:
with open(version_file, 'r') as f:
for line in f:
if line.startswith('VERSION ='):
if line.startswith('__version__ ='):
_, _, version = line.partition('=')
print(version.strip(" \n'\""))
return 0

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


Expand Down
2 changes: 2 additions & 0 deletions asyncpg/__init__.py
Expand Up @@ -14,3 +14,5 @@

__all__ = ('connect', 'create_pool', 'Record', 'Connection') + \
exceptions.__all__ # NOQA

__version__ = '0.12.0'
19 changes: 11 additions & 8 deletions docs/conf.py
Expand Up @@ -2,18 +2,21 @@

import alabaster
import os
import re
import sys

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

with open(os.path.abspath('../setup.py'), 'rt') as f:
_m = re.search(
r'''VERSION\s*=\s*(?P<q>'|")(?P<ver>[\d\.]+)(?P=q)''', f.read())
if not _m:
raise RuntimeError('unable to read the version from setup.py')
version = _m.group('ver')

version_file = os.path.join(os.path.dirname(os.path.dirname(__file__)),
'asyncpg', '__init__.py')

with open(version_file, 'r') as f:
for line in f:
if line.startswith('__version__ ='):
_, _, version = line.partition('=')
version = version.strip(" \n'\"")
break
else:
raise RuntimeError('unable to read the version from asyncpg/__init__.py')

# -- General configuration ------------------------------------------------

Expand Down
11 changes: 10 additions & 1 deletion setup.py
Expand Up @@ -18,7 +18,6 @@
if sys.version_info < (3, 5):
raise RuntimeError('asyncpg requires Python 3.5 or greater')

VERSION = '0.12.0'
CFLAGS = ['-O2']
LDFLAGS = []

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


with open(os.path.join(os.path.dirname(__file__), 'asyncpg', '__init__.py')) as f:
for line in f:
if line.startswith('__version__ ='):
_, _, version = line.partition('=')
VERSION = version.strip(" \n'\"")
break
else:
raise RuntimeError('unable to read the version from asyncpg/__init__.py')


setuptools.setup(
name='asyncpg',
version=VERSION,
Expand Down

0 comments on commit fa6dbc4

Please sign in to comment.