diff options
author | Jason R. Coombs <jaraco@jaraco.com> | 2016-09-09 12:39:43 -0400 |
---|---|---|
committer | Jason R. Coombs <jaraco@jaraco.com> | 2016-09-09 12:39:43 -0400 |
commit | b6f2fee975c570d2beadb9007e6302411f91ab4b (patch) | |
tree | 775b9637580605b4b6d7b647f035fb1d8d0bec41 /setuptools/monkey.py | |
parent | 5cc0ec25c0ef816de01b7416aa6bef172f91566d (diff) | |
download | external_python_setuptools-b6f2fee975c570d2beadb9007e6302411f91ab4b.tar.gz external_python_setuptools-b6f2fee975c570d2beadb9007e6302411f91ab4b.tar.bz2 external_python_setuptools-b6f2fee975c570d2beadb9007e6302411f91ab4b.zip |
Consolidate function patching and resolution of unpatched function, aligning pattern with the patched classes.
Diffstat (limited to 'setuptools/monkey.py')
-rw-r--r-- | setuptools/monkey.py | 33 |
1 files changed, 20 insertions, 13 deletions
diff --git a/setuptools/monkey.py b/setuptools/monkey.py index 33083831..24739d97 100644 --- a/setuptools/monkey.py +++ b/setuptools/monkey.py @@ -6,6 +6,8 @@ import sys import distutils.filelist import platform +from .py26compat import import_module + import setuptools @@ -103,7 +105,20 @@ def _patch_distribution_metadata_write_pkg_info(): ) -unpatched = dict() +def patch_func(replacement, original): + # first set the 'unpatched' attribute on the replacement to + # point to the original. + vars(replacement).setdefault('unpatched', original) + + # next resolve the module in which the original func resides + target_mod = import_module(original.__module__) + + # finally replace the function in the original module + setattr(target_mod, original.__name__, replacement) + + +def get_unpatched_func(candidate): + return getattr(candidate, 'unpatched') def patch_for_msvc_specialized_compiler(): @@ -129,29 +144,21 @@ def patch_for_msvc_specialized_compiler(): # Compilers only availables on Microsoft Windows return - if unpatched: - # Already patched - return - try: # Patch distutils.msvc9compiler - unpatched['msvc9_find_vcvarsall'] = msvc9compiler.find_vcvarsall - msvc9compiler.find_vcvarsall = msvc.msvc9_find_vcvarsall - unpatched['msvc9_query_vcvarsall'] = msvc9compiler.query_vcvarsall - msvc9compiler.query_vcvarsall = msvc.msvc9_query_vcvarsall + patch_func(msvc.msvc9_find_vcvarsall, msvc9compiler.find_vcvarsall) + patch_func(msvc.msvc9_query_vcvarsall, msvc9compiler.query_vcvarsall) except NameError: pass try: # Patch distutils._msvccompiler._get_vc_env - unpatched['msvc14_get_vc_env'] = msvc14compiler._get_vc_env - msvc14compiler._get_vc_env = msvc.msvc14_get_vc_env + patch_func(msvc.msvc14_get_vc_env, msvc14compiler._get_vc_env) except NameError: pass try: # Patch distutils._msvccompiler.gen_lib_options for Numpy - unpatched['msvc14_gen_lib_options'] = msvc14compiler.gen_lib_options - msvc14compiler.gen_lib_options = msvc.msvc14_gen_lib_options + patch_func(msvc.msvc14_gen_lib_options, msvc14compiler.gen_lib_options) except NameError: pass |