Skip to content

Commit 3e7c29b

Browse files
committed
Share version with code, setup.py and docs
1 parent 51c8193 commit 3e7c29b

2 files changed

Lines changed: 23 additions & 7 deletions

File tree

docs/conf.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@
1111
# All configuration values have a default; values that are commented out
1212
# serve to show the default.
1313

14-
import sys, os
14+
import sys
15+
import os
16+
import pkg_resources
1517

1618
# If extensions (or modules to document with autodoc) are in another directory,
1719
# add these directories to sys.path here. If the directory is relative to the
@@ -45,10 +47,17 @@
4547
# |version| and |release|, also used in various other places throughout the
4648
# built documents.
4749
#
50+
51+
try:
52+
release = pkg_resources.get_distribution('webstack-flask-jwt').version
53+
except pkg_resources.DistributionNotFound:
54+
print('webstack-flask-jwt must be installed to build the documentation.')
55+
print('Install from source using `pip install -e .` in a virtualenv.')
56+
sys.exit(1)
57+
4858
# The short X.Y version.
49-
version = '0.3.4'
50-
# The full version, including alpha/beta/rc tags.
51-
release = version
59+
version = '.'.join(release.split('.')[:2])
60+
5261

5362
# The language for content autogenerated by Sphinx. Refer to documentation
5463
# for a list of supported languages.

setup.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,26 @@
1515
<https://github.com/mattupstate/flask-jwt/raw/develop#egg=Flask-JWT-dev>`_
1616
1717
"""
18-
18+
import ast
1919
import sys
20+
import re
2021

2122
from setuptools import setup, find_packages
2223
from setuptools.command.test import test as TestCommand
2324

25+
_version_re = re.compile(r'__version__\s+=\s+(.*)')
26+
27+
PROJECT = 'flask_jwt'
28+
29+
with open(PROJECT + '/__init__.py', 'rb') as f:
30+
version = str(ast.literal_eval(_version_re.search(
31+
f.read().decode('utf-8')).group(1)))
2432

2533
def get_requirements(suffix=''):
2634
with open('requirements%s.txt' % suffix) as f:
2735
rv = f.read().splitlines()
2836
return rv
2937

30-
3138
def get_long_description():
3239
with open('README.rst') as f:
3340
rv = f.read()
@@ -54,7 +61,7 @@ def run_tests(self):
5461

5562
setup(
5663
name='webstack-flask-jwt',
57-
version='0.3.4',
64+
version=version,
5865
url='https://github.com/webstack/flask-jwt',
5966
license='MIT',
6067
author='Matt Wright',

0 commit comments

Comments
 (0)