o
    Zh&                  	   @   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v Zejjej dkohe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   W/var/www/html/lang_env/lib/python3.10/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                       sB   e Zd ZdZ fddZdededef fddZd	d
 Z	  Z
S )BuildBackendzPEP 517 Build Backendc                    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return.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   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   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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|i | | 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   sR   t | j t j| j t| j}| j	rt
|| j	}n|}t
|||i |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   sN    t j|jt|d |  |  V  W d    d S 1 s w   Y  d S )N)prefix)r   buildparamrD   as_cwdrZ   )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   rb   actualexpectedr   r   r   !test_get_requires_for_build_wheel      z6TestBuildMetaBackend.test_get_requires_for_build_wheelc                 C   rc   rd   )get_requires_for_build_sdistrg   rh   r   r   r   !test_get_requires_for_build_sdist   rl   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 )rU   rp   rr   r   r   r   
<listcomp>  s    z9TestBuildMetaBackend.test_build_wheel.<locals>.<listcomp>r	   )r'   r   r(   makedirsbuild_wheeljoinisfiler   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 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"
                )rU   VERSIONrW   pyproject.tomlzpreexisting-Zbuild_r   wtutf-8encodingz0.0.2wbr   )r
   r   r]   r'   r(   rZ   rO   openwriterz   ry   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	  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}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 sw   Y  |dh h dksJ |
h dksJ |dksJ dddddttd dttd fD ]}||v sJ ||fq| dsJ | dksJ 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srcrU   tempfoo-0.1.dist-info/METADATAr   foo-0.1.dist-info/LICENSE.txt"foo-0.1.dist-info/entry_points.txtzfoo-0.1/setup.py>   zfoo-0.1/src/foo/__init__.pyizfoo-0.1/MANIFEST.inzfoo-0.1/PKG-INFOzfoo-0.1/LICENSE.txtzfoo-0.1zfoo-0.1/src/foo.egg-infozfoo-0.1/src/foo/data.txtz%foo-0.1/src/foo.egg-info/requires.txtz!foo-0.1/src/foo.egg-info/PKG-INFOz-foo-0.1/src/foo.egg-info/dependency_links.txtzfoo-0.1/setup.cfgz%foo-0.1/src/foo.egg-info/not-zip-safezfoo-0.1/src/fooz$foo-0.1/src/foo.egg-info/SOURCES.txtzfoo-0.1/src/foo/cli.pyzfoo-0.1/pyproject.tomlzfoo-0.1/README.rstzfoo-0.1/srczfoo-0.1/src/foo/py.typedzfoo-0.1/src/foo/__init__.pyz&foo-0.1/src/foo.egg-info/top_level.txtz)foo-0.1/src/foo.egg-info/entry_points.txt>   r   zfoo/data.txtr   r   z
foo/cli.pyzfoo-0.1.dist-info/top_level.txtzfoo-0.1.dist-info/RECORDzfoo/__init__.pyizfoo-0.1.dist-info/WHEELzfoo/__init__.pyzfoo/py.typedz!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_sdistrx   tarfiler   r'   ry   r{   getnamesr   r|   rD   readr   striprq   )r   r`   r   r   rb   
sdist_pathr   tarZsdist_contentsr   r   metadatalicenseZepointsliner   r   r    test_build_with_pyproject_config<  sb   ,?



	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sJ W d    n1 sw   Y  tt
j|d|}	t|	dd}
|	 }d|vsJ W d    n1 sw   Y  ||
fD ]}dD ]}||v sJ qdD ]}||vsJ qqd 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   rx   existsr   r   r'   ry   rD   extractfiler   r   r   r|   )r   r`   r   rb   r   r   r   Z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(   rw   r   rz   ry   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J d S )Npip-dist-infoMETADATA)r'   r   r(   rw    prepare_metadata_for_build_wheelrz   ry   )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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'   rw   r   r   rz   ry   )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||sJ d S )Ndist)r'   r   r(   r   rz   ry   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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|sJ d S )
NZ	out_sdistrU   rW   rtr   r   r   zversion='0.0.0'zversion='0.0.1')r'   r   r(   rw   r   rz   ry   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   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   )rU   rV   r   r   c                 s       | ]}d |v V  qdS )r   Nr   rs   r#   r   r   r   ru   Z      zNTestBuildMetaBackend.test_build_sdist_pyproject_toml_exists.<locals>.<genexpr>r
   r   r]   rZ   r   r   r   r'   ry   anyr   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   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   rU   Nr   r   r   r   r   ru   d  r   zHTestBuildMetaBackend.test_build_sdist_setup_py_exists.<locals>.<genexpr>)r   r]   defnsrZ   r   r   r   r'   ry   r   r   )r   r   rb   r   r   r   r   r    test_build_sdist_setup_py_exists\  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
        )rU   rV   r   r   c                 s   r   r   r   r   r   r   r   ru   ~  r   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   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   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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.
        r]   r   N)r   r]   _simple_pyproject_examplerZ   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-optionZ	build_extz	--inplacer]   zbuild/proj-42-py3-none-any.whl)	r   r]   r   rZ   r   r   mkdirr   rx   r   r   config_settingsrb   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_metar]   r   z__editable__.*)r   r]   r   r   r   rZ   #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   rS   rT   )r
   formatr   r]   rZ   rf   rm   rg   )
r   r   r   r   r   r   rb   Z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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   rU   rV   ro   r   )r
   r   r]   rZ   rf   )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(   rw   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   sN   t | j |  }tt |d W d    d S 1 s w   Y  d S Nr   )r   r]   _sys_argv_0_passthroughrZ   r0   r   AssertionErrorr   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   "   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   rx   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 )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   rn   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   r   r   )r   r]   r   rZ   r   r   r   r   r   r     s   z@TestBuildMetaLegacyBackend.test_build_sdist_relative_path_importc                 C   r   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 g d}| j||d }d|vsJ d|v s%J i tjdd	i}g d}| j|||d
 }d|v sBJ 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lowerr'   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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)
        rU   r   r   r   rY   N)rJ   
write_textr
   r   rf   ZmonkeypatchZtmp_pathZsetuppyrQ   r   r   r   test_sys_exit_0_in_setuppy  s
   

r  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')rU   r   r   z
some errorr   r   rY   )rJ   r  r0   r   
SystemExitr   rf   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

