diff options
author | Kenn Knowles <kenn.knowles@gmail.com> | 2013-09-24 17:39:04 -0400 |
---|---|---|
committer | Kenn Knowles <kenn.knowles@gmail.com> | 2013-09-24 17:39:04 -0400 |
commit | d7c2072d583b87f24f5e437219e69617776f128b (patch) | |
tree | 4c2b52ba5276d6a6cf82d5f398006edc1bbb37e4 | |
parent | 0e46fb03006c628046c89765439e6a21a22abf73 (diff) | |
download | jsonpath-rw-d7c2072d583b87f24f5e437219e69617776f128b.tar.gz |
Add auto version based on git tags
-rw-r--r-- | jsonpath_rw/__init__.py | 1 | ||||
-rw-r--r-- | jsonpath_rw/version.py | 24 | ||||
-rw-r--r-- | setup.py | 25 |
3 files changed, 49 insertions, 1 deletions
diff --git a/jsonpath_rw/__init__.py b/jsonpath_rw/__init__.py index eb8244e..5666efb 100644 --- a/jsonpath_rw/__init__.py +++ b/jsonpath_rw/__init__.py @@ -1,2 +1,3 @@ from .jsonpath import * from .parser import parse +from .version import __version__ diff --git a/jsonpath_rw/version.py b/jsonpath_rw/version.py new file mode 100644 index 0000000..9d9e891 --- /dev/null +++ b/jsonpath_rw/version.py @@ -0,0 +1,24 @@ +from __future__ import print_function, unicode_literals +import io +import subprocess +import os.path + +__all__ = ['__version__', 'stored_version', 'git_version'] + +VERSION_PATH = os.path.join(os.path.dirname(__file__), 'VERSION') + +def stored_version(): + if os.path.exists(VERSION_PATH): + with io.open(VERSION_PATH, encoding='ascii') as fh: + return fh.read().strip() + else: + return None + +def git_version(): + described_version_bytes = subprocess.Popen(['git', 'describe'], stdout=subprocess.PIPE).communicate()[0].strip() + return described_version_bytes.decode('ascii') + +__version__ = stored_version() or git_version() + +if __name__ == '__main__': + print(__version__) @@ -4,6 +4,7 @@ import sys import os.path import subprocess +VERSION_PATH='jsonpath_rw/VERSION' # Build README.txt from README.md if not present, and if we are actually building for distribution to pypi if not os.path.exists('README.txt') and 'sdist' in sys.argv: @@ -17,9 +18,30 @@ try: except: long_description = 'Could not read README.txt' +# Ensure that the VERSION file is shipped with the distribution +if 'sdist' in sys.argv: + import jsonpath_rw.version + with io.open(VERSION_PATH, 'w', encoding='ascii') as fh: + fh.write(jsonpath_rw.version.git_version()) + +# This requires either jsonpath_rw/VERSION or to be in a git clone (as does the package in general) +# This is identical to code in jsonpath_rw.version. It would be nice to re-use but importing requires all deps +def stored_version(): + if os.path.exists(VERSION_PATH): + with io.open(VERSION_PATH, encoding='ascii') as fh: + return fh.read().strip() + else: + return None + +def git_version(): + described_version_bytes = subprocess.Popen(['git', 'describe'], stdout=subprocess.PIPE).communicate()[0].strip() + return described_version_bytes.decode('ascii') + +version = stored_version() or git_version() + setuptools.setup( name='jsonpath-rw', - version='1.2.0', + version=version, description='A robust and significantly extended implementation of JSONPath for Python, with a clear AST for metaprogramming.', author='Kenneth Knowles', author_email='kenn.knowles@gmail.com', @@ -27,6 +49,7 @@ setuptools.setup( license='Apache 2.0', long_description=long_description, packages = ['jsonpath_rw'], + package_data = {'': ['VERSION']}, test_suite = 'tests', install_requires = [ 'ply', 'decorator', 'six' ], classifiers = [ |