Skip to content

Commit 9cfbebc

Browse files
author
Sean Cribbs
committed
Use git versions instead of manually bumping.
1 parent 3f79fa6 commit 9cfbebc

3 files changed

Lines changed: 57 additions & 1 deletion

File tree

MANIFEST.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ include THANKS
44
include README.rst
55
include LICENSE
66
include RELEASE_NOTES.md
7+
include version.py

setup.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import subprocess
55
import platform
66
from setuptools import setup, find_packages
7+
from version import get_version
78

89
def make_docs():
910
if not os.path.exists('docs'):
@@ -20,7 +21,7 @@ def make_docs():
2021

2122
setup(
2223
name='riak',
23-
version='2.0.0a',
24+
version=get_version(),
2425
packages = find_packages(),
2526
requires = requires,
2627
install_requires = install_requires,

version.py

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# This program is placed into the public domain.
2+
3+
"""
4+
Gets the current version number.
5+
If in a git repository, it is the current git tag.
6+
Otherwise it is the one contained in the PKG-INFO file.
7+
8+
To use this script, simply import it in your setup.py file
9+
and use the results of get_version() as your package version:
10+
11+
from version import *
12+
13+
setup(
14+
...
15+
version=get_version(),
16+
...
17+
)
18+
"""
19+
20+
__all__ = ('get_version')
21+
22+
from os.path import dirname, isdir, join
23+
import re
24+
from subprocess import CalledProcessError, check_output
25+
26+
version_re = re.compile('^Version: (.+)$', re.M)
27+
28+
29+
def get_version():
30+
d = dirname(__file__)
31+
32+
if isdir(join(d, '.git')):
33+
# Get the version using "git describe".
34+
cmd = 'git describe --tags --match [0-9]*'.split()
35+
try:
36+
version = check_output(cmd).decode().strip()
37+
except CalledProcessError:
38+
print('Unable to get version number from git tags')
39+
exit(1)
40+
41+
# PEP 386 compatibility
42+
if '-' in version:
43+
version = '.post'.join(version.split('-')[:2])
44+
45+
else:
46+
# Extract the version from the PKG-INFO file.
47+
with open(join(d, 'PKG-INFO')) as f:
48+
version = version_re.search(f.read()).group(1)
49+
50+
return version
51+
52+
53+
if __name__ == '__main__':
54+
print(get_version())

0 commit comments

Comments
 (0)