Commit 40f0ecc5 authored by Aymeric Augustin's avatar Aymeric Augustin
Browse files

Implemented PEP386-compatible version numbers. Thanks Jannis for the guidance.


git-svn-id: http://code.djangoproject.com/svn/django/trunk@17357 bcc190cf-cafb-0310-a4f2-bffc1f526a37
parent aa4e1522
Loading
Loading
Loading
Loading
+27 −27
Original line number Diff line number Diff line
VERSION = (1, 4, 0, 'alpha', 1)

def get_version():
    version = '%s.%s' % (VERSION[0], VERSION[1])
    if VERSION[2]:
        version = '%s.%s' % (version, VERSION[2])
    if VERSION[3:] == ('alpha', 0):
        version = '%s pre-alpha' % version
    else:
        if VERSION[3] != 'final':
            version = '%s %s %s' % (version, VERSION[3], VERSION[4])
def get_version(version=None):
    """Derives a PEP386-compliant version number from VERSION."""
    if version is None:
        version = VERSION
    assert len(version) == 5
    assert version[3] in ('alpha', 'beta', 'rc', 'final')

    # Now build the two parts of the version number:
    # main = 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])

    sub = ''
    if version[3] == 'alpha' and version[4] == 0:
        # At the toplevel, this would cause an import loop.
        from django.utils.version import get_svn_revision
    svn_rev = get_svn_revision()
    if svn_rev != u'SVN-unknown':
        version = "%s %s" % (version, svn_rev)
    return version
        svn_revision = get_svn_revision()[4:]
        if svn_revision != 'unknown':
            sub = '.dev%s' % svn_revision

    elif version[3] != 'final':
        mapping = {'alpha': 'a', 'beta': 'b', 'rc': 'c'}
        sub = mapping[version[3]] + str(version[4])

def get_distutils_version():
    # Distutils expects a version number formatted as major.minor[.patch][sub]
    parts = 5
    if VERSION[3] == 'final':
        parts = 3
        if VERSION[2] == 0:
            parts = 2
    version = VERSION[:parts]
    version = [str(x)[0] for x in version]      # ['1', '4', '0', 'a', '1']
    if parts > 2:
        version[2:] = [''.join(version[2:])]    # ['1', '4', '0a1']
    version = '.'.join(version)                 # '1.4.0a1'
    return version
    return main + sub
+1 −2
Original line number Diff line number Diff line
@@ -4,12 +4,11 @@ from optparse import OptionParser, NO_DEFAULT
import imp
import warnings

import django
from django.core.management.base import BaseCommand, CommandError, handle_default_options
from django.utils.importlib import import_module

# For backwards compatibility: get_version() used to be in this module.
get_version = django.get_version
from django import get_version

# A cache of loaded commands, so that call_command
# doesn't have to reload every time it's called.
+1 −1
Original line number Diff line number Diff line
@@ -66,7 +66,7 @@ if len(sys.argv) > 1 and sys.argv[1] == 'bdist_wininst':
        file_info[0] = '\\PURELIB\\%s' % file_info[0]

# Dynamically calculate the version based on django.VERSION.
version = __import__('django').get_distutils_version()
version = __import__('django').get_version()

setup(
    name = "Django",
+1 −2
Original line number Diff line number Diff line
@@ -1177,8 +1177,7 @@ class CommandTypes(AdminScriptTestCase):
        args = ['--version']
        out, err = self.run_manage(args)
        self.assertNoOutput(err)
        # Only check the first part of the version number
        self.assertOutput(out, get_version().split('-')[0])
        self.assertOutput(out, get_version())

    def test_help(self):
        "--help is handled as a special case"
+0 −0

Empty file added.

Loading