|
15 | 15 | # limitations under the License. |
16 | 16 | # |
17 | 17 |
|
18 | | -from functools import wraps |
| 18 | +import datetime |
19 | 19 | import operator |
| 20 | +import os |
20 | 21 | import re |
| 22 | +import subprocess |
21 | 23 | import warnings |
| 24 | +from functools import wraps |
22 | 25 |
|
23 | 26 | # for setup.py |
24 | 27 | try: |
25 | 28 | from .exceptions import IncompatibleVersionException, InvalidVersionStringException |
26 | 29 | except Exception: |
27 | 30 | pass |
28 | 31 |
|
| 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 | + |
29 | 96 |
|
30 | | -__version__ = '0.7.0.dev' |
| 97 | +__version__ = get_version(VERSION) |
31 | 98 |
|
32 | 99 |
|
33 | 100 | def _unsupported_function(func, current_version, accepted_versions): |
|
0 commit comments