From ee0c7c1af564465d441af583a1f627a258f4c00d Mon Sep 17 00:00:00 2001 From: Stein Magnus Jodal Date: Sun, 4 Mar 2012 23:26:24 +0100 Subject: [PATCH] Add __version__ to mopidy module --- docs/changes.rst | 7 ++++--- docs/conf.py | 12 +++++++++--- mopidy/__init__.py | 11 ++++------- setup.py | 6 +++++- tests/version_test.py | 8 ++++---- 5 files changed, 26 insertions(+), 18 deletions(-) diff --git a/docs/changes.rst b/docs/changes.rst index 4e5f5cb4..a6b7e361 100644 --- a/docs/changes.rst +++ b/docs/changes.rst @@ -4,8 +4,8 @@ Changes This change log is used to track all major changes to Mopidy. -v0.8.0 (in development) -======================= +v0.8 (in development) +===================== **Important changes** @@ -13,7 +13,8 @@ v0.8.0 (in development) **Changes** -- Nothing so far +- Change from version tuple at :attr:`mopidy.VERSION` to :pep:`386` compliant + version string at :attr:`mopidy.__version__` to conform to :pep:`396`. v0.7.0 (2012-02-25) diff --git a/docs/conf.py b/docs/conf.py index f8b4ffc3..a33a8f2d 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -11,7 +11,9 @@ # All configuration values have a default; values that are commented out # serve to show the default. -import sys, os +import os +import re +import sys class Mock(object): def __init__(self, *args, **kwargs): @@ -49,6 +51,11 @@ MOCK_MODULES = [ for mod_name in MOCK_MODULES: sys.modules[mod_name] = Mock() +def get_version(): + init_py = open('../mopidy/__init__.py').read() + metadata = dict(re.findall("__([a-z]+)__ = '([^']+)'", init_py)) + return metadata['version'] + # If extensions (or modules to document with autodoc) are in another directory, # add these directories to sys.path here. If the directory is relative to the # documentation root, use os.path.abspath to make it absolute, like shown here. @@ -87,8 +94,7 @@ copyright = u'2010-2012, Stein Magnus Jodal and contributors' # built documents. # # The full version, including alpha/beta/rc tags. -import mopidy -release = mopidy.get_version() +release = get_version() # The short X.Y version. version = '.'.join(release.split('.')[:2]) diff --git a/mopidy/__init__.py b/mopidy/__init__.py index f4167e3f..b2d9afa0 100644 --- a/mopidy/__init__.py +++ b/mopidy/__init__.py @@ -1,14 +1,14 @@ -import platform import sys if not (2, 6) <= sys.version_info < (3,): sys.exit(u'Mopidy requires Python >= 2.6, < 3') -import glib import os - +import platform from subprocess import PIPE, Popen -VERSION = (0, 8, 0) +import glib + +__version__ = '0.8' DATA_PATH = os.path.join(str(glib.get_user_data_dir()), 'mopidy') CACHE_PATH = os.path.join(str(glib.get_user_cache_dir()), 'mopidy') @@ -30,9 +30,6 @@ def get_git_version(): version = version[1:] return version -def get_plain_version(): - return '.'.join(map(str, VERSION)) - def get_platform(): return platform.platform() diff --git a/setup.py b/setup.py index a8cf8ed1..ae6cc699 100644 --- a/setup.py +++ b/setup.py @@ -6,9 +6,13 @@ from distutils.core import setup from distutils.command.install_data import install_data from distutils.command.install import INSTALL_SCHEMES import os +import re import sys -from mopidy import get_version +def get_version(): + init_py = open('mopidy/__init__.py').read() + metadata = dict(re.findall("__([a-z]+)__ = '([^']+)'", init_py)) + return metadata['version'] class osx_install_data(install_data): # On MacOS, the platform-specific lib dir is diff --git a/tests/version_test.py b/tests/version_test.py index a7fd82a4..86060693 100644 --- a/tests/version_test.py +++ b/tests/version_test.py @@ -1,14 +1,14 @@ from distutils.version import StrictVersion as SV import platform -from mopidy import get_plain_version, get_platform, get_python +from mopidy import __version__, get_platform, get_python from tests import unittest class VersionTest(unittest.TestCase): def test_current_version_is_parsable_as_a_strict_version_number(self): - SV(get_plain_version()) + SV(__version__) def test_versions_can_be_strictly_ordered(self): self.assert_(SV('0.1.0a0') < SV('0.1.0a1')) @@ -25,8 +25,8 @@ class VersionTest(unittest.TestCase): self.assert_(SV('0.5.0') < SV('0.6.0')) self.assert_(SV('0.6.0') < SV('0.6.1')) self.assert_(SV('0.6.1') < SV('0.7.0')) - self.assert_(SV('0.7.0') < SV(get_plain_version())) - self.assert_(SV(get_plain_version()) < SV('0.8.1')) + self.assert_(SV('0.7.0') < SV(__version__)) + self.assert_(SV(__version__) < SV('0.8.1')) def test_get_platform_contains_platform(self): self.assert_(platform.platform() in get_platform())