3 l]�j��@s�dZddlZddlZddlZddlZddlZddlmZddl Z ddl m Z ddl Z gZ dd�Zdd�Zd d �Zd d �Zd d�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. ZJython)�platformZpython_implementation� __bases__�inspectZgetmro)�cls�r�/usr/lib/python3.6/monkey.py�_get_mros  r cCs0t|tj�rtnt|tj�r tndd�}||�S)NcSsdS)Nr)�itemrrr �<lambda>*szget_unpatched.<locals>.<lambda>)� isinstancerZ 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)�.0rrrr � <genexpr>6sz&get_unpatched_class.<locals>.<genexpr>� distutilsz(distutils has already been patched by %r)r �nextrr�AssertionError)rZexternal_bases�base�msgrrr r/s  rcCs�tjtj_tjd k}|r"tjtj_tjd kpxd tjko@dknpxdtjkoZdknpxdtjkotdkn}|r�d }|tjj _ t �x"tj tjtj fD]}tj j|_q�Wtjjtj_tjjtj_d tjk�r�tjjtjd _t�dS)N����� r��zhttps://upload.pypi.org/legacy/zdistutils.command.build_ext)rrr)r r!r")rr)rrr!)rr#)rr#r$)rr)rrr)rZCommandrZcore�sys� version_info�findallZfilelist�configZ PyPIRCCommandZDEFAULT_REPOSITORY�+_patch_distribution_metadata_write_pkg_file�dist�cmdZ Distribution� extensionZ Extension�modules�#patch_for_msvc_specialized_compiler)Zhas_issue_12885Zneeds_warehouseZ warehouse�modulerrr � patch_allAs&        r0cCstjjtjj_dS)zDPatch write_pkg_file to also write Requires-Python/Requires-ExternalN)rr*Zwrite_pkg_filerZDistributionMetadatarrrr r)jsr)cCs*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)Z replacementZ target_mod� func_nameZoriginalrrr � patch_funcqs r7cCs t|d�S)Nr1)r2)� 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.msvcZWindowsNcsLd|kr dnd}||jd�}t�|�}t|�}t||�sBt|��|||fS)zT Prepare the parameters for patch_func to patch indicated function. �msvc9Zmsvc9_Zmsvc14_�_)�lstripr2r�hasattr� ImportError)Zmod_namer6Z repl_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�partialr7r=)rAr9Zmsvc14r)r@r r.�s&    r.)�__doc__r%Zdistutils.filelistrrrrC� importlibrrZsetuptools.externrr�__all__r rrr0r)r7rr.rrrr �<module>s$   )