o
    5‘ði(‚  ã                	   @   s¸  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
 d dlmZ d dlmZmZ d dlmZ d dlZd dlmZ d dlmZ d dlmZ d	d
lmZ dZee dd¡ƒZdejv Z ej!j"ej#dkore dd�Z$G dd„ dƒZ%G dd„ de%ƒZ&G dd„ de%ƒZ'edƒedƒdœedƒedƒdœedƒedƒdœdedƒiedƒed ƒd!œedƒded ƒd"œgZ(G d#d$„ d$ƒZ)G d%d&„ d&e)ƒZ*ej! +d'¡d(d)„ ƒZ,d*d+„ Z-dS ),é    N)Úfutures)ÚPath)ÚAnyÚCallable)ÚZipFile)Úpath)ÚRequirement)ÚSetuptoolsDeprecationWarningé   )ÚDALSz __import__('setuptools').setup()ÚTIMEOUT_BACKEND_TESTÚ180Ú__pypy__Úwin32z_The combination of PyPy + Windows + pytest-xdist + ProcessPoolExecutor is flaky and problematic)Úreasonc                   @   s   e Zd Zdddd„ZdS )	ÚBuildBackendBaseÚ.Núsetuptools.build_metaÚreturnc                 C   s   || _ |pi | _|| _d S )N)ÚcwdÚenvÚbackend_name)Úselfr   r   r   © r   ú_/root/parts/websockify/install/lib/python3.10/site-packages/setuptools/tests/test_build_meta.pyÚ__init__&   s   

zBuildBackendBase.__init__)r   Nr   ©r   N)Ú__name__Ú
__module__Ú__qualname__r   r   r   r   r   r   %   s    r   c                       sD   e Zd ZdZd‡ fdd„Zdededef fdd	„Zd
d„ Z	‡  Z
S )ÚBuildBackendzPEP 517 Build Backendr   Nc                    s$   t ƒ j|i |¤Ž tjdd�| _d S )Nr
   )Úmax_workers)Úsuperr   r   ÚProcessPoolExecutorÚpool)r   ÚargsÚkwargs©Ú	__class__r   r   r   /   s   zBuildBackend.__init__Úname.c                    s   ‡ ‡fdd„}|S )ú<Handles arbitrary function invocations on the build backend.c               
      sÂ   t j ˆj¡}t|ˆjˆjƒ}d }zˆj t j	¡ 
t¡}ˆjj|ˆ g| ¢R i |¤Ž 
t¡W S  tjyM   ˆjjdd� ˆ |¡ t dt› d�¡ Y d S  tjjttfy`   tr_t d¡ ‚ w )NF)Úwaitz(Backend did not respond before timeout (z s)z3PyPy frequently fails tests with ProcessPoolExector)Úosr   Úabspathr   ÚBuildBackendCallerr   r   r$   ÚsubmitÚgetpidÚresultÚTIMEOUTr   ÚTimeoutErrorÚshutdownÚ_killÚpytestÚxfailÚprocessÚBrokenProcessPoolÚMemoryErrorÚOSErrorÚIS_PYPY)r%   ÚkwÚrootÚcallerÚpid©r)   r   r   r   Úmethod6   s   $

ýz(BuildBackend.__getattr__.<locals>.methodr   )r   r)   rB   r   rA   r   Ú__getattr__3   s   zBuildBackend.__getattr__c                 C   s\   |d u rd S t  tt¡� t |tjdkrtjntj	¡ W d   ƒ d S 1 s'w   Y  d S )NÚnt)
Ú
contextlibÚsuppressÚProcessLookupErrorr;   r,   Úkillr)   ÚsignalÚSIGTERMÚSIGKILL)r   r@   r   r   r   r5   H   s
    "ÿzBuildBackend._killr   )r   r   r   Ú__doc__r   Ústrr   r   rC   r5   Ú__classcell__r   r   r'   r   r    ,   s
    r    c                       s,   e Zd Zd‡ fdd„Zdefdd„Z‡  ZS )r.   r   Nc                    s,   t ƒ j|i |¤Ž | j d¡\| _}| _d S )Nú:)r"   r   r   Ú	partitionÚbackend_obj)r   r%   r&   Ú_r'   r   r   r   P   s   zBuildBackendCaller.__init__c                 O   sR   t  | j¡ t j | j¡ t | j¡}| j	rt
|| j	ƒ}n|}t
||ƒ|i |¤ŽS )r*   )r,   Úchdirr   ÚenvironÚupdater   Ú	importlibÚimport_moduler   rQ   Úgetattr)r   r)   r%   r=   ÚmodÚbackendr   r   r   Ú__call__U   s   zBuildBackendCaller.__call__r   )r   r   r   r   r   r[   rN   r   r   r'   r   r.   O   s    r.   zÒ
            __import__('setuptools').setup(
                name='foo',
                version='0.0.0',
                py_modules=['hello'],
                setup_requires=['six'],
            )
            úC
            def run():
                print('hello')
            ©úsetup.pyúhello.pyzü
            assert __name__ == '__main__'
            __import__('setuptools').setup(
                name='foo',
                version='0.0.0',
                py_modules=['hello'],
                setup_requires=['six'],
            )
            aF  
            variable = True
            def function():
                return variable
            assert variable
            __import__('setuptools').setup(
                name='foo',
                version='0.0.0',
                py_modules=['hello'],
                setup_requires=['six'],
            )
            r^   aƒ  
            # Some packages construct files on the fly, include them in the package,
            # and immediately remove them after `setup()` (e.g. pybind11==2.9.1).
            # Therefore, we cannot use `distutils.core.run_setup(..., stop_after=...)`
            # to obtain a distribution object first, and then run the distutils
            # commands later, because these files will be removed in the meantime.

            with open('world.py', 'w', encoding="utf-8") as f:
                f.write('x = 42')

            try:
                __import__('setuptools').setup(
                    name='foo',
                    version='0.0.0',
                    py_modules=['world'],
                    setup_requires=['six'],
                )
            finally:
                # Some packages will clean temporary files
                __import__('os').unlink('world.py')
            zŽ
        [metadata]
        name = foo
        version = 0.0.0

        [options]
        py_modules=hello
        setup_requires=six
        z7
        def run():
            print('hello')
        )ú	setup.cfgr_   )r`   r^   r_   c                   @   s   e Zd ZdZdd„ Zejed�dd„ ƒZdd„ Z	d	d
„ Z
dd„ Zej dd¡dd„ ƒZej ddeg¡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#d$„ Zd%d&„ Zd'd(„ Zed)ƒd*ed+ƒd,œZd-d.„ Zed/ƒd0d1d2iid3œZd4d5„ Zd6d7„ Z d8d9„ Z!ej d:d;d<ig¡d=d>„ ƒZ"ej d?d@dAgfdBdAgfdCdAgfdDdAgfdEdAdFgfdGdAgfdHdAgfdIdJgfdKdAdFgfdLdAdFgfdMdAdFgfg¡ej dNdOdPg¡dQdR„ ƒƒZ#dSdT„ Z$dUdV„ Z%dWedXƒiZ&dYdZ„ Z'dWed[ƒiZ(d\d]„ Z)ej d^d_¡d`da„ ƒZ*dS )bÚTestBuildMetaBackendr   c                 C   s   t | jd�S )N©r   )r    r   )r   r   r   r   Úget_build_backendå   s   z&TestBuildMetaBackend.get_build_backend)Úparamsc                 c   sN   � t j|jt|ƒd� | ¡ � |  ¡ V  W d   ƒ d S 1 s w   Y  d S )N)Úprefix)r   ÚbuildÚparamrM   Úas_cwdrc   )r   ÚtmpdirÚrequestr   r   r   Úbuild_backendè   s
   €
"ÿz"TestBuildMetaBackend.build_backendc                 C   ó&   |  ¡ }dg}t|ƒt|ƒksJ ‚d S ©NÚsix)Úget_requires_for_build_wheelÚsorted©r   rk   ÚactualÚexpectedr   r   r   Ú!test_get_requires_for_build_wheelî   ó   z6TestBuildMetaBackend.test_get_requires_for_build_wheelc                 C   rl   rm   )Úget_requires_for_build_sdistrp   rq   r   r   r   Ú!test_get_requires_for_build_sdistó   ru   z6TestBuildMetaBackend.test_get_requires_for_build_sdistc           	      C   s²   t j d¡}t  |¡ | |¡}t j ||¡}t j |¡sJ ‚t j d¡r'J ‚t|ƒ�}t| 	¡ ƒ}W d   ƒ n1 s<w   Y  dd„ |D ƒ}dd„ |D ƒ}t
|ƒdksWJ ‚d S )Nz	pip-wheelúworld.pyc                 s   s   � | ]
}|  d ¡r|V  qdS )z.pyN©Úendswith©Ú.0Úfr   r   r   Ú	<genexpr>  s   € z8TestBuildMetaBackend.test_build_wheel.<locals>.<genexpr>c                 S   s   g | ]	}|  d ¡s|‘qS )r^   ry   r{   r   r   r   Ú
<listcomp>	  s    z9TestBuildMetaBackend.test_build_wheel.<locals>.<listcomp>r
   )r,   r   r-   ÚmakedirsÚbuild_wheelÚjoinÚisfiler   ÚsetÚnamelistÚlen)	r   rk   Údist_dirÚ
wheel_nameÚ
wheel_fileÚzipfileÚwheel_contentsÚpython_scriptsÚmodulesr   r   r   Útest_build_wheelø   s   


ÿz%TestBuildMetaBackend.test_build_wheelÚ
build_type)ÚwheelÚsdistc                 C   s  ddt dƒt dƒdœ}t |¡ tj d| ¡}|  ¡ }t|d| ƒ}||ƒ}tdd	d
d��}| d¡ W d   ƒ n1 s>w   Y  ||ƒ}	tj 	tj 
||¡¡sTJ ‚||	ksZJ ‚ttj 
||	¡dƒ ¡  ||ƒ}
|
|	kspJ ‚tj tj 
||
¡¡dksJ ‚d S )Nz$from setuptools import setup
setup()z0.0.1zo
                [metadata]
                name = foo
                version = file: VERSION
                ú›
                [build-system]
                requires = ["setuptools", "wheel"]
                build-backend = "setuptools.build_meta"
                )r^   ÚVERSIONr`   úpyproject.tomlzpreexisting-Úbuild_r“   Úwtúutf-8©Úencodingz0.0.2Úwbr   )r   r   rf   r,   r-   rc   rX   ÚopenÚwriterƒ   r‚   ÚcloseÚgetsize)r   r�   Ú
tmpdir_cwdÚfilesr‡   rk   Úbuild_methodÚfirst_resultÚversion_fileÚsecond_resultÚthird_resultr   r   r   Ú%test_build_with_existing_file_present  s0   ÿÿö
ÿ"z:TestBuildMetaBackend.test_build_with_existing_file_presentÚsetup_scriptNc                 C   s  t dƒt dƒdddddddd	d
œidœ}|r||d< |  ¡ }| ¡ �; t |¡ ddg}t ¡ � |D ]	}t d|t¡ q3| 	d¡}| 
d¡}W d   ƒ n1 sQw   Y  W d   ƒ n1 s`w   Y  t tj |d|¡¡�}	t|	 ¡ ƒ}
W d   ƒ n1 s�w   Y  ttj |d|¡ƒ�&}t| ¡ ƒ}t| d¡dƒ}t| d¡dƒ}t| d¡dƒ}W d   ƒ n1 s¹w   Y  |
dh h d£ksÉJ ‚|h d£ksÑJ ‚|dks×J ‚ddddddttdƒƒ dttdƒƒ fD ]}||v søJ ||fƒ‚qì| ¡  d¡�sJ ‚| ¡ d k�sJ ‚d S )!Naj  
                [build-system]
                requires = ["setuptools", "wheel"]
                build-backend = "setuptools.build_meta"

                [project]
                name = "foo"
                license = {text = "MIT"}
                description = "This is a Python package"
                dynamic = ["version", "readme"]
                classifiers = [
                    "Development Status :: 5 - Production/Stable",
                    "Intended Audience :: Developers"
                ]
                urls = {Homepage = "http://github.com"}
                dependencies = [
                    "appdirs",
                ]

                [project.optional-dependencies]
                all = [
                    "tomli>=1",
                    "pyscaffold>=4,<5",
                    'importlib; python_version == "2.6"',
                ]

                [project.scripts]
                foo = "foo.cli:main"

                [tool.setuptools]
                zip-safe = false
                package-dir = {"" = "src"}
                packages = {find = {where = ["src"]}}
                license-files = ["LICENSE*"]

                [tool.setuptools.dynamic]
                version = {attr = "foo.__version__"}
                readme = {file = "README.rst"}

                [tool.distutils.sdist]
                formats = "gztar"
                zd
                global-include *.py *.txt
                global-exclude *.py[cod]
                zThis is a ``README``z!---- placeholder MIT license ----Úfooz__version__ = '0.1'z__version__: strz def main(): print('hello world')Ú )ú__init__.pyz__init__.pyizcli.pyzdata.txtzpy.typed)r”   úMANIFEST.inz
README.rstzLICENSE.txtÚsrcr^   zQ'tool.setuptools.license-files' is deprecated in favor of 'project.license-files'z/`project.license` as a TOML table is deprecatedÚignoreÚtempúfoo-0.1.dist-info/METADATAr—   ú&foo-0.1.dist-info/licenses/LICENSE.txtú"foo-0.1.dist-info/entry_points.txtzfoo-0.1/setup.py>   úfoo-0.1úfoo-0.1/srcúfoo-0.1/src/fooúfoo-0.1/PKG-INFOúfoo-0.1/setup.cfgúfoo-0.1/README.rstúfoo-0.1/LICENSE.txtúfoo-0.1/MANIFEST.inúfoo-0.1/pyproject.tomlúfoo-0.1/src/foo/cli.pyúfoo-0.1/src/foo.egg-infoúfoo-0.1/src/foo/data.txtúfoo-0.1/src/foo/py.typedúfoo-0.1/src/foo/__init__.pyúfoo-0.1/src/foo/__init__.pyiú!foo-0.1/src/foo.egg-info/PKG-INFOú$foo-0.1/src/foo.egg-info/SOURCES.txtú%foo-0.1/src/foo.egg-info/not-zip-safeú%foo-0.1/src/foo.egg-info/requires.txtú&foo-0.1/src/foo.egg-info/top_level.txtú)foo-0.1/src/foo.egg-info/entry_points.txtú-foo-0.1/src/foo.egg-info/dependency_links.txt>   ú
foo/cli.pyúfoo/data.txtúfoo/py.typedúfoo/__init__.pyúfoo/__init__.pyiúfoo-0.1.dist-info/WHEELúfoo-0.1.dist-info/RECORDúfoo-0.1.dist-info/top_level.txtr¯   r±   r°   z!Summary: This is a Python packagezLicense: MITzLicense-File: LICENSE.txtz+Classifier: Intended Audience :: DeveloperszRequires-Dist: appdirszRequires-Dist: ztomli>=1 ; extra == "all"z2importlib; python_version=="2.6" and extra =="all"z$[console_scripts]
foo = foo.cli:main)r   rc   rh   r   rf   ÚwarningsÚcatch_warningsÚfilterwarningsr	   Úbuild_sdistr�   Útarfiler›   r,   r‚   r„   Úgetnamesr   r…   rM   Úreadr   Ústriprz   )r   ri   r§   r    rk   ÚmsgsÚmsgÚ
sdist_pathr‰   ÚtarÚsdist_contentsrŠ   r‹   ÚmetadataÚlicenseÚepointsÚliner   r   r   Ú test_build_with_pyproject_config?  sx   ÿ,ÿûÿË?

þ

ü€úÿ
ÿú
ÿù
z5TestBuildMetaBackend.test_build_with_pyproject_configc                 C   sÚ  t dƒt dƒt dƒdœ}|  ¡ }| ¡ � t |¡ | d¡}| d¡}W d   ƒ n1 s.w   Y  |d  ¡ s;J ‚|d  ¡ sCJ ‚|d  ¡ rKJ ‚|d	  ¡ rSJ ‚|d
  ¡ r[J ‚|d  ¡ rcJ ‚|d  ¡ rkJ ‚|d  ¡ rsJ ‚t 	t
j |d|¡¡�}t| d¡ ¡ dƒ}| ¡ }d|vs“J ‚W d   ƒ n1 s�w   Y  tt
j |d|¡ƒ�}	t|	 d¡dƒ}
|	 ¡ }d|vs¿J ‚W d   ƒ n1 sÉw   Y  ||
fD ]}dD ]}||v sÞJ ‚qÖdD ]}||vséJ ‚qáqÒd S )NaR  
                [build-system]
                requires = ["setuptools", "wheel"]
                build-backend = "setuptools.build_meta"

                [project]
                name = "foo"
                description = "This is a Python package"
                version = "42"
                dependencies = ["six"]
                zO
                def run():
                    print('hello')
                z•
                __import__('setuptools').setup(
                    name='bar',
                    version='13',
                )
                )r”   r_   r^   r®   ztemp/foo-42.tar.gzztemp/foo-42-py3-none-any.whlztemp/bar-13.tar.gzztemp/bar-42.tar.gzztemp/foo-13.tar.gzztemp/bar-13-py3-none-any.whlztemp/bar-42-py3-none-any.whlztemp/foo-13-py3-none-any.whlzfoo-42/PKG-INFOr—   zbar-13/PKG-INFOzfoo-42.dist-info/METADATAzbar-13.dist-info/METADATA)z	Name: foozVersion: 42)z	Name: barzVersion: 13)r   rc   rh   r   rf   rÓ   r�   ÚexistsrÔ   r›   r,   r‚   rM   ÚextractfilerÖ   rÕ   r   r…   )r   ri   r    rk   rÚ   r‰   rÛ   Úpkg_infoÚmembersrŠ   rÝ   Úfilerà   r   r   r   Ú(test_static_metadata_in_pyproject_configÑ  sR   ÿÿÿì


ýýýÿýz=TestBuildMetaBackend.test_static_metadata_in_pyproject_configc                 C   s>   t j d¡}t  |¡ | |¡}t j t j ||¡¡sJ ‚d S )Nz	pip-sdist)r,   r   r-   r€   rÓ   rƒ   r‚   ©r   rk   r‡   Ú
sdist_namer   r   r   Útest_build_sdist  s   

z%TestBuildMetaBackend.test_build_sdistc                 C   s@   t j d¡}t  |¡ | |¡}t j t j ||d¡¡sJ ‚d S )Núpip-dist-infoÚMETADATA)r,   r   r-   r€   Ú prepare_metadata_for_build_wheelrƒ   r‚   )r   rk   r‡   Ú	dist_infor   r   r   Ú%test_prepare_metadata_for_build_wheel  s   

 z:TestBuildMetaBackend.test_prepare_metadata_for_build_wheelc                 C   s@   dD ]	}t j|dd� q| d¡}t j t j |d¡¡sJ ‚dS )zy
        Some users might pass metadata_directory pre-populated with `.tox` or `.venv`.
        See issue #3523.
        )z?.tox/python/lib/python3.10/site-packages/attrs-22.1.0.dist-infozD.tox/python/lib/python3.10/site-packages/autocommand-2.2.1.dist-infoz>.nox/python/lib/python3.10/site-packages/build-0.8.0.dist-infoz4.venv/python3.10/site-packages/click-8.1.3.dist-infoz5venv/python3.10/site-packages/distlib-0.3.5.dist-infoz4env/python3.10/site-packages/docutils-0.19.dist-infoT)Úexist_okr   rì   N)r,   r€   rí   r   rƒ   r‚   )r   rk   Úpre_existingrî   r   r   r   Útest_prepare_metadata_inplace  s   
z2TestBuildMetaBackend.test_prepare_metadata_inplacec                 C   s4   t j d¡}| |¡}t j t j ||¡¡sJ ‚d S )NÚdist)r,   r   r-   rÓ   rƒ   r‚   rè   r   r   r   Útest_build_sdist_explicit_dist0  s   
z3TestBuildMetaBackend.test_build_sdist_explicit_distc                 C   s  t j d¡}t  |¡ | |¡}t j t j ||¡¡sJ ‚t j d¡}t j |¡s/t j d¡}t|ddd��}| 	¡ }W d   ƒ n1 sEw   Y  t|ddd��}| 
| dd	¡¡ W d   ƒ n1 sew   Y  t |¡ t  |¡ | d¡}t j t j t j d¡|¡¡sŠJ ‚d S )
NÚ	out_sdistr^   r`   Úrtr—   r˜   r–   zversion='0.0.0'zversion='0.0.1')r,   r   r-   r€   rÓ   rƒ   r‚   râ   r›   rÖ   rœ   ÚreplaceÚshutilÚrmtree)r   rk   Úsdist_into_directoryré   Ú	setup_locÚfile_handlerÚcontentr   r   r   Útest_build_sdist_version_change7  s"   


ÿÿ


&z4TestBuildMetaBackend.test_build_sdist_version_changec                 C   s„   t dƒdt dƒdœ}t |¡ |  ¡ }| d¡}t tj d|¡¡�}t	dd„ | 
¡ D ƒƒs0J ‚W d   ƒ d S 1 s;w   Y  d S )Nú°
                __import__('setuptools').setup(
                    name='foo',
                    version='0.0.0',
                    py_modules=['hello']
                )r©   r’   )r^   r_   r”   r®   c                 s   ó   � | ]}d |v V  qdS )r”   Nr   ©r|   r)   r   r   r   r~   g  ó   € zNTestBuildMetaBackend.test_build_sdist_pyproject_toml_exists.<locals>.<genexpr>©r   r   rf   rc   rÓ   rÔ   r›   r,   r‚   ÚanyrÕ   ©r   rŸ   r    rk   Ú
targz_pathrÛ   r   r   r   Ú&test_build_sdist_pyproject_toml_existsP  s   ÿÿö

"ÿz;TestBuildMetaBackend.test_build_sdist_pyproject_toml_existsc                 C   st   t  td ¡ |  ¡ }| d¡}t tj  d|¡¡�}t	dd„ | 
¡ D ƒƒs(J ‚W d   ƒ d S 1 s3w   Y  d S )Nr   r®   c                 s   r   ©r^   Nr   r  r   r   r   r~   q  r  zHTestBuildMetaBackend.test_build_sdist_setup_py_exists.<locals>.<genexpr>)r   rf   Údefnsrc   rÓ   rÔ   r›   r,   r‚   r  rÕ   )r   rŸ   rk   r  rÛ   r   r   r   Ú test_build_sdist_setup_py_existsi  s   
"ÿz5TestBuildMetaBackend.test_build_sdist_setup_py_existsc                 C   s„   t dƒdt dƒdœ}t |¡ |  ¡ }| d¡}t tj d|¡¡�}t	dd„ | 
¡ D ƒƒr0J ‚W d   ƒ d S 1 s;w   Y  d S )Nzˆ
        __import__('setuptools').setup(
            name='foo',
            version='0.0.0',
            py_modules=['hello']
        )r©   z"
        exclude setup.py
        )r^   r_   r«   r®   c                 s   r   r  r   r  r   r   r   r~   ‹  r  zSTestBuildMetaBackend.test_build_sdist_setup_py_manifest_excluded.<locals>.<genexpr>r  r  r   r   r   Ú+test_build_sdist_setup_py_manifest_excludeds  s   ÿÿö

"ÿz@TestBuildMetaBackend.test_build_sdist_setup_py_manifest_excludedc                 C   s4   t dƒdt dƒdœ}t |¡ |  ¡ }| d¡ d S )Nrÿ   r©   zE
                [sdist]
                formats=zip
                ©r^   r_   r`   r®   )r   r   rf   rc   rÓ   )r   rŸ   r    rk   r   r   r   Ú3test_build_sdist_builds_targz_even_if_zip_indicated�  s   ÿÿö
zHTestBuildMetaBackend.test_build_sdist_builds_targz_even_if_zip_indicatedz´
            __import__('setuptools').setup(
                name='foo',
                version=__import__('hello').__version__,
                py_modules=['hello']
            )z__version__ = "0.0.0"z9
            [sdist]
            formats=zip
            r  c                 C   sR   t  | j¡ |  ¡ }tjtdd�� | d¡ W d   ƒ d S 1 s"w   Y  d S )Nz^No module named 'hello'$©Úmatchr®   )r   rf   Ú_relative_path_import_filesrc   r6   ÚraisesÚImportErrorrÓ   ©r   rŸ   rk   r   r   r   Ú%test_build_sdist_relative_path_import·  s
   "ÿz:TestBuildMetaBackend.test_build_sdist_relative_path_importzX
            [project]
            name = "proj"
            version = "42"
            Úprojrª   r©   )r”   r¬   c                 C   sD   t t|ƒ d¡ƒ}|sJ ‚|D ]}| ¡ st |¡jdksJ ‚qdS )z?All files in the directory should be either links or hard linksz**/*r   N)Úlistr   ÚglobÚ
is_symlinkr,   ÚstatÚst_nlink)r   Ú
parent_dirr    ræ   r   r   r   Ú_assert_link_treeÈ  s   €ÿz&TestBuildMetaBackend._assert_link_treec                 C   sB   t  | j¡ |  ¡ }tdƒ ¡ rJ ‚| d¡ tdƒ ¡ rJ ‚dS )zù
        Sanity check to ensure tests with --mode=strict are different from the ones
        without --mode.

        --mode=strict should create a local directory with a package tree.
        The directory should not get created otherwise.
        rf   r®   N)r   rf   Ú_simple_pyproject_examplerc   r   râ   Úbuild_editabler  r   r   r   Ú%test_editable_without_config_settingsÏ  s
   
z:TestBuildMetaBackend.test_editable_without_config_settingsc                 C   sh   dddgi}t  | j¡ |  ¡ }tdƒ ¡ rJ ‚tdƒ ¡  | d|¡ | d|¡ tdƒ ¡ s2J ‚d S )Nz--build-optionÚ	build_extz	--inplacerf   zbuild/proj-42-py3-none-any.whl)	r   rf   r  rc   r   râ   Úmkdirrí   r�   ©r   rŸ   Úconfig_settingsrk   r   r   r   Útest_build_wheel_inplaceÝ  s   z-TestBuildMetaBackend.test_build_wheel_inplacer#  zeditable-modeÚstrictc                 C   sf   t  i | j¥di i¥¡ tdƒ ¡ rJ ‚|  ¡ }| d|¡ | d|d¡ |  t	tdƒ 
d¡ƒ¡ d S )NÚ_metarf   r®   z__editable__.*)r   rf   r  r   râ   rc   Ú#prepare_metadata_for_build_editabler  r  Únextr  r"  r   r   r   Ú"test_editable_with_config_settingsç  s   z7TestBuildMetaBackend.test_editable_with_config_settings)Úsetup_literalÚrequirementsz'foo'r¨   z['foo']z'foo\n'z	'foo\n\n'z['foo', 'bar']Úbarz'# Has a comment line\nfoo'z'foo # Has an inline comment'z'foo \\\n >=3.0'zfoo>=3.0z
'foo\nbar'z'foo\nbar\n'z['foo\n', 'bar\n']Ú	use_wheelTFc           
      C   s`   t dƒj|d�t dƒdœ}t |¡ |  ¡ }|r|j}n|j}t|ƒ}|ƒ }	|t|	ƒks.J ‚d S )Na  
                from setuptools import setup

                setup(
                    name="qux",
                    version="0.0.0",
                    py_modules=["hello"],
                    setup_requires={setup_literal},
                )
            )r*  r\   r]   )r   Úformatr   rf   rc   ro   rv   rp   )
r   r*  r+  r-  rŸ   r    rk   Úget_requiresrs   rr   r   r   r   Útest_setup_requiresð  s"   ÿõÿó
z(TestBuildMetaBackend.test_setup_requiresc                 C   sB   t dƒt dƒdddœ}t |¡ |  ¡ }| ¡ }|dgksJ ‚d S )Nzd
                [project]
                name = "proj"
                version = "42"
            z¯
                __import__('setuptools').setup(
                    setup_requires=["foo"],
                    py_modules = ["hello", "world"]
                )
            z'hello'z'world')r”   r^   r_   rx   r¨   )r   r   rf   rc   ro   )r   rŸ   r    rk   Úsetup_requiresr   r   r   Ú'test_setup_requires_with_auto_discovery&  s   ÿÿï
z<TestBuildMetaBackend.test_setup_requires_with_auto_discoveryc                 C   sH   t dƒt dƒdœ}t |¡ |  ¡ }tj d¡}t |¡ | |¡ d S )NaN  
                        from setuptools import setup

                        setup(
                            name="qux",
                            version="0.0.0",
                            py_modules=["hello"],
                            setup_requires=["does-not-exist >99"],
                        )
                    z[
                    def run():
                        print('hello')
                    r]   rë   )r   r   rf   rc   r,   r-   r€   rí   )r   rŸ   r    rk   r‡   r   r   r   Ú test_dont_install_setup_requiresB  s   ÿÿó

z5TestBuildMetaBackend.test_dont_install_setup_requiresr^   aD  
            import os
            import sys

            __import__('setuptools').setup(
                name='foo',
                version='0.0.0',
            )

            sys_argv = os.path.abspath(sys.argv[0])
            file_path = os.path.abspath('setup.py')
            assert sys_argv == file_path
            c                 C   sN   t  | j¡ |  ¡ }t t¡� | d¡ W d   ƒ d S 1 s w   Y  d S ©Nr®   )r   rf   Ú_sys_argv_0_passthroughrc   r6   r  ÚAssertionErrorrÓ   r  r   r   r   Útest_sys_argv_passthroughu  s
   "ÿz.TestBuildMetaBackend.test_sys_argv_passthrougha  
            import os
            assert os.path.isabs(__file__)
            __import__('setuptools').setup(
                name='foo',
                version='0.0.0',
                py_modules=['hello'],
                setup_requires=['six'],
            )
            c                 C   ó"   t  | j¡ |  ¡ }| d¡ d S r4  )r   rf   Ú_setup_py_file_abspathrc   rÓ   r  r   r   r   Útest_setup_py_file_abspathŠ  s   z/TestBuildMetaBackend.test_setup_py_file_abspathÚ
build_hook)rÓ   r�   c                 C   s^   ddi}t  |¡ t d¡}tjt|d�� t||ƒdƒ W d   ƒ d S 1 s(w   Y  d S )Nr^   r©   zNo distribution was found.r  r®   )r   rf   ÚreÚescaper6   r  Ú
ValueErrorrX   )r   rk   r;  r    rÙ   r   r   r   Útest_build_with_empty_setuppy�  s   

"ÿz2TestBuildMetaBackend.test_build_with_empty_setuppy)+r   r   r   r   rc   r6   Úfixturer	  rk   rt   rw   rŽ   ÚmarkÚparametrizer¦   ÚSETUP_SCRIPT_STUBrá   rç   rê   rï   rò   rô   rþ   r  r
  r  r  r   r  r  r  r  r  r$  r)  r0  r2  r3  r5  r7  r9  r:  r?  r   r   r   r   ra   â   s’    


2
 ?
ÿÿöÿ
ø





õþ%"ÿÿÿÿra   c                   @   s    e Zd ZdZdd„ Zdd„ ZdS )ÚTestBuildMetaLegacyBackendz setuptools.build_meta:__legacy__c                 C   r8  r4  )r   rf   r  rc   rÓ   r  r   r   r   r  �  s   z@TestBuildMetaLegacyBackend.test_build_sdist_relative_path_importc                 C   r8  r4  )r   rf   r5  rc   rÓ   r  r   r   r   r7  ¤  s   z4TestBuildMetaLegacyBackend.test_sys_argv_passthroughN)r   r   r   r   r  r7  r   r   r   r   rD  ™  s    rD  z/ignore::setuptools.SetuptoolsDeprecationWarningc                 C   sB   |   |¡ d}|d jt|ƒdd� tdd�}| ¡ g ksJ ‚dS )zHSetuptools should be resilient to setup.py with ``sys.exit(0)`` (#3973).zr
        import sys, setuptools
        setuptools.setup(name='foo', version='0.0.0')
        sys.exit(0)
        r^   r—   r˜   r   rb   N)rS   Ú
write_textr   r    ro   ©ÚmonkeypatchÚtmp_pathÚsetuppyrZ   r   r   r   Útest_sys_exit_0_in_setuppy«  s
   

rJ  c                 C   sf   |   |¡ d}|d j|dd� tjtdd�� tdd�}| ¡  W d   ƒ d S 1 s,w   Y  d S )	Nz"import sys; sys.exit('some error')r^   r—   r˜   z
some errorr  r   rb   )rS   rE  r6   r  Ú
SystemExitr    ro   rF  r   r   r   Útest_system_exit_in_setuppy¹  s   


"þrL  ).rE   rV   r,   r<  rø   rI   ÚsysrÔ   rÐ   Ú
concurrentr   Úpathlibr   Útypingr   r   rŠ   r   r6   Újaracor   Úpackaging.requirementsr   Úsetuptools.warningsr	   Útextwrapr   rC  ÚintÚgetenvr2   Úbuiltin_module_namesr<   rA  ÚskipifÚplatformÚ
pytestmarkr   r    r.   r	  ra   rD  rÒ   rJ  rL  r   r   r   r   Ú<module>   sž    
þ#ÿ
ÿõÿÿôÿÿñÿÿÿÿôÿÿó˜     <

