diff --git a/.gitignore b/.gitignore index e0eeb59417..4a39e651d6 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,4 @@ run_tests.log tests/ .quantum-venv/ .venv/ +quantum/vcsversion.py diff --git a/quantum/version.py b/quantum/version.py new file mode 100644 index 0000000000..a108bb88fd --- /dev/null +++ b/quantum/version.py @@ -0,0 +1,46 @@ +# vim: tabstop=4 shiftwidth=4 softtabstop=4 + +# Copyright 2011 OpenStack LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +try: + from quantum.vcsversion import version_info +except ImportError: + version_info = {'branch_nick': u'LOCALBRANCH', + 'revision_id': 'LOCALREVISION', + 'revno': 0} + +QUANTUM_VERSION = ['2012', '1', None] +YEAR, COUNT, REVSISION = QUANTUM_VERSION + +FINAL = False # This becomes true at Release Candidate time + + +def canonical_version_string(): + return '.'.join(filter(None, QUANTUM_VERSION)) + + +def version_string(): + if FINAL: + return canonical_version_string() + else: + return '%s-dev' % (canonical_version_string(),) + + +def vcs_version_string(): + return "%s:%s" % (version_info['branch_nick'], version_info['revision_id']) + + +def version_string_with_vcs(): + return "%s-%s" % (canonical_version_string(), vcs_version_string()) diff --git a/run_tests.sh b/run_tests.sh index 0a0a593f5f..e4adfde941 100755 --- a/run_tests.sh +++ b/run_tests.sh @@ -96,7 +96,7 @@ function run_pep8 { PEP8_EXCLUDE="vcsversion.py,*.pyc" PEP8_OPTIONS="--exclude=$PEP8_EXCLUDE --repeat --show-source" - PEP8_INCLUDE="bin/* quantum run_tests.py setup*.py version.py" + PEP8_INCLUDE="bin/* quantum run_tests.py setup*.py" ${wrapper} pep8 $PEP8_OPTIONS $PEP8_INCLUDE } diff --git a/setup.py b/setup.py index 242f832080..89c3a06195 100644 --- a/setup.py +++ b/setup.py @@ -6,11 +6,37 @@ except ImportError: from setuptools import setup, find_packages import sys -import version +import os +import subprocess +from quantum import version + + +def run_git_command(cmd): + output = subprocess.Popen(["/bin/sh", "-c", cmd], + stdout=subprocess.PIPE) + return output.communicate()[0].strip() + + +if os.path.isdir('.git'): + branch_nick_cmd = 'git branch | grep -Ei "\* (.*)" | cut -f2 -d" "' + branch_nick = run_git_command(branch_nick_cmd) + revid_cmd = "git --no-pager log --max-count=1 | cut -f2 -d' ' | head -1" + revid = run_git_command(revid_cmd) + revno_cmd = "git --no-pager log --oneline | wc -l" + revno = run_git_command(revno_cmd) + with open("quantum/vcsversion.py", 'w') as version_file: + version_file.write(""" +# This file is automatically generated by setup.py, So don't edit it. :) +version_info = { + 'branch_nick': '%s', + 'revision_id': '%s', + 'revno': %s +} +""" % (branch_nick, revid, revno)) Name = 'quantum' Url = "https://launchpad.net/quantum" -Version = version.get_git_version() +Version = version.canonical_version_string() License = 'Apache License 2.0' Author = 'Netstack' AuthorEmail = 'netstack@lists.launchpad.net' diff --git a/version.py b/version.py deleted file mode 100644 index f78426bde6..0000000000 --- a/version.py +++ /dev/null @@ -1,105 +0,0 @@ -# -*- coding: utf-8 -*- -# Author: Douglas Creager -# This file is placed into the public domain. - -# Calculates the current version number. If possible, this is the -# output of “git describe”, modified to conform to the versioning -# scheme that setuptools uses. If “git describe” returns an error -# (most likely because we're in an unpacked copy of a release tarball, -# rather than in a git working copy), then we fall back on reading the -# contents of the RELEASE-VERSION file. -# -# To use this script, simply import it your setup.py file, and use the -# results of get_git_version() as your package version: -# -# from version import * -# -# setup( -# version=get_git_version(), -# . -# . -# . -# ) -# -# This will automatically update the RELEASE-VERSION file, if -# necessary. Note that the RELEASE-VERSION file should *not* be -# checked into git; please add it to your top-level .gitignore file. -# -# You'll probably want to distribute the RELEASE-VERSION file in your -# sdist tarballs; to do this, just create a MANIFEST.in file that -# contains the following line: -# -# include RELEASE-VERSION - -__all__ = ("get_git_version") - -from subprocess import Popen, PIPE - -FALLBACK_VERSION = "2012.1dev" - - -def call_git_describe(abbrev=4): - try: - p = Popen(['git', 'describe', '--abbrev=%d' % abbrev], - stdout=PIPE, stderr=PIPE) - p.stderr.close() - line = p.stdout.readlines()[0] - return line.strip() - except: - return FALLBACK_VERSION - - -def read_release_version(): - try: - f = open("RELEASE-VERSION", "r") - - try: - version = f.readlines()[0] - return version.strip() - - finally: - f.close() - - except: - return None - - -def write_release_version(version): - f = open("RELEASE-VERSION", "w") - f.write("%s\n" % version) - f.close() - - -def get_git_version(abbrev=4): - # Read in the version that's currently in RELEASE-VERSION. - - release_version = read_release_version() - - # First try to get the current version using “git describe”. - - version = call_git_describe(abbrev) - - # If that doesn't work, fall back on the value that's in - # RELEASE-VERSION. - - if version is None: - version = release_version - - # If we still don't have anything, that's an error. - - if version is None: - raise ValueError("Cannot find the version number!") - - # If the current version is different from what's in the - # RELEASE-VERSION file, update the file to be current. - - if version != release_version: - write_release_version(version) - - # Finally, return the current version. - - return version - - -if __name__ == "__main__": - print get_git_version()