summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJason R. Coombs <jaraco@jaraco.com>2016-09-04 21:28:23 -0400
committerStephen Finucane <sfinucan@redhat.com>2017-10-12 13:44:04 +0100
commita260dc3f294568529562fe548ff73cac5d57df1a (patch)
treecebcd629349b9e4c4f020714320e777a0424719f
parentc45687fb9b9fa541ceb47e5f9069c4628943ba2d (diff)
downloadpbr-a260dc3f294568529562fe548ff73cac5d57df1a.tar.gz
Discover Distribution through the class hierarchy
Discovering the underlying Distribution class through the class hierarchy saves unpatching and repatching. Based on commits ed579a5dbb2a1843874969a58bb2b6f1eca2e50d and 10b87cc1eb92f50906ff645d0221c74f03de94b9 from [1]. [1] https://github.com/jaraco/pbr/commits/issue-1620153-signoff Closes-Bug: #1620153. Change-Id: I7418cc3ab36823d029a93f86df9c8b25aa7b0c5f Signed-off-by: Jason R. Coombs <jaraco@jaraco.com> Signed-off-by: Monty Taylor <mordred@inaugust.com> Signed-off-by: Stephen Finucane <sfinucan@redhat.com>
-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
import sys
import warnings
-from setuptools import dist
-
from pbr import util
-_saved_core_distribution = core.Distribution
-
-
-def _monkeypatch_distribution():
- core.Distribution = dist._get_unpatched(core.Distribution)
-
-
-def _restore_distribution_monkeypatch():
- core.Distribution = _saved_core_distribution
-
-
if sys.version_info[0] == 3:
string_type = str
integer_types = (int,)
@@ -94,8 +81,7 @@ def pbr(dist, attr, value):
not work well with distributions that do use a `Distribution` subclass.
"""
- try:
- _monkeypatch_distribution()
+ if True:
if not value:
return
if isinstance(value, string_type):
@@ -135,11 +121,15 @@ def pbr(dist, attr, value):
warnings.warn(msg)
# Re-finalize the underlying Distribution
- core.Distribution.finalize_options(dist)
+ try:
+ super(dist.__class__, dist).finalize_options()
+ except TypeError:
+ # If dist is not declared as a new-style class (with object as
+ # a subclass) then super() will not work on it. This is the case
+ # for Python 2. In that case, fall back to doing this the ugly way
+ dist.__class__.__bases__[-1].finalize_options(dist)
# This bit comes out of distribute/setuptools
if isinstance(dist.metadata.version, integer_types + (float,)):
# Some people apparently take "version number" too literally :)
dist.metadata.version = str(dist.metadata.version)
- finally:
- _restore_distribution_monkeypatch()