diff options
author | Doug Hellmann <doug.hellmann@dreamhost.com> | 2013-09-25 16:55:49 -0400 |
---|---|---|
committer | Doug Hellmann <doug.hellmann@dreamhost.com> | 2013-10-09 17:49:18 -0400 |
commit | ae25b565d37c831d4caea8347a6ba6279683fbca (patch) | |
tree | fa1f7025527069c70fcc17330085c1c4489f2c43 | |
parent | 3391ca5c1a9a1db4e96e0043b953d0b5d463d7fd (diff) | |
download | pbr-ae25b565d37c831d4caea8347a6ba6279683fbca.tar.gz |
Do not pass unicode where byte strings are wanted
Some versions of the tarfile module break when unicode data is
passed as metadata (like the version). See
http://bugs.python.org/issue11638 for details.
This change ensures that version number is always a byte strings
under python 2, where the problem exists.
Change-Id: Ic266cd7cce0394d28794ee61afe269f1296be2a2
-rw-r--r-- | pbr/packaging.py | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/pbr/packaging.py b/pbr/packaging.py index 8233dec..157a6f4 100644 --- a/pbr/packaging.py +++ b/pbr/packaging.py @@ -761,7 +761,13 @@ def _get_version_from_git(pre_version): else: return _run_git_command( ['describe', '--always'], git_dir).replace('-', '.') - return None + # If we don't know the version, return an empty string so at least + # the downstream users of the value always have the same type of + # object to work with. + try: + return unicode() + except NameError: + return '' def _get_version_from_pkg_info(package_name): @@ -801,6 +807,12 @@ def get_version(package_name, pre_version=None): if version: return version version = _get_version_from_git(pre_version) + # Handle http://bugs.python.org/issue11638 + # version will either be an empty unicode string or a valid + # unicode version string, but either way it's unicode and needs to + # be encoded. + if sys.version_info[0] == 2: + version = version.encode('utf-8') if version: return version raise Exception("Versioning for this project requires either an sdist" |