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>
This commit is contained in:
parent
c45687fb9b
commit
a260dc3f29
26
pbr/core.py
26
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()
|
||||
|
|
Loading…
Reference in New Issue