summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorErik M. Bray <embray@stsci.edu>2013-03-06 00:08:49 +0000
committerErik M. Bray <embray@stsci.edu>2013-03-06 00:08:49 +0000
commit890d9685cdba0cfc8ca2b86c8981b272f3bc16aa (patch)
treea34c3d6761c3cdf3803a69f5f73be10ad4f7823f
parentb83cdb89705d746a4a0fb9f8b85522b3442301e6 (diff)
downloadpbr-890d9685cdba0cfc8ca2b86c8981b272f3bc16aa.tar.gz
Fixes #20. Make sure the manifest_maker monkeypatch only occurs once and that it gets all its required locals encapsulated. This is why I hate any sort of monkey-patching, but it appears to be the only way to get this feature working.
git-svn-id: https://svn.stsci.edu/svn/ssb/stsci_python/d2to1/trunk@23570 fe389314-cf27-0410-b35b-8c050e845b92
-rw-r--r--pbr/d2to1/util.py12
1 files changed, 7 insertions, 5 deletions
diff --git a/pbr/d2to1/util.py b/pbr/d2to1/util.py
index 32dea29..5e45de1 100644
--- a/pbr/d2to1/util.py
+++ b/pbr/d2to1/util.py
@@ -209,9 +209,9 @@ def cfg_to_args(path='setup.cfg'):
# Unfortunately the only really sensible way to do this is to
# monkey-patch the manifest_maker class
@monkeypatch_method(manifest_maker)
- def add_defaults(self, extra_files=extra_files):
- log.info('[d2to1] running patched manifest_maker command with '
- 'extra_files support')
+ def add_defaults(self, extra_files=extra_files, log=log):
+ log.info('[d2to1] running patched manifest_maker command '
+ 'with extra_files support')
add_defaults._orig(self)
self.filelist.extend(extra_files)
@@ -535,8 +535,10 @@ def monkeypatch_method(cls):
"""
def wrapper(func):
- setattr(func, '_orig', getattr(cls, func.__name__))
- setattr(cls, func.__name__, func)
+ orig = getattr(cls, func.__name__, None)
+ if orig and not hasattr(orig, '_orig'): # Already patched
+ setattr(func, '_orig', orig)
+ setattr(cls, func.__name__, func)
return func
return wrapper