o
    NZh-                     @   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setattrZsave_user_site_setting)monkeypatch	user_base	user_site r   H/var/www/auris/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)Zas_cwd)Ztmpdirorigr   r   r   
tmpdir_cwd"   s   
"r   Tsession)Z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.
    ZxdistN )	configZpluginmanagerZ
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 sampleprojectZsampleproject)
subprocess
check_callstr	Exceptionpytestskip)tmp_pathcmdr   r   r   sample_project9   s   r*   c                 c   s8    t |  d V  W d    d S 1 sw   Y  d S r   )r   r   )r*   r   r   r   sample_project_cwdF   s   "r+   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 )NZ
dist_buildz*.tar.gzz*.whlzbuild/lib/build-mbuildz--outdir)r   Zsession_locked_tmp_dirnextglobr   r   rootdirexistsr"   check_outputr   
executabler$   )tmp_path_factoryr   tmpsdistwheelr   r   r   _build_distributionsT   s*   	

$r8   )r   c                 C   s8   t d}|rt j|rt| S t| |\}}|S )NZPRE_BUILT_SETUPTOOLS_SDISTosgetenvr   r1   r   resolver8   )r4   r   prebuiltr6   _r   r   r   setuptools_sdisto   
   
r?   c                 C   s8   t d}|rt j|rt| S t| |\}}|S )NZPRE_BUILT_SETUPTOOLS_WHEELr9   )r4   r   r=   r>   r7   r   r   r   setuptools_wheely   r@   rA   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)r(   rA   envr   r   r   rB      s   

$rB   c                 C   s.   t  }t| d |_ddg|_|  |S )z7Virtual env without any version of setuptools installedvenv_without_setuptoolsrC   
--no-wheelr   rE   r   r   rF   rG   Z
ensure_envr(   rJ   r   r   r   rK      
   
rK   c                 C   s.   t  }t| d |_g d|_|  |S )z1Virtual env without any common packages installed	bare_venv)rC   z--no-piprL   z	--no-seedrM   rN   r   r   r   rP      rO   rP   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contentZ
file_bytes	file_infor   r   r   
make_sdist   s   "rg   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)rg   r   )ra   distnameversionr   r   r   make_trivial_sdist   s   rm   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 )rn   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__)rh   __init__.pyNr   )	splitrangerT   r   r:   r   ro   appendrg   )
ra   rk   rl   Z	nspackagepackagessetup_pyinitrb   packagerd   r   rr   r   make_nspkg_sdist   s*   
 r}   c                 C   s&   t | dtdj|||dfdg d S )Nrh   z                import setuptools
                setuptools.setup(
                  name={name!r},
                  version={version!r},
                  python_requires={python_requires!r},
                )
                )rR   rl   python_requiresri   )rg   r   format)ra   rk   rl   r~   r   r   r   make_python_requires_sdist   s   	r   Z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==)rR   rl   Zsetup_requiresZdependency_linkszname version;z: zg
            [metadata]
            {metadata}
            [options]
            {options}
            
)optionsmetadatar   rj   wrQ   )encodingNzI            import setuptools
            setuptools.setup(**%r)
        rh   -z.tar.gz)r   r:   r   abspathupdatero   mkdirpoprv   
isinstancetuplelistrx   r   r   rV   write)r   rk   rl   Zmake_packageZsetup_py_templateZsetup_attrsZuse_setup_cfgZnormalized_distnameZtest_setup_attrsr   r   r   rR   valuesectionZtest_setup_cfg_contentsfZ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!'))ru   zhello.pyztest.txtzAnother file in here.)zpyproject.tomlrh   rj   mypkgother)pythonr,   pipinstallZpbrr   )prefixZPBR_VERSIONz0.42)r   runr   jaracor   r-   Zsetenv)r(   r
   rB   rb   r   r   r   r   pbr_packagea  s(    r   )&r   rW   r:   r"   r   rU   r^   pathlibr   Zjaraco.pathr   r   r&   Zsetuptools._normalizationr   r   r   r   textwrapr   Zfixturer   r   r   r*   r+   r8   r?   rA   rB   rK   rP   rg   rm   r}   r   r   r   r   r   r   r   <module>   s`    







	
	

	
	$
M