Skip to content

Commit e445f56

Browse files
author
Clark Perkins
committed
Updated versioning scheme
1 parent c89b2ac commit e445f56

File tree

1 file changed

+69
-2
lines changed

1 file changed

+69
-2
lines changed

stackdio/client/version.py

Lines changed: 69 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,86 @@
1515
# limitations under the License.
1616
#
1717

18-
from functools import wraps
18+
import datetime
1919
import operator
20+
import os
2021
import re
22+
import subprocess
2123
import warnings
24+
from functools import wraps
2225

2326
# for setup.py
2427
try:
2528
from .exceptions import IncompatibleVersionException, InvalidVersionStringException
2629
except Exception:
2730
pass
2831

32+
VERSION = (0, 7, 0, 'dev', 0)
33+
34+
35+
def get_version(version):
36+
"""
37+
Returns a PEP 440-compliant version number from VERSION.
38+
39+
Created by modifying django.utils.version.get_version
40+
"""
41+
42+
# Now build the two parts of the version number:
43+
# major = X.Y[.Z]
44+
# sub = .devN - for development releases
45+
# | {a|b|rc}N - for alpha, beta and rc releases
46+
# | .postN - for post-release releases
47+
48+
assert len(version) == 5
49+
50+
version_parts = version[:3]
51+
52+
# Build the first part of the version
53+
major = '.'.join(str(x) for x in version_parts)
54+
55+
# Just return it if this is a final release version
56+
if version[3] == 'final':
57+
return major
58+
59+
# Add the rest
60+
sub = ''.join(str(x) for x in version[3:5])
61+
62+
if version[3] == 'dev':
63+
# Override the sub part. Add in a timestamp
64+
timestamp = get_git_changeset()
65+
sub = 'dev%s' % (timestamp if timestamp else '')
66+
return '%s.%s' % (major, sub)
67+
if version[3] == 'post':
68+
# We need a dot for post
69+
return '%s.%s' % (major, sub)
70+
elif version[3] in ('a', 'b', 'rc'):
71+
# No dot for these
72+
return '%s%s' % (major, sub)
73+
else:
74+
raise ValueError('Invalid version: %s' % str(version))
75+
76+
77+
# Borrowed directly from django
78+
def get_git_changeset():
79+
"""Returns a numeric identifier of the latest git changeset.
80+
81+
The result is the UTC timestamp of the changeset in YYYYMMDDHHMMSS format.
82+
This value isn't guaranteed to be unique, but collisions are very unlikely,
83+
so it's sufficient for generating the development version numbers.
84+
"""
85+
repo_dir = os.path.dirname(os.path.abspath(__file__))
86+
git_log = subprocess.Popen('git log --pretty=format:%ct --quiet -1 HEAD',
87+
stdout=subprocess.PIPE, stderr=subprocess.PIPE,
88+
shell=True, cwd=repo_dir, universal_newlines=True)
89+
timestamp = git_log.communicate()[0]
90+
try:
91+
timestamp = datetime.datetime.utcfromtimestamp(int(timestamp))
92+
return timestamp.strftime('%Y%m%d%H%M%S')
93+
except ValueError:
94+
return None
95+
2996

30-
__version__ = '0.7.0.dev'
97+
__version__ = get_version(VERSION)
3198

3299

33100
def _unsupported_function(func, current_version, accepted_versions):

0 commit comments

Comments
 (0)