From 11edbc160b0eb7d2ca43b22cfaab9f9eb3b810cd Mon Sep 17 00:00:00 2001 From: Stein Magnus Jodal Date: Tue, 25 Jan 2011 22:03:28 +0100 Subject: [PATCH] Special case get_version() to include git revision id if we're running from a git repo --- mopidy/__init__.py | 24 +++++++++++++++++++++++- tests/version_test.py | 8 ++++---- 2 files changed, 27 insertions(+), 5 deletions(-) diff --git a/mopidy/__init__.py b/mopidy/__init__.py index fc56efac..4bb4609b 100644 --- a/mopidy/__init__.py +++ b/mopidy/__init__.py @@ -1,9 +1,31 @@ +import os import sys if not (2, 6) <= sys.version_info < (3,): sys.exit(u'Mopidy requires Python >= 2.6, < 3') +VERSION = (0, 4, 0) + +def is_in_git_repo(): + git_dir = os.path.abspath(os.path.join( + os.path.dirname(__file__), '../.git')) + return os.path.exists(git_dir) + +def get_git_version(): + if not is_in_git_repo(): + return None + git_version = os.popen('git describe').read().strip() + if git_version.startswith('v'): + git_version = git_version[1:] + return git_version + +def get_plain_version(): + return '.'.join(map(str, VERSION)) + def get_version(): - return u'0.4.0' + if is_in_git_repo(): + return get_git_version() + else: + return get_plain_version() class MopidyException(Exception): def __init__(self, message, *args, **kwargs): diff --git a/tests/version_test.py b/tests/version_test.py index a035f520..f1f86b59 100644 --- a/tests/version_test.py +++ b/tests/version_test.py @@ -1,11 +1,11 @@ from distutils.version import StrictVersion as SV import unittest -from mopidy import get_version +from mopidy import get_plain_version class VersionTest(unittest.TestCase): def test_current_version_is_parsable_as_a_strict_version_number(self): - SV(get_version()) + SV(get_plain_version()) def test_versions_can_be_strictly_ordered(self): self.assert_(SV('0.1.0a0') < SV('0.1.0a1')) @@ -16,5 +16,5 @@ class VersionTest(unittest.TestCase): self.assert_(SV('0.1.0') < SV('1.0.0')) self.assert_(SV('0.2.0') < SV('0.3.0')) self.assert_(SV('0.3.0') < SV('0.3.1')) - self.assert_(SV('0.3.1') < SV(get_version())) - self.assert_(SV(get_version()) < SV('0.4.1')) + self.assert_(SV('0.3.1') < SV(get_plain_version())) + self.assert_(SV(get_plain_version()) < SV('0.4.1'))