summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZuul <zuul@review.openstack.org>2017-10-20 06:10:00 +0000
committerGerrit Code Review <review@openstack.org>2017-10-20 06:10:00 +0000
commit3db298ad906dbd905c9b9ac4b6a877daa29130ee (patch)
tree05bda4f28d49465439dddbdd743c8ffacaaa2b98
parent721aa9547b26d8f70f240da2343359444281aee3 (diff)
parenta260dc3f294568529562fe548ff73cac5d57df1a (diff)
Merge "Discover Distribution through the class hierarchy"
-rw-r--r--pbr/core.py26
1 files changed, 8 insertions, 18 deletions
diff --git a/pbr/core.py b/pbr/core.py
index 753387e..3649e36 100644
--- a/pbr/core.py
+++ b/pbr/core.py
@@ -50,22 +50,9 @@ import os
50import sys 50import sys
51import warnings 51import warnings
52 52
53from setuptools import dist
54
55from pbr import util 53from pbr import util
56 54
57 55
58_saved_core_distribution = core.Distribution
59
60
61def _monkeypatch_distribution():
62 core.Distribution = dist._get_unpatched(core.Distribution)
63
64
65def _restore_distribution_monkeypatch():
66 core.Distribution = _saved_core_distribution
67
68
69if sys.version_info[0] == 3: 56if sys.version_info[0] == 3:
70 string_type = str 57 string_type = str
71 integer_types = (int,) 58 integer_types = (int,)
@@ -94,8 +81,7 @@ def pbr(dist, attr, value):
94 not work well with distributions that do use a `Distribution` subclass. 81 not work well with distributions that do use a `Distribution` subclass.
95 """ 82 """
96 83
97 try: 84 if True:
98 _monkeypatch_distribution()
99 if not value: 85 if not value:
100 return 86 return
101 if isinstance(value, string_type): 87 if isinstance(value, string_type):
@@ -135,11 +121,15 @@ def pbr(dist, attr, value):
135 warnings.warn(msg) 121 warnings.warn(msg)
136 122
137 # Re-finalize the underlying Distribution 123 # Re-finalize the underlying Distribution
138 core.Distribution.finalize_options(dist) 124 try:
125 super(dist.__class__, dist).finalize_options()
126 except TypeError:
127 # If dist is not declared as a new-style class (with object as
128 # a subclass) then super() will not work on it. This is the case
129 # for Python 2. In that case, fall back to doing this the ugly way
130 dist.__class__.__bases__[-1].finalize_options(dist)
139 131
140 # This bit comes out of distribute/setuptools 132 # This bit comes out of distribute/setuptools
141 if isinstance(dist.metadata.version, integer_types + (float,)): 133 if isinstance(dist.metadata.version, integer_types + (float,)):
142 # Some people apparently take "version number" too literally :) 134 # Some people apparently take "version number" too literally :)
143 dist.metadata.version = str(dist.metadata.version) 135 dist.metadata.version = str(dist.metadata.version)
144 finally:
145 _restore_distribution_monkeypatch()