Skip to content

Commit af9e4ba

Browse files
committed
Switched to using new get_version() in setup.py
1 parent bf03705 commit af9e4ba

File tree

1 file changed

+14
-10
lines changed

1 file changed

+14
-10
lines changed

setup.py

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,22 @@
11
#!/usr/bin/env python
22
# -*- coding: utf-8 -*-
33
import os
4+
import re
45
import sys
56

67
from setuptools import find_packages, setup
78

8-
__version__ = None
9-
with open('jwt/__init__.py') as fp:
10-
_locals = {}
11-
for line in fp:
12-
if line.startswith('__version__'):
13-
exec(line, None, _locals)
14-
__version__ = _locals['__version__']
15-
break
9+
10+
def get_version(package):
11+
"""
12+
Return package version as listed in `__version__` in `init.py`.
13+
"""
14+
with open(os.path.join(package, '__init__.py'), 'rb') as init_py:
15+
src = init_py.read().decode('utf-8')
16+
return re.search("__version__ = ['\"]([^'\"]+)['\"]", src).group(1)
17+
18+
19+
version = get_version('jwt')
1620

1721
with open(os.path.join(os.path.dirname(__file__), 'README.md')) as readme:
1822
long_description = readme.read()
@@ -21,7 +25,7 @@
2125
os.system('python setup.py sdist upload')
2226
os.system('python setup.py bdist_wheel upload')
2327
print('You probably want to also tag the version now:')
24-
print(" git tag -a {0} -m 'version {0}'".format(__version__))
28+
print(" git tag -a {0} -m 'version {0}'".format(version))
2529
print(' git push --tags')
2630
sys.exit()
2731

@@ -33,7 +37,7 @@
3337

3438
setup(
3539
name='PyJWT',
36-
version=__version__,
40+
version=version,
3741
author='José Padilla',
3842
author_email='hello@jpadilla.com',
3943
description='JSON Web Token implementation in Python',

0 commit comments

Comments
 (0)