From 0717133197d8929a03ec267d4e3c5b1696f02fb3 Mon Sep 17 00:00:00 2001 From: John Dickinson Date: Tue, 29 Oct 2013 12:29:49 -0700 Subject: [PATCH] Make pbr a build-time only dependency This lets you build swift packages that don't require pbr to be installed at all. You would need pbr on the machine running rpmbuild / debuild, but not on the machines that install the packages. Unfortunately, this does not make swift able to be installed via pip 0.3.1 on Lucid; you'll need to uninstall the system python-pip package and install a new pip some other way. Given that pip < 1.3 doesn't perform SSL certificate validation for pypi (trivial MITM attack, anyone?), you'd probably want to get a new pip anyway. Change-Id: Ia50a229c5ae4dd2158beeaa953619b5e8f987c55 --- requirements.txt | 1 - swift/__init__.py | 21 +++++++++++++++------ 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/requirements.txt b/requirements.txt index dae7525cdb..113986693f 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,3 @@ -pbr>=0.5.21,<1.0 dnspython>=1.9.4 eventlet>=0.9.15 greenlet>=0.3.1 diff --git a/swift/__init__.py b/swift/__init__.py index 7e8fb7b8dc..9d0e8896f7 100644 --- a/swift/__init__.py +++ b/swift/__init__.py @@ -16,13 +16,22 @@ import os import gettext -import pbr.version - - -_version_info = pbr.version.VersionInfo('swift') -__version__ = _version_info.release_string() -__canonical_version__ = _version_info.version_string() +import pkg_resources +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__ = __canonical_version__ = pkg_resources.get_provider( + pkg_resources.Requirement.parse('swift')).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_info = pbr.version.VersionInfo('swift') + __version__ = _version_info.release_string() + __canonical_version__ = _version_info.version_string() _localedir = os.environ.get('SWIFT_LOCALEDIR') _t = gettext.translation('swift', localedir=_localedir, fallback=True)