Special case get_version() to include git revision id if we're running from a git repo
This commit is contained in:
parent
e1668efff6
commit
11edbc160b
@ -1,9 +1,31 @@
|
|||||||
|
import os
|
||||||
import sys
|
import sys
|
||||||
if not (2, 6) <= sys.version_info < (3,):
|
if not (2, 6) <= sys.version_info < (3,):
|
||||||
sys.exit(u'Mopidy requires Python >= 2.6, < 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():
|
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):
|
class MopidyException(Exception):
|
||||||
def __init__(self, message, *args, **kwargs):
|
def __init__(self, message, *args, **kwargs):
|
||||||
|
|||||||
@ -1,11 +1,11 @@
|
|||||||
from distutils.version import StrictVersion as SV
|
from distutils.version import StrictVersion as SV
|
||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
from mopidy import get_version
|
from mopidy import get_plain_version
|
||||||
|
|
||||||
class VersionTest(unittest.TestCase):
|
class VersionTest(unittest.TestCase):
|
||||||
def test_current_version_is_parsable_as_a_strict_version_number(self):
|
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):
|
def test_versions_can_be_strictly_ordered(self):
|
||||||
self.assert_(SV('0.1.0a0') < SV('0.1.0a1'))
|
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.1.0') < SV('1.0.0'))
|
||||||
self.assert_(SV('0.2.0') < SV('0.3.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.0') < SV('0.3.1'))
|
||||||
self.assert_(SV('0.3.1') < SV(get_version()))
|
self.assert_(SV('0.3.1') < SV(get_plain_version()))
|
||||||
self.assert_(SV(get_version()) < SV('0.4.1'))
|
self.assert_(SV(get_plain_version()) < SV('0.4.1'))
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user