From 375b430ffffc463e683473a26886baa0e2a71d92 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Nov=C3=BD?= Date: Sun, 13 Dec 2015 14:37:53 +0100 Subject: [PATCH] Automagic versioning Use pbr for versioning when developing but use PKG-INFO file in production. This lets you build swauth package that don't require pbr to be installed at all. You would need pbr on machine building package but not on machines that install the package. Stolen from Swift: https://github.com/openstack/swift/blob/master/swift/__init__.py Change-Id: Ic3a8fe1d9fe8d7d1f84b63142049970295fbcaab --- doc/source/conf.py | 5 +++-- swauth/__init__.py | 19 +++++++++++++++---- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/doc/source/conf.py b/doc/source/conf.py index ab0645a..3c31ec1 100644 --- a/doc/source/conf.py +++ b/doc/source/conf.py @@ -65,9 +65,10 @@ copyright = u'2010-2011, OpenStack, LLC' # built documents. # # The short X.Y version. -version = '.'.join(str(v) for v in swauth.version_info[:2]) +from swauth import __version__ +version = __version__.rsplit('.', 1)[0] # The full version, including alpha/beta/rc tags. -release = swauth.version +release = swauth.__version__ # The language for content autogenerated by Sphinx. Refer to documentation # for a list of supported languages. diff --git a/swauth/__init__.py b/swauth/__init__.py index 67f86b6..47f805b 100644 --- a/swauth/__init__.py +++ b/swauth/__init__.py @@ -14,10 +14,21 @@ # limitations under the License. import gettext +import pkg_resources -#: Version information (major, minor, revision[, 'dev']). -version_info = (1, 0, 9, 'dev') -#: Version string 'major.minor.revision'. -version = __version__ = ".".join(map(str, version_info)) +try: + # First, try to get our version out of PKG-INFO. If we're installed, + # this'll let us find our version without pulling in pbr. After all, if + # we're installed on a system, we're not in a Git-managed source tree, so + # pbr doesn't really buy us anything. + __version__ = pkg_resources.get_provider( + pkg_resources.Requirement.parse('swauth')).version +except pkg_resources.DistributionNotFound: + # No PKG-INFO? We're probably running from a checkout, then. Let pbr do + # its thing to figure out a version number. + import pbr.version + __version__ = pbr.version.VersionInfo( + 'swauth').version_string() + gettext.install('swauth')