Skip to content

Commit

Permalink
Update setup.py to parse __init__.py to get the version.
Browse files Browse the repository at this point in the history
This way it only needs to be updated in one place.
  • Loading branch information
kbrose committed Mar 9, 2018
1 parent 03b074c commit 2ec1f30
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,27 @@
from setuptools import setup, find_packages
from setuptools.command.install import install as _install

import os

init_file = os.path.join(os.path.split(__file__)[0], 'lib/tagnews/__init__.py')
with open(init_file) as f:
try:
s = f.read()
version_index = s.index('__version__')
version = s[version_index:].split('\n')[0].split("'")[1].strip()
# make sure it is in correct format by trying to parse it
[int(x) for x in version.split('.')]
assert len(version.split('.')) == 3
except Exception as e:
raise RuntimeError(
'Problem parsing lib/tagnews/__init__.py to get version.'
' Make sure somewhere in that file there is a line that'
' looks approximately like "__version__ = \'x.y.z\'",'
' including using single quotes, not double quotes.'
)

setup(name='tagnews',
version='1.0.1',
version=version,
description=('automatically tag articles with justice-related categories'
' and extract location information'),
author='Kevin Rose, Josh Herzberg, Matt Sweeney',
Expand Down

0 comments on commit 2ec1f30

Please sign in to comment.