o
    (g()                     @   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ZddlZddlZddl	Z	ddl
Z
ddlmZ g dZG dd deZG dd de	jjZejd	d
 Zdd Zdd Zdd Zejdd ZG dd deZG dd deZe ZejZejZejZejZej Z e Z!dS )a-  A PEP 517 interface to setuptools

Previously, when a user or a command line tool (let's call it a "frontend")
needed to make a request of setuptools to take a certain action, for
example, generating a list of installation requirements, the frontend would
would call "setup.py egg_info" or "setup.py bdist_wheel" on the command line.

PEP 517 defines a different method of interfacing with setuptools. Rather
than calling "setup.py" directly, the frontend should:

  1. Set the current directory to the directory with a setup.py file
  2. Import this module into a safe python interpreter (one in which
     setuptools can potentially set global variables or crash hard).
  3. Call one of the functions defined in PEP 517.

What each function does is defined in PEP 517. However, here is a "casual"
definition of the functions (this definition should not be relied on for
bug reports or API stability):

  - `build_wheel`: build a wheel in the folder and return the basename
  - `get_requires_for_build_wheel`: get the `setup_requires` to build
  - `prepare_metadata_for_build_wheel`: get the `install_requires`
  - `build_sdist`: build an sdist in the folder and return the basename
  - `get_requires_for_build_sdist`: get the `setup_requires` to build

Again, this is not a formal definition! Just a "taste" of the module.
    N)parse_requirements)get_requires_for_build_sdistget_requires_for_build_wheel prepare_metadata_for_build_wheelbuild_wheelbuild_sdist
__legacy__SetupRequirementsErrorc                   @   s   e Zd Zdd ZdS )r	   c                 C   s
   || _ d S N)
specifiers)selfr    r   ]/var/www/python.lazyprojects.co.uk/venv/lib/python3.10/site-packages/setuptools/build_meta.py__init__5   s   
zSetupRequirementsError.__init__N)__name__
__module____qualname__r   r   r   r   r   r	   4   s    r	   c                   @   s&   e Zd Zdd Zeejdd ZdS )Distributionc                 C   s   t ttt|}t|r
   )listmapstrr   r	   )r   r   specifier_listr   r   r   fetch_build_eggs:   s   zDistribution.fetch_build_eggsc                 c   s2    t jj}| t j_z
dV  W |t j_dS |t j_w )zw
        Replace
        distutils.dist.Distribution with this class
        for the duration of this context.
        N)	distutilscorer   )clsorigr   r   r   patch?   s   zDistribution.patchN)r   r   r   r   classmethod
contextlibcontextmanagerr   r   r   r   r   r   9   s
    r   c                  c   s.    t j} dd t _z	dV  W | t _dS | t _w )a
  Temporarily disable installing setup_requires

    Under PEP 517, the backend reports build dependencies to the frontend,
    and the frontend is responsible for ensuring they're installed.
    So setuptools (acting as a backend) should not try to install them.
    c                 S   s   d S r
   r   )attrsr   r   r   <lambda>X   s    z+no_install_setup_requires.<locals>.<lambda>N)
setuptools_install_setup_requires)r   r   r   r   no_install_setup_requiresO   s   
r%   c                    s    fddt  D S )Nc                    s&   g | ]}t jt j |r|qS r   )ospathisdirjoin).0namea_dirr   r   
<listcomp>`   s    
z1_get_immediate_subdirectories.<locals>.<listcomp>)r&   listdirr,   r   r,   r   _get_immediate_subdirectories_   s   r0   c                    s<    fddt | D }z|\}W |S  ty   tdw )Nc                 3   s    | ]
}|  r|V  qd S r
   endswithr*   f	extensionr   r   	<genexpr>e   s    
z'_file_with_extension.<locals>.<genexpr>z[No distribution was found. Ensure that `setup.py` is not empty and that it calls `setup()`.)r&   r/   
ValueError)	directoryr6   matchingfiler   r5   r   _file_with_extensiond   s   
r<   c                 C   s&   t j| stdS ttdt| S )Nz%from setuptools import setup; setup()open)r&   r'   existsioStringIOgetattrtokenizer=   setup_scriptr   r   r   _open_setup_scriptr   s   
rE   c                   c   sB    t   t dd d V  W d    d S 1 sw   Y  d S )Nignorezsetup.py install is deprecated)warningscatch_warningsfilterwarningsr   r   r   r   suppress_known_deprecationz   s
   
"rJ   c                   @   sf   e Zd Zdd Zdd ZdddZdd	d
ZdddZ	dddZdd Z			dddZ
dddZdS )_BuildMetaBackendc                 C   s   |pi }| dg  |S )N--global-option)
setdefaultr   config_settingsr   r   r   _fix_config   s   z_BuildMetaBackend._fix_configc              
   C   s   |  |}tjd d dg |d  t_zt  |   W d    W |S 1 s*w   Y  W |S  tyI } z||j7 }W Y d }~|S d }~ww )N   egg_inforL   )rP   sysargvr   r   	run_setupr	   r   )r   rO   requirementser   r   r   _get_build_requires   s    


z%_BuildMetaBackend._get_build_requiressetup.pyc                 C   sX   |}d}t |}| dd}W d    n1 sw   Y  tt||dt  d S )N__main__z\r\nz\nexec)rE   readreplacer[   compilelocals)r   rD   __file__r   r4   coder   r   r   rU      s   
z_BuildMetaBackend.run_setupNc                 C   s   |  |}| j|dgdS )NwheelrV   rP   rX   rN   r   r   r   r      s   
z._BuildMetaBackend.get_requires_for_build_wheelc                 C   s   |  |}| j|g dS )Nrc   rd   rN   r   r   r   r      s   
z._BuildMetaBackend.get_requires_for_build_sdistc                 C   s   t jd d dd|g t _t  |   W d    n1 sw   Y  |}	 dd t|D }t|dkrLtt|dkrLtj	|t|d }q&t|dksTJ 	 ||krmt
tj	||d | t
j|dd |d S )	NrQ   	dist_infoz
--egg-baseTc                 S   s   g | ]	}| d r|qS )z
.dist-infor1   r3   r   r   r   r.      s    
zF_BuildMetaBackend.prepare_metadata_for_build_wheel.<locals>.<listcomp>r   )ignore_errors)rS   rT   r%   rU   r&   r/   lenr0   r'   r)   shutilmovermtree)r   metadata_directoryrO   dist_info_directory
dist_infosr   r   r   r      s0   
z2_BuildMetaBackend.prepare_metadata_for_build_wheelc              	   C   s   |  |}tj|}tj|dd tj|dT}tjd d | d|g |d  t_t	  | 
  W d    n1 s=w   Y  t||}tj||}tj|rYt| ttj||| W d    |S 1 sow   Y  |S )NT)exist_ok)dirrQ   z
--dist-dirrL   )rP   r&   r'   abspathmakedirstempfileTemporaryDirectoryrS   rT   r%   rU   r<   r)   r>   removerename)r   setup_commandresult_extensionresult_directoryrO   tmp_dist_dirresult_basenameresult_pathr   r   r   _build_with_temp_dir   s.   



z&_BuildMetaBackend._build_with_temp_dirc                 C   s<   t   | dgd||W  d    S 1 sw   Y  d S )Nbdist_wheelz.whl)rJ   r|   )r   wheel_directoryrO   rk   r   r   r   r      s
   
$z_BuildMetaBackend.build_wheelc                 C   s   |  g dd||S )N)sdistz	--formatsgztarz.tar.gz)r|   )r   sdist_directoryrO   r   r   r   r      s   
z_BuildMetaBackend.build_sdistrY   r
   )NN)r   r   r   rP   rX   rU   r   r   r   r|   r   r   r   r   r   r   rK      s    



"
rK   c                       s"   e Zd ZdZd fdd	Z  ZS )_BuildMetaLegacyBackendaO  Compatibility backend for setuptools

    This is a version of setuptools.build_meta that endeavors
    to maintain backwards
    compatibility with pre-PEP 517 modes of invocation. It
    exists as a temporary
    bridge between the old packaging mechanism and the new
    packaging mechanism,
    and will eventually be removed.
    rY   c              
      s   t tj}tjtj|}|tjvrtjd| tjd }|tjd< ztt	| j
|d W |tjd d < |tjd< d S |tjd d < |tjd< w )Nr   rC   )r   rS   r'   r&   dirnamerp   insertrT   superr   rU   )r   rD   sys_path
script_dir
sys_argv_0	__class__r   r   rU      s    



z!_BuildMetaLegacyBackend.run_setupr   )r   r   r   __doc__rU   __classcell__r   r   r   r   r      s    
r   )"r   r?   r&   rS   rB   rh   r   rr   rG   r#   r   pkg_resourcesr   __all__BaseExceptionr	   distr   r    r%   r0   r<   rE   rJ   objectrK   r   _BACKENDr   r   r   r   r   r   r   r   r   r   <module>   s>    	

n)
