U
    aÊ¹j"ƒ  ã                	   @   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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
Zee dd¡ƒZdejkZejjej dkoÐe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'd&d'„ Z(ej )d(¡d)d*„ ƒZ*d+d,„ Z+dS )-é    N)Úfutures)ÚPath)ÚAnyÚCallable)ÚZipFile)Úpath)ÚRequirementé   )ÚDALSz __import__('setuptools').setup()ZTIMEOUT_BACKEND_TESTZ180Z__pypy__Úwin32z_The combination of PyPy + Windows + pytest-xdist + ProcessPoolExecutor is flaky and problematic)Úreasonc                   @   s   e Zd Zddd„ZdS )ÚBuildBackendBaseÚ.Núsetuptools.build_metac                 C   s   || _ |pi | _|| _d S )N)ÚcwdÚenvÚbackend_name)Úselfr   r   r   © r   ú_/var/www/html/bwave/python/venv/lib/python3.8/site-packages/setuptools/tests/test_build_meta.pyÚ__init__#   s    
zBuildBackendBase.__init__)r   Nr   )Ú__name__Ú
__module__Ú__qualname__r   r   r   r   r   r   "   s   r   c                       s@   e Zd ZdZ‡ fdd„Zeedef dœdd„Zdd	„ Z	‡  Z
S )
ÚBuildBackendzPEP 517 Build Backendc                    s    t ƒ j||Ž 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Úreturnc                    s   ‡ ‡fdd„}|S )ú<Handles arbitrary function invocations on the build backend.c               
      sÆ   t j ˆj¡}t|ˆjˆjƒ}d }z2ˆj t j	¡ 
t¡}ˆjj|ˆ f| ž|Ž 
t¡W S  tjk
r”   ˆjjdd� ˆ |¡ t dt› d�¡ Y n. tjjttfk
rÀ   trºt d¡ ‚ Y nX d S )NF)Úwaitz(Backend did not respond before timeout (z s)z3PyPy frequently fails tests with ProcessPoolExector)Úosr   Úabspathr   ÚBuildBackendCallerr   r   r   ZsubmitÚgetpidÚresultÚTIMEOUTr   ÚTimeoutErrorÚshutdownÚ_killÚpytestZxfailÚprocessZBrokenProcessPoolÚMemoryErrorÚOSErrorÚIS_PYPY)r   ÚkwÚrootZcallerÚpid©r#   r   r   r   Úmethod3   s    

z(BuildBackend.__getattr__.<locals>.methodr   )r   r#   r9   r   r8   r   Ú__getattr__0   s    zBuildBackend.__getattr__c              	   C   sF   |d krd S t  tt¡�$ t |tjdkr0tjntj	¡ W 5 Q R X d S )NÚnt)
Ú
contextlibÚsuppressÚProcessLookupErrorr3   r'   Úkillr#   ÚsignalÚSIGTERMÚSIGKILL)r   r7   r   r   r   r/   E   s    zBuildBackend._kill)r   r   r   Ú__doc__r   Ústrr   r   r:   r/   Ú__classcell__r   r   r!   r   r   )   s   r   c                       s$   e Zd Z‡ fdd„Zdd„ Z‡  ZS )r)   c                    s(   t ƒ j||Ž | j d¡\| _}| _d S )Nú:)r   r   r   Ú	partitionÚbackend_obj)r   r   r    Ú_r!   r   r   r   M   s    zBuildBackendCaller.__init__c                 O   sN   t  | j¡ t j | j¡ t | j¡}| j	r:t
|| j	ƒ}n|}t
||ƒ||ŽS )r%   )r'   Úchdirr   ÚenvironÚupdater   Ú	importlibÚimport_moduler   rH   Úgetattr)r   r#   r   r5   ÚmodÚbackendr   r   r   Ú__call__R   s    zBuildBackendCaller.__call__)r   r   r   r   rR   rE   r   r   r!   r   r)   L   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'],
            )
            rU   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.cfgrV   )rW   rU   rV   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   s6   t j|jt|ƒd� | ¡ � |  ¡ V  W 5 Q R X d S )N)Úprefix)r   ÚbuildÚparamrD   Úas_cwdrZ   )r   ÚtmpdirÚrequestr   r   r   Úbuild_backendå   s    
z"TestBuildMetaBackend.build_backendc                 C   s&   |  ¡ }dg}t|ƒt|ƒks"t‚d S ©NÚsix)Úget_requires_for_build_wheelÚsortedÚAssertionError©r   rb   ÚactualÚexpectedr   r   r   Ú!test_get_requires_for_build_wheelë   s    z6TestBuildMetaBackend.test_get_requires_for_build_wheelc                 C   s&   |  ¡ }dg}t|ƒt|ƒks"t‚d S rc   )Úget_requires_for_build_sdistrf   rg   rh   r   r   r   Ú!test_get_requires_for_build_sdistð   s    z6TestBuildMetaBackend.test_get_requires_for_build_sdistc           	   	   C   sž   t j d¡}t  |¡ | |¡}t j ||¡}t j |¡s>t‚t j d¡rNt‚t|ƒ�}t	| 
¡ ƒ}W 5 Q R X dd„ |D ƒ}dd„ |D ƒ}t|ƒdksšt‚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 )rU   ro   rq   r   r   r   Ú
<listcomp>  s     
 z9TestBuildMetaBackend.test_build_wheel.<locals>.<listcomp>r	   )r'   r   r(   ÚmakedirsÚbuild_wheelÚjoinÚisfilerg   r   ÚsetÚnamelistÚlen)	r   rb   Údist_dirÚ
wheel_nameÚ
wheel_fileÚzipfileÚwheel_contentsZ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 5 Q R X ||ƒ}	tj 	tj 
||¡¡s”t‚||	ks t‚ttj 
||	¡dƒ ¡  ||ƒ}
|
|	ksÌt‚tj tj 
||
¡¡dksêt‚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"
                )rU   ÚVERSIONrW   úpyproject.tomlzpreexisting-Zbuild_rˆ   Úwtúutf-8©Úencodingz0.0.2Úwbr   )r
   r   r]   r'   r(   rZ   rO   ÚopenÚwritery   rx   rg   ÚcloseÚgetsize)r   r„   Ú
tmpdir_cwdÚfilesr}   rb   Zbuild_methodZfirst_resultZversion_fileZsecond_resultZthird_resultr   r   r   Ú%test_build_with_existing_file_present	  s.    ÿÿö
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œ}|r4||d< |  ¡ }| ¡ �$ t |¡ | d¡}| d¡}W 5 Q R X t t	j 
|d|¡¡�}t| ¡ ƒ}W 5 Q R X tt	j 
|d|¡ƒ�B}	t|	 ¡ ƒ}
t|	 d¡dƒ}t|	 d¡dƒ}t|	 d¡dƒ}W 5 Q R X |dh dddddddddddddd d!d"d#d$d%d&d'd(hk�s8t‚|
d)d*d+d,d-ddd.dd/d0hk�s\t‚|dk�sjt‚d1d2d3d4d5ttd6ƒƒ d5ttd7ƒƒ fD ]}||k�s’t||fƒ‚�q’| ¡  d¡�sÄt‚| ¡ d8k�sÖt‚d S )9Naj  
                [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ÚsrcrU   Útempzfoo-0.1.dist-info/METADATAr‹   zfoo-0.1.dist-info/LICENSE.txtz"foo-0.1.dist-info/entry_points.txtzfoo-0.1/setup.pyzfoo-0.1zfoo-0.1/LICENSE.txtzfoo-0.1/MANIFEST.inzfoo-0.1/PKG-INFOzfoo-0.1/README.rstzfoo-0.1/pyproject.tomlzfoo-0.1/setup.cfgzfoo-0.1/srczfoo-0.1/src/foozfoo-0.1/src/foo/__init__.pyzfoo-0.1/src/foo/__init__.pyizfoo-0.1/src/foo/cli.pyzfoo-0.1/src/foo/data.txtzfoo-0.1/src/foo/py.typedzfoo-0.1/src/foo.egg-infoz!foo-0.1/src/foo.egg-info/PKG-INFOz$foo-0.1/src/foo.egg-info/SOURCES.txtz-foo-0.1/src/foo.egg-info/dependency_links.txtz)foo-0.1/src/foo.egg-info/entry_points.txtz%foo-0.1/src/foo.egg-info/requires.txtz&foo-0.1/src/foo.egg-info/top_level.txtz%foo-0.1/src/foo.egg-info/not-zip-safezfoo/__init__.pyzfoo/__init__.pyiz
foo/cli.pyzfoo/data.txtzfoo/py.typedzfoo-0.1.dist-info/WHEELzfoo-0.1.dist-info/top_level.txtzfoo-0.1.dist-info/RECORDz!Summary: This is a Python packagezLicense: MITz+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
   rZ   r_   r   r]   Úbuild_sdistrw   Útarfiler�   r'   rx   rz   Úgetnamesr   r{   rD   Úreadrg   r   Ústriprp   )r   r`   r–   r”   rb   Ú
sdist_pathr   ÚtarZsdist_contentsr€   r�   ÚmetadataÚlicenseZepointsÚliner   r   r   Ú test_build_with_pyproject_config<  s¢    ÿ,ÿûÿË?


êõ
ÿú	z5TestBuildMetaBackend.test_build_with_pyproject_configc              	   C   s¬  t dƒt dƒt dƒdœ}|  ¡ }| ¡ �$ t |¡ | d¡}| d¡}W 5 Q R X |d  ¡ sbt‚|d  ¡ srt‚|d  ¡ r‚t‚|d	  ¡ r’t‚|d
  ¡ r¢t‚|d  ¡ r²t‚|d  ¡ rÂt‚|d  ¡ rÒt‚t	 
tj |d|¡¡�0}t| d¡ ¡ dƒ}| ¡ }d|k�st‚W 5 Q R X ttj |d|¡ƒ�,}	t|	 d¡dƒ}
|	 ¡ }d|k�sZt‚W 5 Q R X ||
fD ]:}dD ]}||k�stt‚�qtdD ]}||k�sŽt‚�qŽ�qld 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‰   rV   rU   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
   rZ   r_   r   r]   r�   rw   Úexistsrg   rž   r�   r'   rx   rD   Úextractfiler    rŸ   r   r{   )r   r`   r”   rb   r¢   r   r£   Úpkg_infoÚmembersr€   r¤   Úfiler¦   r   r   r   Ú(test_static_metadata_in_pyproject_configÄ  sH    ÿÿÿì


z=TestBuildMetaBackend.test_static_metadata_in_pyproject_configc                 C   s>   t j d¡}t  |¡ | |¡}t j t j ||¡¡s:t‚d S )Nz	pip-sdist)r'   r   r(   rv   r�   ry   rx   rg   ©r   rb   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<t‚d S )Núpip-dist-infoÚMETADATA)r'   r   r(   rv   Ú prepare_metadata_for_build_wheelry   rx   rg   )r   rb   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<t‚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'   rv   r³   r   ry   rx   rg   )r   rb   Zpre_existingr´   r   r   r   Útest_prepare_metadata_inplace  s    
z2TestBuildMetaBackend.test_prepare_metadata_inplacec                 C   s4   t j d¡}| |¡}t j t j ||¡¡s0t‚d S )NÚdist)r'   r   r(   r�   ry   rx   rg   r®   r   r   r   Útest_build_sdist_explicit_dist#  s    
z3TestBuildMetaBackend.test_build_sdist_explicit_distc              	   C   sð   t j d¡}t  |¡ | |¡}t j t j ||¡¡s:t‚t j d¡}t j |¡s^t j d¡}t	|ddd��}| 
¡ }W 5 Q R X t	|ddd��}| | dd	¡¡ W 5 Q R X t |¡ t  |¡ | d¡}t j t j t j d¡|¡¡sìt‚d S )
NZ	out_sdistrU   rW   Úrtr‹   rŒ   rŠ   zversion='0.0.0'zversion='0.0.1')r'   r   r(   rv   r�   ry   rx   rg   r¨   r�   r    r�   ÚreplaceÚshutilÚrmtree)r   rb   Zsdist_into_directoryr¯   Z	setup_locÚfile_handlerÚcontentr   r   r   Útest_build_sdist_version_change*  s    




z4TestBuildMetaBackend.test_build_sdist_version_changec              	   C   sn   t dƒdt dƒdœ}t |¡ |  ¡ }| d¡}t tj d|¡¡� }t	dd„ | 
¡ D ƒƒs`t‚W 5 Q R X d S )Nú°
                __import__('setuptools').setup(
                    name='foo',
                    version='0.0.0',
                    py_modules=['hello']
                )r˜   r‡   )rU   rV   r‰   rœ   c                 s   s   | ]}d |kV  qdS )r‰   Nr   ©rr   r#   r   r   r   rt   Z  s     zNTestBuildMetaBackend.test_build_sdist_pyproject_toml_exists.<locals>.<genexpr>©r
   r   r]   rZ   r�   rž   r�   r'   rx   ÚanyrŸ   rg   ©r   r“   r”   rb   Ú
targz_pathr£   r   r   r   Ú&test_build_sdist_pyproject_toml_existsC  s    ÿÿö

z;TestBuildMetaBackend.test_build_sdist_pyproject_toml_existsc              	   C   s^   t  td ¡ |  ¡ }| d¡}t tj  d|¡¡� }t	dd„ | 
¡ D ƒƒsPt‚W 5 Q R X d S )Nr   rœ   c                 s   s   | ]}d |kV  qdS ©rU   Nr   rÂ   r   r   r   rt   d  s     zHTestBuildMetaBackend.test_build_sdist_setup_py_exists.<locals>.<genexpr>)r   r]   ÚdefnsrZ   r�   rž   r�   r'   rx   rÄ   rŸ   rg   )r   r“   rb   rÆ   r£   r   r   r   Ú test_build_sdist_setup_py_exists\  s
    
z5TestBuildMetaBackend.test_build_sdist_setup_py_existsc              	   C   sn   t dƒdt dƒdœ}t |¡ |  ¡ }| d¡}t tj d|¡¡� }t	dd„ | 
¡ D ƒƒr`t‚W 5 Q R X d S )Nzˆ
        __import__('setuptools').setup(
            name='foo',
            version='0.0.0',
            py_modules=['hello']
        )r˜   z"
        exclude setup.py
        )rU   rV   rš   rœ   c                 s   s   | ]}d |kV  qdS rÈ   r   rÂ   r   r   r   rt   ~  s     zSTestBuildMetaBackend.test_build_sdist_setup_py_manifest_excluded.<locals>.<genexpr>rÃ   rÅ   r   r   r   Ú+test_build_sdist_setup_py_manifest_excludedf  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
                ©rU   rV   rW   rœ   )r
   r   r]   rZ   r�   )r   r“   r”   rb   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   s<   t  | j¡ |  ¡ }tjtdd�� | d¡ W 5 Q R X d S )Nz^No module named 'hello'$©Úmatchrœ   )r   r]   Ú_relative_path_import_filesrZ   r0   ÚraisesÚImportErrorr�   ©r   r“   rb   r   r   r   Ú%test_build_sdist_relative_path_importª  s    z:TestBuildMetaBackend.test_build_sdist_relative_path_importzX
            [project]
            name = "proj"
            version = "42"
            Zprojr™   r˜   )r‰   r›   c                 C   sD   t t|ƒ d¡ƒ}|st‚|D ] }| ¡ st |¡jdkst‚qdS )z?All files in the directory should be either links or hard linksz**/*r   N)Úlistr   Úglobrg   Ú
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$t‚| d¡ tdƒ ¡ r>t‚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.
        r]   rœ   N)r   r]   Ú_simple_pyproject_examplerZ   r   r¨   rg   Ú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ƒ ¡ r0t‚tdƒ ¡  | d|¡ | 	d|¡ tdƒ ¡ sdt‚d S )Nz--build-optionÚ	build_extz	--inplacer]   zbuild/proj-42-py3-none-any.whl)
r   r]   rÜ   rZ   r   r¨   rg   Úmkdirr³   rw   ©r   r“   Úconfig_settingsrb   r   r   r   Útest_build_wheel_inplaceÐ  s    z-TestBuildMetaBackend.test_build_wheel_inplacerâ   zeditable-modeÚstrictc                 C   sb   t  | jdi i–¡ tdƒ ¡ r$t‚|  ¡ }| d|¡ | d|d¡ |  	t
tdƒ d¡ƒ¡ d S )NÚ_metar]   rœ   z__editable__.*)r   r]   rÜ   r   r¨   rg   rZ   Ú#prepare_metadata_for_build_editablerÝ   rÛ   ÚnextrÖ   rá   r   r   r   Ú"test_editable_with_config_settingsÚ  s    z7TestBuildMetaBackend.test_editable_with_config_settingsz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 |¡ |  ¡ }|r8|j}n|j}t|ƒ}|ƒ }	|t|	ƒks\t‚d S )Na  
                from setuptools import setup

                setup(
                    name="qux",
                    version="0.0.0",
                    py_modules=["hello"],
                    setup_requires={setup_literal},
                )
            )Úsetup_literalrS   rT   )	r
   Úformatr   r]   rZ   re   rl   rf   rg   )
r   rë   Úrequirementsrê   r“   r”   rb   Úget_requiresrj   ri   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>t‚d S )Nzd
                [project]
                name = "proj"
                version = "42"
            z¯
                __import__('setuptools').setup(
                    setup_requires=["foo"],
                    py_modules = ["hello", "world"]
                )
            z'hello'z'world')r‰   rU   rV   rn   r—   )r
   r   r]   rZ   re   rg   )r   r“   r”   rb   Z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')
                    rT   r±   )r
   r   r]   rZ   r'   r(   rv   r³   )r   r“   r”   rb   r}   r   r   r   Ú test_dont_install_setup_requires5  s    ÿÿó

z5TestBuildMetaBackend.test_dont_install_setup_requiresrU   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   s8   t  | j¡ |  ¡ }t t¡� | d¡ W 5 Q R X d S ©Nrœ   )r   r]   Ú_sys_argv_0_passthroughrZ   r0   rÑ   rg   r�   rÓ   r   r   r   Útest_sys_argv_passthroughh  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   s"   t  | j¡ |  ¡ }| d¡ d S rò   )r   r]   Ú_setup_py_file_abspathrZ   r�   rÓ   r   r   r   Útest_setup_py_file_abspath}  s    z/TestBuildMetaBackend.test_setup_py_file_abspathÚ
build_hook)r�   rw   c              	   C   sH   ddi}t  |¡ t d¡}tjt|d�� t||ƒdƒ W 5 Q R X d S )NrU   r˜   zNo distribution was found.rÎ   rœ   )r   r]   ÚreÚescaper0   rÑ   Ú
ValueErrorrO   )r   rb   r÷   r”   Úmsgr   r   r   Útest_build_with_empty_setuppy‚  s
    

z2TestBuildMetaBackend.test_build_with_empty_setuppy)+r   r   r   r   rZ   r0   ZfixturerÉ   rb   rk   rm   rƒ   ÚmarkZparametrizer•   ÚSETUP_SCRIPT_STUBr§   r­   r°   rµ   r·   r¹   rÀ   rÇ   rÊ   rË   rÍ   r
   rÐ   rÔ   rÜ   rÛ   rÞ   rã   rè   rï   rð   rñ   ró   rô   rõ   rö   rü   r   r   r   r   rX   ß   s”   


2
 ?
ÿÿöÿ
ø





õþ%" ÿÿ ÿÿrX   c                   @   s    e Zd ZdZdd„ Zdd„ ZdS )ÚTestBuildMetaLegacyBackendz setuptools.build_meta:__legacy__c                 C   s"   t  | j¡ |  ¡ }| d¡ d S rò   )r   r]   rÐ   rZ   r�   rÓ   r   r   r   rÔ   �  s    z@TestBuildMetaLegacyBackend.test_build_sdist_relative_path_importc                 C   s"   t  | j¡ |  ¡ }| d¡ d S rò   )r   r]   ró   rZ   r�   rÓ   r   r   r   rô   —  s    z4TestBuildMetaLegacyBackend.test_sys_argv_passthroughN)r   r   r   r   rÔ   rô   r   r   r   r   rÿ   Œ  s   rÿ   c                 C   s�   d}t  t|ƒddœ¡ dddddg}| j||d	� ¡ }d
|ksDt‚d|ksPt‚tjddi–}dddddg}| j|||d� ¡ }d
|ksŒt‚d S )Nz—
    [build-system]
    requires = ["setuptools"]
    build-backend = "setuptools.build_meta"
    [project]
    name = "myproj"
    version = "42"
    r˜   )r‰   zmymod.pyÚpipÚinstallz--no-build-isolationz-er   )r   z#running setup.py develop for myprojzcreated wheel for myprojZSETUPTOOLS_ENABLE_FEATURESzlegacy-editable)r   r   )r   r]   r
   ÚrunÚlowerrg   r'   rK   )Úvenvr`   r“   Ú	pyprojectÚcmdÚoutputr   r   r   r   Útest_legacy_editable_installž  s    r  z/ignore::setuptools.SetuptoolsDeprecationWarningc                 C   sB   |   |¡ d}|d jt|ƒdd� tdd�}| ¡ g ks>t‚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)
        rU   r‹   rŒ   r   rY   N)rJ   Ú
write_textr
   r   re   rg   ©ZmonkeypatchZtmp_pathZsetuppyrQ   r   r   r   Útest_sys_exit_0_in_setuppy¶  s
    

r  c              	   C   sP   |   |¡ d}|d j|dd� tjtdd�� tdd�}| ¡  W 5 Q R X d S )	Nz"import sys; sys.exit('some error')rU   r‹   rŒ   z
some errorrÎ   r   rY   )rJ   r	  r0   rÑ   Ú
SystemExitr   re   r
  r   r   r   Útest_system_exit_in_setuppyÄ  s    

r  ),r<   rM   r'   rø   r¼   r@   Úsysrž   Z
concurrentr   Úpathlibr   Útypingr   r   r€   r   r0   Zjaracor   Zpackaging.requirementsr   Útextwrapr
   rþ   ÚintÚgetenvr,   Úbuiltin_module_namesr4   rý   ZskipifÚplatformZ
pytestmarkr   r   r)   rÉ   rX   rÿ   r  Úfilterwarningsr  r  r   r   r   r   Ú<module>   sœ   
þ#ÿ
ÿõÿÿôÿÿñ ÿÿÿÿôÿÿó˜     2

