U
    ui"                  	   @   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oe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   D/tmp/pip-unpacked-wheel-9osl9suo/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rt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st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
||st||	kstttj
||	d  ||}
|
|	ksttjtj
||
dkst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st||fq| dst| d8kst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  rt|d	  rt|d
  rt|d  rt|d  rt|d  rt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st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|st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_locZ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 )NZ_metar]   r   z__editable__.*)r   r]   r   r   r   rg   rZ   Z#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st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

