o _aa@sdZddlZddlZddlZddlZddlZddlmZddl Z ddl Z gZ ddZ ddZ dd Zd d Zd d ZddZddZddZdS)z Monkey patching of distutils. N) import_modulecCs"tdkr |f|jSt|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)platformpython_implementation __bases__inspectgetmro)clsr 3/usr/lib/python3/dist-packages/setuptools/monkey.py_get_mros  r cCs.t|trtn t|tjrtndd}||S)NcSsdS)Nr )itemr r r (szget_unpatched..) isinstancetypeget_unpatched_classtypes FunctionTypeget_unpatched_function)r lookupr r r get_unpatched$s rcCs:ddt|D}t|}|jdsd|}t||S)zProtect against re-patching the distutils if reloaded Also ensures that no other distutils extension monkeypatched the distutils first. css |] }|jds|VqdS) setuptoolsN) __module__ startswith).0r r r r 3s  z&get_unpatched_class.. distutilsz(distutils has already been patched by %r)r nextrrAssertionError)r external_basesbasemsgr r r r-s rcCstjtj_tjdk}|rtjtj_tjdkp/dtjko dknp/dtjko-dkn}|r9d}|tjj _ t tj tjtj fD]}tj j|_qDtjjtj_tjjtj_dtjvretjjtjd_tdS)N)r") )r")r"r')r"r#zhttps://upload.pypi.org/legacy/zdistutils.command.build_ext)rCommandrcoresys version_infofindallfilelistconfig PyPIRCCommandDEFAULT_REPOSITORY_patch_distribution_metadatadistcmd Distribution extension Extensionmodules#patch_for_msvc_specialized_compiler)has_issue_12885needs_warehouse warehousemoduler r r patch_all?s*          r>cCs*dD]}ttj|}ttjj||qdS)zDPatch write_pkg_file and read_pkg_file for higher metadata standards)write_pkg_file read_pkg_fileget_metadata_versionN)getattrrr3setattrrDistributionMetadata)attrnew_valr r r r2fs r2cCs*t||}t|d|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)rBvars setdefaultrC) replacement target_mod func_nameoriginalr r r patch_funcms rNcCs t|dS)NrG)rB) candidater r r r~s rcstdtdkr dSfdd}t|d}t|d}zt|dt|d Wn ty5Ynwzt|d Wn tyGYnwz t|d WdSty[YdSw) z\ Patch functions in distutils to use standalone Microsoft Visual C++ compilers. zsetuptools.msvcWindowsNcsLd|vrdnd}||d}t|}t|}t||s!t||||fS)zT Prepare the parameters for patch_func to patch indicated function. msvc9msvc9_msvc14__)lstriprBrhasattr ImportError)mod_namerL repl_prefix repl_namereplmodmsvcr r patch_paramss   z9patch_for_msvc_specialized_compiler..patch_paramszdistutils.msvc9compilerzdistutils._msvccompilerfind_vcvarsallquery_vcvarsall _get_vc_envgen_lib_options)rrsystem functoolspartialrNrW)r_rQmsvc14r r]r r9s,       r9)__doc__r+distutils.filelistrrrre importlibrrr__all__r rrr>r2rNrr9r r r r s&  '