Updated versioning code

This commit is contained in:
Karl Hobley 2015-02-09 13:25:11 +00:00
parent c19a19699a
commit 7f39cc4eab

View file

@ -1,31 +1,25 @@
# https://raw.githubusercontent.com/django/django/stable/1.6.x/django/utils/version.py
# https://raw.githubusercontent.com/django/django/master/django/utils/version.py
# This was copied into Wagtail so the get_git_changeset will use a file located in Wagtail instead of Django
# Replace this with version that uses lru cache when we drop Django 1.6 support
from __future__ import unicode_literals
import datetime
import os
import subprocess
from django.utils.lru_cache import lru_cache
def get_version(version=None):
"Returns a PEP 386-compliant version number from VERSION."
if version is None:
from django import VERSION as version
else:
assert len(version) == 5
assert version[3] in ('alpha', 'beta', 'rc', 'final')
version = get_complete_version(version)
# Now build the two parts of the version number:
# main = X.Y[.Z]
# major = X.Y[.Z]
# sub = .devN - for pre-alpha releases
# | {a|b|c}N - for alpha, beta and rc releases
parts = 2 if version[2] == 0 else 3
main = '.'.join(str(x) for x in version[:parts])
major = get_major_version(version)
sub = ''
if version[3] == 'alpha' and version[4] == 0:
@ -37,9 +31,39 @@ def get_version(version=None):
mapping = {'alpha': 'a', 'beta': 'b', 'rc': 'c'}
sub = mapping[version[3]] + str(version[4])
return str(main + sub)
return str(major + sub)
def get_major_version(version=None):
"Returns major version from VERSION."
version = get_complete_version(version)
parts = 2 if version[2] == 0 else 3
major = '.'.join(str(x) for x in version[:parts])
return major
def get_complete_version(version=None):
"""Returns a tuple of the wagtail version. If version argument is non-empty,
then checks for correctness of the tuple provided.
"""
if version is None:
from wagtail import VERSION as version
else:
assert len(version) == 5
assert version[3] in ('alpha', 'beta', 'rc', 'final')
return version
def get_docs_version(version=None):
version = get_complete_version(version)
if version[3] != 'final':
return 'dev'
else:
return '%d.%d' % version[:2]
@lru_cache()
def get_git_changeset():
"""Returns a numeric identifier of the latest git changeset.
@ -57,3 +81,4 @@ def get_git_changeset():
except ValueError:
return None
return timestamp.strftime('%Y%m%d%H%M%S')