Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Use pkg_resources to find Sonata's version

This removes some magic dance between setup.py, sonata.version and sonata.genversion
at the expense of having to run "setup.py egg_info" to know the version of Sonata.
  • Loading branch information...
commit e44479ee19e1c9f8f32159121456f5f4dcb8d404 1 parent e1debcb
@multani authored
View
10 run-sonata
@@ -1,5 +1,15 @@
#!/usr/bin/env python
+import os
+import sys
+
+if not os.path.exists("Sonata.egg-info"):
+ print "Sonata.egg-info directory doesn't exist. Attempting to generate it."
+ argv = sys.argv
+ sys.argv = ["setup.py", "egg_info"]
+ import setup
+ sys.argv = argv
+
import sonata.launcher
if __name__ == '__main__':
View
27 setup.py
@@ -3,8 +3,9 @@
from distutils.dep_util import newer
import glob
import os
+from subprocess import check_output
+
from setuptools import setup, Extension
-from sonata.version import version
def capture(cmd):
@@ -36,13 +37,18 @@ def generate_translation_files():
return lang_files
-versionfile = open("sonata/genversion.py","wt")
-versionfile.write("""
-# generated by setup.py
-VERSION = 'v%s'
-""" % version)
-versionfile.close()
+# Compute the version using Git.
+# If the HEAD also points to a tag (say "v42.3.2"), it should returns this tag,
+# otherwise the last tag+commit information (like "v42.3.2-188-gc0d1")
+def compute_version():
+ version = check_output(["git", "describe", "--tags", "--abbrev=4", "HEAD"],
+ cwd=os.path.dirname(os.path.abspath(__file__)))
+
+ # Remove newlines and the "v" in front of the version, to please setuptools
+ version = version.strip().lstrip("v")
+
+ return version
data_files = [
@@ -58,7 +64,7 @@ def generate_translation_files():
setup(
name='Sonata',
- version=version,
+ version=compute_version(),
description='GTK+ client for the Music Player Daemon (MPD).',
author='Scott Horowitz',
author_email='stonecrest@gmail.com',
@@ -98,8 +104,3 @@ def generate_translation_files():
'test': tests_require,
},
)
-try:
- os.remove("sonata/genversion.py")
- os.remove("sonata/genversion.pyc")
-except:
- pass
View
6 sonata/cli.py
@@ -4,7 +4,7 @@
import logging
from optparse import OptionParser
-from version import version
+from sonata import misc
# the mpd commands need a connection to server and exit without gui
mpd_cmds = ["play", "pause", "stop", "next", "prev", "pp", "info",
@@ -41,7 +41,7 @@ def parse(self, argv):
" info %s" % _("display current song info"),
" status %s" % _("display MPD status"),
))
- _version = "%prog " + version
+ _version = "%prog " + misc.sonata_version()
parser = OptionParser(usage=_usage, version=_version)
parser.add_option("-p", "--popup", dest="popup",
@@ -130,7 +130,7 @@ def apply_profile_arg(self, config):
class CliMain(object):
def __init__(self, args):
- global os, mpd, config, library, mpdh, misc
+ global os, mpd, config, library, mpdh
import os
import mpd
import config
View
12 sonata/launcher.py
@@ -54,18 +54,6 @@ def run():
logger.critical("Perhaps Sonata is improperly installed?")
sys.exit(1)
- try:
- from sonata.version import version
- except ImportError:
- logger.critical("Python failed to find the sonata modules.")
- logger.critical("An old or incomplete installation was "
- "found in the following directory: %s",
- os.path.dirname(sonata.__file__))
- logger.critical("Perhaps you want to delete it?")
- sys.exit(1)
-
- # XXX check that version.VERSION is what this script was installed for
-
## Apply global fixes:
# the following line is to fix python-zsi 2.0 and thus lyrics in ubuntu:
View
6 sonata/main.py
@@ -79,8 +79,6 @@
import rhapsodycovers
import dbus_plugin as dbus
-from version import version
-
class Base(object):
@@ -1015,7 +1013,7 @@ def gnome_session_management(self):
# Code thanks to quodlibet:
# XXX gnome.init sets process name, locale...
- gnome.init("sonata", version)
+ gnome.init("sonata", misc.sonata_version())
misc.setlocale()
@@ -3511,7 +3509,7 @@ def tags_mpd_update(self, tag_paths):
def on_about(self, _action):
about_dialog = about.About(self.window,
self.config,
- version,
+ misc.sonata_version(),
__license__,
self.path_to_icon('sonata_large.png'))
View
21 sonata/misc.py
@@ -6,6 +6,8 @@
import logging
import sys
+import pkg_resources
+
logger = logging.getLogger(__name__)
@@ -262,3 +264,22 @@ def setlocale():
except:
logger.exception("Failed to set locale")
sys.exit(1)
+
+def sonata_version():
+ try:
+ working_set = pkg_resources.WorkingSet()
+ sonata_distribution = working_set.by_key["sonata"]
+ except:
+ # Don't fail just because we can't find the version, it's not *that*
+ # important. Though, we log the error, hoping to fix it.
+ logger.warning(
+ "Unable to find Sonata's version. Is there a Sonata.egg-info "
+ "directory, did you run 'setup.py egg_info'?")
+ logger.warning("Using '(unknown version)' instead.")
+ logger.exception("The error was:")
+ version = "(unknown version)"
+ else:
+ version = sonata_distribution.version
+
+ return version
+
View
33 sonata/version.py
@@ -1,33 +0,0 @@
-import os
-from subprocess import Popen, PIPE
-
-try:
- import genversion
- build_ver = genversion.VERSION
-except ImportError:
- build_ver = None
-
-# Should be the most recent release
-default_version = "v1.6.2.1"
-
-def _version():
- '''Get the version number of the sources
-
- First check the build generated file, fallback to git describe if this is
- not a build, finally fallback to the default most recent release.
- '''
- if build_ver:
- version = build_ver
- else:
- try:
- dir = os.path.dirname(__file__)
- version = Popen(["git", "describe", "--abbrev=4", "HEAD"],
- cwd=dir, stdout=PIPE,
- stderr=PIPE).communicate()[0]
- if not version:
- raise OSError
- except OSError:
- version = default_version
- return version.strip()[1:]
-
-version = _version()
Please sign in to comment.
Something went wrong with that request. Please try again.