8000 Add auto version based on git tags · joshbenner/python-jsonpath-rw@d7c2072 · GitHub
[go: up one dir, main page]

Skip to content

Commit d7c2072

Browse files
committed
Add auto version based on git tags
1 parent 0e46fb0 commit d7c2072

File tree

3 files changed

+49
-1
lines changed

3 files changed

+49
-1
lines changed

jsonpath_rw/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
from .jsonpath import *
22
from .parser import parse
3+
from .version import __version__

jsonpath_rw/version.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
from __future__ import print_function, unicode_literals
2+
import io
3+
import subprocess
4+
import os.path
5+
6+
__all__ = ['__version__', 'stored_version', 'git_version']
7+
8+
VERSION_PATH = os.path.join(os.path.dirname(__file__), 'VERSION')
9+
10+
def stored_version():
11+
if os.path.exists(VERSION_PATH):
12+
with io.open(VERSION_PATH, encoding='ascii') as fh:
13+
return fh.read().strip()
14+
else:
15+
return None
16+
17+
def git_version():
18+
described_version_bytes = subprocess.Popen(['git', 'describe'], stdout=subprocess.PIPE).communicate()[0].strip()
19+
return described_version_bytes.decode('ascii')
20+
21+
__version__ = stored_version() or git_version()
22+
23+
if __name__ == '__main__':
24+
print(__version__)

setup.py

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import os.path
55
import subprocess
66

7+
VERSION_PATH='jsonpath_rw/VERSION'
78

89
# Build README.txt from README.md if not present, and if we are actually building for distribution to pypi
910
if not os.path.exists('README.txt') and 'sdist' in sys.argv:
@@ -17,16 +18,38 @@
1718
except:
1819
long_description = 'Could not read README.txt'
1920

21+
# Ensure that the VERSION file is shipped with the distribution
22+
if 'sdist' in sys.argv:
23+
import jsonpath_rw.version
24+
with io.open(VERSION_PATH, 'w', encoding='ascii') as fh:
25+
fh.write(jsonpath_rw.version.git_version())
26+
27+
# This requires either jsonpath_rw/VERSION or to be in a git clone (as does the package in general)
28+
# This is identical to code in jsonpath_rw.version. It would be nice to re-use but importing requires all deps
29+
def stored_version():
30+
if os.path.exists(VERSION_PATH):
31+
with io.open(VERSION_PATH, encoding='ascii') as fh:
32+
return fh.read().strip()
33+
else:
34+
return None
35+
36+
def git_version():
37+
described_version_bytes = subprocess.Popen(['git', 'describe'], stdout=subprocess.PIPE).communicate()[0].strip()
38+
return described_version_bytes.decode('ascii')
39+
40+
version = stored_version() or git_version()
41+
2042
setuptools.setup(
2143
name='jsonpath-rw',
22-
version='1.2.0',
44+
version=version,
2345
description='A robust and significantly extended implementation of JSONPath for Python, with a clear AST for metaprogramming.',
2446
author='Kenneth Knowles',
2547
author_email='kenn.knowles@gmail.com',
2648
url='https://github.com/kennknowles/python-jsonpath-rw',
2749
license='Apache 2.0',
2850
long_description=long_description,
2951
packages = ['jsonpath_rw'],
52+
package_data = {'': ['VERSION']},
3053
test_suite = 'tests',
3154
install_requires = [ 'ply', 'decorator', 'six' ],
3255
classifiers = [

0 commit comments

Comments
 (0)
0