3

Q'ícã@s¤dZddlZddlZddlZddlZddlZddlmZddl	Z	ddl
mZddlZgZ
dd„Zdd„Zd	d
„Zdd„Zd
d„Zdd„Zdd„Zdd„Zdd„ZdS)z
Monkey patching of distutils.
éN)Ú
import_module)ÚsixcCs"tjƒdkr|f|jStj|ƒS)am
    Returns the bases classes for cls sorted by the MRO.

    Works around an issue on Jython where inspect.getmro will not return all
    base classes if multiple classes share the same name. Instead, this
    function will return a tuple containing the class itself, and the contents
    of cls.__bases__. See https://github.com/pypa/setuptools/issues/1024.
    ÚJython)ÚplatformÚpython_implementationÚ	__bases__ÚinspectÚgetmro)Úcls©rú7/tmp/pip-build-l_bcah40/setuptools/setuptools/monkey.pyÚ_get_mros	r
cCs0t|tjƒrtnt|tjƒr tndd„}||ƒS)NcSsdS)Nr)ÚitemrrrÚ<lambda>*szget_unpatched.<locals>.<lambda>)Ú
isinstancerÚclass_typesÚget_unpatched_classÚtypesÚFunctionTypeÚget_unpatched_function)rÚlookuprrrÚ
get_unpatched&srcCs:dd„t|ƒDƒ}t|ƒ}|jjdƒs6d|}t|ƒ‚|S)z•Protect against re-patching the distutils if reloaded

    Also ensures that no other distutils extension monkeypatched the distutils
    first.
    css|]}|jjdƒs|VqdS)Ú
setuptoolsN)Ú
__module__Ú
startswith)Ú.0r
rrrú	<genexpr>6sz&get_unpatched_class.<locals>.<genexpr>Ú	distutilsz(distutils has already been patched by %r)r
ÚnextrrÚAssertionError)r
Zexternal_basesÚbaseÚmsgrrrr/srcCsútjtj_tjdk}|r"tjtj_tjdkpxd
tjko@dknpxdtjkoZdknpxdtjkotdkn}|rŒd	}|tjj	_
tƒtƒx"tj
tjtjfD]}tj
j|_qªWtjjtj_tjjtj_d
tjkrðtjjtjd
_tƒdS)Nééééé
réézhttps://upload.pypi.org/legacy/zdistutils.command.build_ext)r"r#r")r$r%r&)r"r)r"r"r%)r"r')r"r'r()r"r#)r"r#r")rÚCommandrÚcoreÚsysÚversion_infoÚfindallÚfilelistÚconfigÚ
PyPIRCCommandÚDEFAULT_REPOSITORYÚ+_patch_distribution_metadata_write_pkg_fileÚ+_patch_distribution_metadata_write_pkg_infoÚdistÚcmdÚDistributionÚ	extensionÚ	ExtensionÚmodulesÚ#patch_for_msvc_specialized_compiler)Zhas_issue_12885Zneeds_warehouseZ	warehouseÚmodulerrrÚ	patch_allAs(




r<cCstjjtjj_dS)zDPatch write_pkg_file to also write Requires-Python/Requires-ExternalN)rr4Úwrite_pkg_filerÚDistributionMetadatarrrrr2ksr2cCs<dtjdd…kodkn}|s*dStjjtjj_dS)zÇ
    Workaround issue #197 - Python 3 prior to 3.2.2 uses an environment-local
    encoding to save the pkg_info. Monkey-patch its write_pkg_info method to
    correct this undesirable behavior.
    r"Nr$)r")r"r$r$)r+r,rr4Úwrite_pkg_inforr>)Zenvironment_localrrrr3rs"r3cCs*t||ƒ}t|ƒjd|ƒt|||ƒdS)zž
    Patch func_name in target_mod with replacement

    Important - original must be resolved by name to avoid
    patching an already patched function.
    Ú	unpatchedN)ÚgetattrÚvarsÚ
setdefaultÚsetattr)ÚreplacementZ
target_modÚ	func_nameÚoriginalrrrÚ
patch_funcs
rHcCs
t|dƒS)Nr@)rA)Ú	candidaterrrr’srcs¾tdƒ‰tjƒdkrdS‡fdd„}tj|dƒ}tj|dƒ}yt|dƒŽt|d	ƒŽWntk
rlYnXyt|d
ƒŽWntk
r’YnXyt|dƒŽWntk
r¸YnXdS)z\
    Patch functions in distutils to use standalone Microsoft Visual C++
    compilers.
    zsetuptools.msvcÚWindowsNcsLd|krdnd}||jdƒ}tˆ|ƒ}t|ƒ}t||ƒsBt|ƒ‚|||fS)zT
        Prepare the parameters for patch_func to patch indicated function.
        Úmsvc9Zmsvc9_Zmsvc14_Ú_)ÚlstriprArÚhasattrÚImportError)Úmod_namerFZrepl_prefixZ	repl_nameÚreplÚmod)ÚmsvcrrÚpatch_params¢s

z9patch_for_msvc_specialized_compiler.<locals>.patch_paramszdistutils.msvc9compilerzdistutils._msvccompilerZfind_vcvarsallZquery_vcvarsallZ_get_vc_envZgen_lib_options)rrÚsystemÚ	functoolsÚpartialrHrO)rTrKZmsvc14r)rSrr:–s&
r:)Ú__doc__r+Údistutils.filelistrrrrVÚ	importlibrrZsetuptools.externrrÚ__all__r
rrr<r2r3rHrr:rrrrÚ<module>s&	*