From 13dab0c5a88f8e915f12b5b666d271c1efcd34db Mon Sep 17 00:00:00 2001 From: Joel Dunham Date: Mon, 9 Apr 2018 13:35:49 -0700 Subject: [PATCH] Fix setup.py version retrieval --- .gitignore | 1 + setup.py | 29 +++++++++++++++++++++-------- 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/.gitignore b/.gitignore index 3be99ef..6199df0 100644 --- a/.gitignore +++ b/.gitignore @@ -4,6 +4,7 @@ # Byte-compiled / optimized / DLL files __pycache__/ *.py[cod] +.pytest_cache/ # C extensions *.so diff --git a/setup.py b/setup.py index 3a3bd97..3b2de78 100644 --- a/setup.py +++ b/setup.py @@ -5,24 +5,37 @@ https://github.com/pypa/sampleproject """ -# Always prefer setuptools over distutils -from setuptools import setup, find_packages -# To use a consistent encoding -from codecs import open +import codecs from os import path +import re -from metsrw import __version__ +from setuptools import setup, find_packages here = path.abspath(path.dirname(__file__)) + +def read(*parts): + with codecs.open(path.join(here, *parts), 'r') as fp: + return fp.read() + + +def find_version(*file_paths): + version_file = read(*file_paths) + version_match = re.search(r"^__version__ = ['\"]([^'\"]*)['\"]", + version_file, re.M) + if version_match: + return version_match.group(1) + raise RuntimeError("Unable to find version string.") + + # Get the long description from the relevant file -with open(path.join(here, 'README.md'), encoding='utf-8') as f: +with codecs.open(path.join(here, 'README.md'), encoding='utf-8') as f: long_description = f.read() setup( name='metsrw', - version=__version__, + version=find_version('metsrw', '__init__.py'), description='Library for dealing with METS files.', long_description=long_description, @@ -48,7 +61,7 @@ packages=find_packages(exclude=['docs', 'fixtures', 'requirements', 'tests*']), - install_requires=['lxml', 'six'], + install_requires=['future', 'lxml', 'six'], include_package_data=True )