o
    (ga                     @   s   d Z ddlZddlZddlZddlZddlZddlmZ ddl	Z	ddl
Z
g Z	 dd Zdd Zdd	 Zd
d Zdd Zdd Zdd Zdd ZdS )z
Monkey patching of distutils.
    N)import_modulec                 C   s"   t  dkr| f| j S t| 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
   Y/var/www/python.lazyprojects.co.uk/venv/lib/python3.10/site-packages/setuptools/monkey.py_get_mro   s   	
r   c                 C   s.   t | trtnt | tjrtndd }|| S )Nc                 S   s   d S )Nr
   )itemr
   r
   r   <lambda>(   s    zget_unpatched.<locals>.<lambda>)
isinstancetypeget_unpatched_classtypesFunctionTypeget_unpatched_function)r   lookupr
   r
   r   get_unpatched$   s
   r   c                 C   s:   dd t | D }t|}|jdsd|  }t||S )zProtect against re-patching the distutils if reloaded

    Also ensures that no other distutils extension monkeypatched the distutils
    first.
    c                 s   s     | ]}|j d s|V  qdS )
setuptoolsN)
__module__
startswith).0r	   r
   r
   r   	<genexpr>3   s    

z&get_unpatched_class.<locals>.<genexpr>	distutilsz(distutils has already been patched by %r)r   nextr   r   AssertionError)r	   external_basesbasemsgr
   r
   r   r   -   s   r   c                  C   s   t jtj_tjdk} | rt jtj_tjdk p/dtj  k o dk n  p/dtj  k o-dkn  }|r9d}|tjj	_
t  tjtjtjfD ]}t jj|_qDt jjtj_t jjtj_dtjv ret jjtjd _t  d S )N)      r"   )         )r"      )r"   r'      )r"   r#   zhttps://upload.pypi.org/legacy/zdistutils.command.build_ext)r   Commandr   coresysversion_infofindallfilelistconfigPyPIRCCommandDEFAULT_REPOSITORY_patch_distribution_metadatadistcmdDistribution	extension	Extensionmodules#patch_for_msvc_specialized_compiler)has_issue_12885needs_warehouse	warehousemoduler
   r
   r   	patch_all?   s*   







r>   c                  C   s*   dD ]} t tj| }ttjj| | qdS )zDPatch write_pkg_file and read_pkg_file for higher metadata standards)write_pkg_fileread_pkg_fileget_metadata_versionN)getattrr   r3   setattrr   DistributionMetadata)attrnew_valr
   r
   r   r2   f   s   r2   c                 C   s*   t ||}t| d| t|||  dS )z
    Patch func_name in target_mod with replacement

    Important - original must be resolved by name to avoid
    patching an already patched function.
    	unpatchedN)rB   vars
setdefaultrC   )replacement
target_mod	func_nameoriginalr
   r
   r   
patch_funcm   s   
rN   c                 C   s
   t | dS )NrG   )rB   )	candidater
   r
   r   r   ~   s   
r   c                     s   t d t dkrdS  fdd} t| d}t| d}zt|d  t|d	  W n	 ty5   Y nw zt|d
  W n	 tyG   Y nw z	t|d  W dS  ty[   Y dS w )z\
    Patch functions in distutils to use standalone Microsoft Visual C++
    compilers.
    zsetuptools.msvcWindowsNc                    sL   d| v rdnd}|| d }t |}t| }t||s!t||||fS )zT
        Prepare the parameters for patch_func to patch indicated function.
        msvc9msvc9_msvc14__)lstriprB   r   hasattrImportError)mod_namerL   repl_prefix	repl_namereplmodmsvcr
   r   patch_params   s   


z9patch_for_msvc_specialized_compiler.<locals>.patch_paramszdistutils.msvc9compilerzdistutils._msvccompilerfind_vcvarsallquery_vcvarsall_get_vc_envgen_lib_options)r   r   system	functoolspartialrN   rW   )r_   rQ   msvc14r
   r]   r   r9      s,   r9   )__doc__r+   distutils.filelistr   r   r   re   	importlibr   r   r   __all__r   r   r   r>   r2   rN   r   r9   r
   r
   r
   r   <module>   s&    	'