o
    LK&h-                     @   st  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 d dl	Z
d dlZd dlZd dlmZ ddlmZmZ ddlmZ ejdd Zejd	d
 Zejddddd Zejdd Zejdd Zdd Zejdddd Zejdddd Zejdd Zejdd Zejdd  Zd!d" Z d#d$ Z!d%d& Z"d'd( Z#d)d*e!ddd+fd,d-Z$ejd.d/ Z%dS )0    N)Path)
safer_name   )contextsenvironment)DALSc              
   c   s    t  H}| d| t  %}| d| t   dV  W d   n1 s)w   Y  W d   n1 s8w   Y  W d   dS W d   dS 1 sPw   Y  dS )za
    Override site.USER_BASE and site.USER_SITE with temporary directories in
    a context.
    zsite.USER_BASEzsite.USER_SITEN)r   tempdirsetattrsave_user_site_setting)monkeypatch	user_base	user_site r   L/var/www/html/venv/lib/python3.10/site-packages/setuptools/tests/fixtures.pyuser_override   s   


"r   c                 c   s6    |   }|V  W d    d S 1 sw   Y  d S N)as_cwd)tmpdirorigr   r   r   
tmpdir_cwd"   s   
"r   Tsession)autousescopec                 C   sN   | j jds	dS tt tjd W d   dS 1 s w   Y  dS )z
    Workaround pytest-dev/pytest-xdist#376

    ``pytest-xdist`` tends to inject '' into ``sys.path``,
    which may break certain isolation expectations.
    Remove the entry so the import
    machinery behaves the same irrespective of xdist.
    xdistN )	configpluginmanager
has_plugin
contextlibsuppress
ValueErrorsyspathremove)requestr   r   r   workaround_xdist_376(   s
   
"r%   c                 C   sH   g d}zt j|t| d W | d S  ty#   td Y | d S w )z<
    Clone the 'sampleproject' and return a path to it.
    )gitclonez%https://github.com/pypa/sampleproject)cwdzUnable to clone sampleprojectsampleproject)
subprocess
check_callstr	Exceptionpytestskip)tmp_pathcmdr   r   r   sample_project9   s   r2   c                 c   s8    t |  d V  W d    d S 1 sw   Y  d S r   )r"   r   )r2   r   r   r   sample_project_cwdF   s   "r3   c              
   C   s   t || d]}t|dd }t|dd }|r'|r'||fW  d    S t|jjd r2J t	t
jdddt|t|jjg t|jjd rOJ t|dt|dfW  d    S 1 sgw   Y  d S )N
dist_buildz*.tar.gzz*.whlzbuild/lib/build-mbuildz--outdir)r   session_locked_tmp_dirnextglobr   r   rootdirexistsr*   check_outputr!   
executabler,   )tmp_path_factoryr$   tmpsdistwheelr   r   r   _build_distributionsT   s*   	

$rB   )r   c                 C   s8   t d}|rt j|rt| S t| |\}}|S )NPRE_BUILT_SETUPTOOLS_SDISTosgetenvr"   r;   r   resolverB   )r>   r$   prebuiltr@   _r   r   r   setuptools_sdisto   
   
rJ   c                 C   s8   t d}|rt j|rt| S t| |\}}|S )NPRE_BUILT_SETUPTOOLS_WHEELrD   )r>   r$   rH   rI   rA   r   r   r   setuptools_wheely   rK   rM   c                 C   sd   t  }t| d |_ddg|_t||_tj dd |	 W  d   S 1 s+w   Y  dS )z?Virtual env with the version of setuptools under test installedvenv--no-setuptoolsz--wheel=bundleN)
PYTHONPATH)
r   
VirtualEnvr"   r   rootcreate_optsr,   reqr   create)r0   rM   envr   r   r   rN      s   

$rN   c                 C   s.   t  }t| d |_ddg|_|  |S )z7Virtual env without any version of setuptools installedvenv_without_setuptoolsrO   
--no-wheelr   rQ   r"   r   rR   rS   
ensure_envr0   rV   r   r   r   rW      
   
rW   c                 C   s.   t  }t| d |_g d|_|  |S )z1Virtual env without any common packages installed	bare_venv)rO   z--no-piprX   z	--no-seedrY   r[   r   r   r   r]      r\   r]   c                 C   s   t |dksJ t| d3}|D ]'\}}t|d}tj|d}t | |_t	t

 |_|j||d qW d   dS 1 sDw   Y  dS )z
    Create a simple sdist tarball at dist_path, containing the files
    listed in ``files`` as ``(filename, content)`` tuples.
    r   zw:gzutf-8)name)fileobjN)lentarfileopenioBytesIOencodeTarInfogetvaluesizeinttimemtimeaddfile)	dist_pathfilesdistfilenamecontent
file_bytes	file_infor   r   r   
make_sdist   s   "ru   c              	   C   s(   t | dtd|d|dfdg dS )z\
    Create a simple sdist tarball at dist_path, containing just a simple
    setup.py.
    setup.pyzT             import setuptools
             setuptools.setup(
                 name=z,
                 version=z
             )
         	setup.cfgr   N)ru   r   )rn   distnameversionr   r   r   make_trivial_sdist   s   r{   c           
   
      s   d|v sJ | d  d } fddtdt d D }td|d|d|d	|d
	}d}d|ftj|d|fg}|dd D ]}tjj| ddg  }	||	df qEt| | dS )z
    Make an sdist tarball with distname and version which also contains one
    package with the same name as distname.  The top-level package is
    designated a namespace package).
    .r   c                    s   g | ]}d   d| qS )r|   N)join).0idxpartsr   r   
<listcomp>   s    z$make_nspkg_sdist.<locals>.<listcomp>r   zE        import setuptools
        setuptools.setup(
            name=z,
            version=z,
            packages=z",
            namespace_packages=[z]
        )
    z7__import__('pkg_resources').declare_namespace(__name__)rv   __init__.pyNr   )	splitrangera   r   rE   r"   r}   appendru   )
rn   ry   rz   	nspackagepackagessetup_pyinitro   packagerq   r   r   r   make_nspkg_sdist   s*   
 r   c                 C   s&   t | dtdj|||dfdg d S )Nrv   z                import setuptools
                setuptools.setup(
                  name={name!r},
                  version={version!r},
                  python_requires={python_requires!r},
                )
                )r_   rz   python_requiresrw   )ru   r   format)rn   ry   rz   r   r   r   r   make_python_requires_sdist   s   	r   foobarz0.1r   c                 C   s  t |}dd| d| gtj| gd}|r|| tj| d}	t|	 |rjg }
g }|D ](}||}|d v rA|}n|
}t	|t
tfrOd|}|| d|  q1tdjd	|
d	|d
}nd}ttj|	dddd}|| W d   n1 sw   Y  |du rtd}ttj|	dddd}|||  W d   n1 sw   Y  tj| | d| d}|||| |	S )a  Creates a source tree under path for a trivial test package that has a
    single requirement in setup_requires--a tarball for that requirement is
    also created and added to the dependency_links argument.

    ``distname`` and ``version`` refer to the name/version of the package that
    the test package requires via ``setup_requires``.  The name of the test
    package itself is just 'test_pkg'.
    test_pkgz0.0z==)r_   rz   setup_requiresdependency_linkszname version;z: zg
            [metadata]
            {metadata}
            [options]
            {options}
            
)optionsmetadatar   rx   wr^   )encodingNzI            import setuptools
            setuptools.setup(**%r)
        rv   -z.tar.gz)r   rE   r"   abspathupdater}   mkdirpopr   
isinstancetuplelistr   r   r   rc   write)r"   ry   rz   make_packagesetup_py_templatesetup_attrsuse_setup_cfgnormalized_distnametest_setup_attrsr   r   r   r_   valuesectiontest_setup_cfg_contentsffoobar_pathr   r   r   create_setup_requires_package  sT   



r   c                 C   sd   t dt dt ddddddid	}|g d
 | d }|  tjj||d |dd |S )Nz
            [build-system]
            requires = ["setuptools"]
            build-backend = "setuptools.build_meta"
            z
            __import__('setuptools').setup(
                pbr=True,
                setup_requires=["pbr"],
            )
            z
            [metadata]
            name = mypkg

            [files]
            packages =
                mypkg
            r   zprint('Hello world!'))r   zhello.pyztest.txtzAnother file in here.)zpyproject.tomlrv   rx   mypkgother)pythonr5   pipinstallpbrr   )prefixPBR_VERSIONz0.42)r   runr   jaracor"   r6   setenv)r0   r   rN   ro   r   r   r   r   pbr_packagea  s(    r   )&r   rd   rE   r*   r!   rb   rk   pathlibr   jaraco.pathr   r"   r.   setuptools._normalizationr   r   r   r   textwrapr   fixturer   r   r%   r2   r3   rB   rJ   rM   rN   rW   r]   ru   r{   r   r   r   r   r   r   r   r   <module>   s`    







	
	

	
	$
M