From a260dc3f294568529562fe548ff73cac5d57df1a Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Sun, 4 Sep 2016 21:28:23 -0400 Subject: [PATCH] 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 Signed-off-by: Monty Taylor Signed-off-by: Stephen Finucane --- pbr/core.py | 26 ++++++++------------------ 1 file changed, 8 insertions(+), 18 deletions(-) diff --git a/pbr/core.py b/pbr/core.py index 753387e9..3649e36e 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()