o
    Zhw                  
   @  s  d dl m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 d dlmZ d dlmZ d dlmZ d d	lmZ d d
lmZ d dlZd dlZd dlZd dlmZ d dlmZ d dl m!Z!m"Z"m#Z#m$Z$m%Z%m&Z&m'Z'm(Z(m)Z) d dl*m+Z+ d dl,m-Z- d dl.m/Z/ ddl0m1Z1m2Z2 d dl3m4Z4 ej5ddgddd Z6eded7 dddededdd d!id"Z8d#Z9ej:j;ejd$kd%d&ej:<d'i e8d(e9ie8gd)d* Z=d+d, Z>d-d. Z?G d/d0 d0Z@G d1d2 d2ZAd3d4 ZBG d5d6 d6ZCd7d8 ZDG d9d: d:ZEG d;d< d<ZFej:Gd=d>d? ZHd@dA ZIG dBdC dCZJG dDdE dEZKG dFdG dGZLdHdI ZMej:GdJdKdL ZNdMdN ZOdOdP ZPdQdR ZQd^dXdYZRd_d\d]ZSdS )`    )annotationsN)deepcopy)import_module)EXTENSION_SUFFIXES)Path)dedent)Any)Mock)uuid4)	resources)	_DebuggingTips_encode_pth_find_namespaces_find_package_roots_find_virtual_namespaces_finder_template	_LinkTree_TopLevelFindereditable_wheel)Distribution)	Extension)SetuptoolsDeprecationWarning   )contexts
namespaces)	run_setupstrictlenient)paramsc                 C  s   | j dkr	ddgS g S )Nr   --config-settingseditable-mode=strict)param)request r#   ]/var/www/html/lang_env/lib/python3.10/site-packages/setuptools/tests/test_editable_install.pyeditable_opts+   s   
r%   a          [build-system]
        requires = ["setuptools"]
        build-backend = "setuptools.build_meta"

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

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

        [tool.setuptools.dynamic]
        readme = {file = "README.rst"}

        [tool.distutils.egg_info]
        tag-build = ".post0"
        zr        global-include *.py *.txt
        global-exclude *.py[cod]
        prune dist
        prune build
        zThis is a ``README``z!---- placeholder MIT license ----mypkga                  import sys
                from importlib.metadata import PackageNotFoundError, version

                try:
                    __version__ = version(__name__)
                except PackageNotFoundError:
                    __version__ = "unknown"
                a                  from importlib.resources import read_text
                from . import __version__, __name__ as parent
                from .mod import x

                data = read_text(parent, "data.txt")
                print(__version__, data, x)
                zx = ''zHello World)__init__.pyz__main__.pymod.pyzdata.txt)pyproject.tomlMANIFEST.inz
README.rstzLICENSE.txtsrcz __import__('setuptools').setup()darwinpypa/setuptools#4328reasonfilessetup.pyc                 C  s   | d }|   tjj||d ddddddt|g|}t|| g d	}|| d
ks3J |d jddd |d jddd || dksPJ d S )Nr&   prefixpython-mpipinstall--no-build-isolation-e)r4   r5   r&   z3.14159.post0 Hello Worldzsrc/mypkg/data.txtfoobarutf-8encodingzsrc/mypkg/mod.pyx = 42z3.14159.post0 foobar 42)	mkdirjaracopathbuildstrprintrunstrip
write_text)tmp_pathvenvr0   r%   projectcmdr#   r#   r$   test_editable_with_pyproject|   s&   	
rL   c                 C  sz   dt dddiddi}tjj|| d | d }dd	d
dddt|g|}t|| g d}|| dks;J d S )Nr&   ac                  [build-system]
                requires = ["setuptools", "wheel"]
                build-backend = "setuptools.build_meta"

                [project]
                name = "mypkg"
                version = "3.14159"

                [tool.setuptools]
                packages = ["pkg"]
                py-modules = ["mod"]
                r'   za = 4b = 2)r)   pkgr(   r2   r4   r5   r6   r7   r8   r9   )r4   -cz$import pkg, mod; print(pkg.a, mod.b)z4 2r   r@   rA   rB   rC   rD   rE   rF   rH   rI   r%   r0   rJ   rK   r#   r#   r$   test_editable_with_flat_layout   s.   
rR   c                 C  st   dt dddi}tjj|| d | d }dddd	d
dt|g|}t|| g d}|| dks8J d S )Nr&   a>                  [build-system]
                requires = ["setuptools", "wheel"]
                build-backend = "setuptools.build_meta"

                [project]
                name = "mod"
                version = "3.14159"

                [tool.setuptools]
                py-modules = ["mod"]
                rM   )r)   r(   r2   r4   r5   r6   r7   r8   r9   )r4   rO   zimport mod; print(mod.b)2rP   rQ   r#   r#   r$    test_editable_with_single_module   s,   
rT   c                   @  s8   e Zd Zdd Zejddejdddd Zd	S )
TestLegacyNamespacesc              
   C  s   t jtdd}|d }|  d}|D ]O}tj||dd}|; | '}|| tddd	}	t	|	}
|

  |
d
j}|
|| W d    n1 sNw   Y  W d    n1 s]w   Y  qt|d}t|t|kstJ d S )Nz .*namespace_packages parameter.*matchz.installation_dir)z	myns.pkgAz	myns.pkgBmyns.n.pkgAmyns.n.pkgB42)versionr1   config)Z
stop_afterZ	dist_infoz*-nspkg.pth)pytestwarnsr   r?   r   build_namespace_packagecontextchdirr   r   finalize_optionsget_finalized_commandnameZ_install_namespaceslistgloblen)selfrH   monkeypatchdeprecationZinstallation_dirZexamplesrd   rN   ctxdistrK   Zeditable_namer0   r#   r#   r$   test_nspkg_file_is_unique   s*   
 z.TestLegacyNamespaces.test_nspkg_file_is_uniqueimpl)pkg_resourcesns)zmyns.nc           
   	   C  s   d}t j|| d|d}t j|| d|d}|d j|dd |d j|dd |dd }	|	d	 |d
dddt|g|	 |d
ddddt|g|	 |d
dd| d| dg |g d dS )a>  
        Installing two packages sharing the same namespace, one installed
        naturally using pip or `--single-version-externally-managed`
        and the other installed in editable mode should leave the namespace
        intact and both packages reachable by import.
        (Ported from test_develop).
        zq        [build-system]
        requires = ["setuptools"]
        build-backend = "setuptools.build_meta"
        z.pkgA)rn   z.pkgBr)   r;   r<   Nr8   r4   r5   r6   r7   r9   rO   zimport z.pkgA; import )r4   rO   zimport pkg_resources)r   r_   rG   appendrE   rC   )
rh   rI   rH   rp   rn   r%   build_systempkg_Apkg_Boptsr#   r#   r$   !test_namespace_package_importable  s   
z6TestLegacyNamespaces.test_namespace_package_importableN)__name__
__module____qualname__rm   r]   markparametrizerv   r#   r#   r#   r$   rU      s    rU   c                   @  s$   e Zd Zdd Zdd Zdd ZdS )TestPep420Namespacesc              	   C  sz   t |d}t |d}|dd }|d |ddddt|g| |ddddd	t|g| |g d
 dS )z
        Installing two packages sharing the same namespace, one installed
        normally using pip and the other installed in editable mode
        should allow importing both packages.
        rX   rY   Nr8   r4   r5   r6   r7   r9   )r4   rO   z&import myns.n.pkgA; import myns.n.pkgB)r   build_pep420_namespace_packagerq   rE   rC   )rh   rI   rH   r%   rs   rt   ru   r#   r#   r$   rv   .  s   
z6TestPep420Namespaces.test_namespace_package_importablec           	   	   C  s   dt dddidi}tjj||d |d }t|d}t|d}|d	d	 }|d
 |ddddt|g| |dddddt|g| |dddddt|g| |g d d	S )z@Currently users can create a namespace by tweaking `package_dir`pkgAat                      [build-system]
                    requires = ["setuptools", "wheel"]
                    build-backend = "setuptools.build_meta"

                    [project]
                    name = "pkgA"
                    version = "3.14159"

                    [tool.setuptools]
                    package-dir = {"myns.n.pkgA" = "src"}
                    r'   a = 1)r)   r+   r2   rY   zmyns.n.pkgCNr8   r4   r5   r6   r7   r9   )r4   rO   z#from myns.n import pkgA, pkgB, pkgC)	r   r@   rA   rB   r   r}   rq   rE   rC   )	rh   rI   rH   r%   r0   rs   rt   Zpkg_Cru   r#   r#   r$   &test_namespace_created_via_package_dir=  s"   
z;TestPep420Namespaces.test_namespace_created_via_package_dirc              
   C  s   dt dddddddtd d	i}tjj||d
 |d }dg}|ddddddt|g| |g d}| dksAJ d}|ddt |g}d|v sSJ dS )a/  Sometimes users might specify an ``include`` pattern that ignores parent
        packages. In a normal installation this would ignore all modules inside the
        parent packages, and make them namespaces (reported in issue #3504),
        so the editable mode should preserve this behaviour.
        r~   ar                      [build-system]
                    requires = ["setuptools", "wheel"]
                    build-backend = "setuptools.build_meta"

                    [project]
                    name = "pkgA"
                    version = "3.14159"

                    [tool.setuptools]
                    packages.find.include = ["mypkg.*"]
                     zb = 1r   )r'   zpkgA.py)r'   zother.pynr*   )r)   r&   r*   r2   r8   r4   r5   r6   -vr7   r9   )r4   rO   z'from mypkg.n import pkgA; print(pkgA.a)1z}        try:
            import mypkg.other
        except ImportError:
            print("mypkg.other not defined")
        rO   zmypkg.other not definedN)r   EXAMPLEr@   rA   rB   rE   rC   rF   )rh   rI   rH   r0   rs   ru   outrK   r#   r#   r$   0test_namespace_accidental_config_in_lenient_mode_  s,    zETestPep420Namespaces.test_namespace_accidental_config_in_lenient_modeN)rw   rx   ry   rv   r   r   r#   r#   r#   r$   r|   -  s    "r|   c           	   	     s   | d   fddt jD }|D ]}|jdd qt| ttjtjt	t
|d}t jddd	d
t
|dt
 dg	|}tj||d t dkrLdnd} | d }tj|g|d dS )z>
    Editable install to a prefix should be discoverable.
    r3   c                   s4   g | ]}d |v r| tjr t|tj qS )zsite-packages)
startswithsysr3   r   relative_to).0rA   r2   r#   r$   
<listcomp>  s
    z-test_editable_with_prefix.<locals>.<listcomp>T)parents)
PYTHONPATHr5   r6   r7   z
--editablez--prefixr8   )envWindowsScriptsbinsampleN)r   rA   r?   _addsitedirsdictosenvironpathsepjoinmaprC   
executable
subprocess
check_callplatformsystem)	rH   Zsample_projectr%   Zsite_packages_allspr   rK   r   exer#   r2   r$   test_editable_with_prefix  s0   

r   c                   @  sh   e Zd Z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dd ZdS )TestFinderTemplateThis test focus in getting a particular implementation detail right.
    If at some point in time the implementation is changed for something different,
    this test can be modified or even excluded.
    c                 C  s   i }t ||| |d   d S )Nr7   )exec)rh   finderlocr#   r#   r$   install_finder  s   z!TestFinderTemplate.install_finderc           
   	   C  s.  ddddididdid}t jj||d	 t|d
 t|d d}ttt |i }t ] t @ dD ]	}t	j
|d  q8| | td}td}td}|jdksZJ |jdksaJ t|d  }	t||	 W d    n1 sxw   Y  W d    d S W d    d S 1 sw   Y  d S )Npkg1r   mod1.pyza = 42)r'   subpkgmod2.pyza = 43src1src2r2   z	src1/pkg1z	src2/mod2)r   mod2)r   pkg1.subpkgpkg1.subpkg.mod1r   r   r   r   *   +   zsrc1/pkg1/subpkg)r@   rA   rB   rC   r   r
   r   
save_pathssave_sys_modulesr   modulespopr   r   aresolveassert_path)
rh   rH   r0   mappingtemplatemodmod1r   r   expectedr#   r#   r$   test_packages  s0   	


Pz TestFinderTemplate.test_packagesc           
   	   C  s"  ddddi}t jj||d dt|d i}dg i}ttt ||}t _ t B dD ]	}t	j
|d  q0| | td}t|d	 }t|d  }	t||	 |jd
ks^J |jdddkshJ W d    n1 srw   Y  W d    d S W d    d S 1 sw   Y  d S )NrN   a = 13abc)r'   text.txtr2   ns.othernamerp   rp   r   r      r;   r<   )r@   rA   rB   rC   r   r
   r   r   r   r   r   r   r   r   importlib_resourcesr0   r   r   r   	read_text)
rh   rH   r0   r   r   r   r   rN   textr   r#   r#   r$   test_namespace  s    

Pz!TestFinderTemplate.test_namespacec           
   	   C  sD  ddddiiidddiid}t jj||d t|d	 t|d
 d}dt|d t|d gi}ttt ||}t Y t < dD ]	}t	j
|d  qG| | td}td}t|d	  }	t||	 |jdksrJ |jdksyJ W d    n1 sw   Y  W d    d S W d    d S 1 sw   Y  d S )Nrp   r   r'   r   r   b = 37r   r2   zsrc1/ns/pkg1zsrc2/ns)ns.pkgArp   r   r   )rp   r   ns.mod2r   r   r   %   )r@   rA   rB   rC   r   r
   r   r   r   r   r   r   r   r   r   r   r   b)
rh   rH   r0   r   namespaces_r   r   r~   r   r   r#   r#   r$   test_combine_namespaces  s(   




Pz*TestFinderTemplate.test_combine_namespacesc              	   C  s  dddiidddiid}t j }||0 t j| dd	d
dddgd}t|}t|tt }t	dd |
 D }W d   n1 sJw   Y  t x t [ |d D ]	}tj|d q]| | td}	td}
t|d  }tt|	j |ksJ t|d  }tt|
j |ksJ |	jdksJ |
jdksJ W d   n1 sw   Y  W d   dS W d   dS 1 sw   Y  dS )z
        Users may attempt to combine namespace packages in a nested way via
        ``package_dir`` as shown in pypa/setuptools#4248.
        Z
my_packagezmy_module.pyr   Zmy_package2zmy_module2.pyr   )r+   r   	%PEP 517%zsrc/my_packagezsrc2/my_package2)different_namedifferent_name.subpkgr   r   )script_namepackage_dirpackagesc                 s  s"    | ]\}}| d r|V  qdS )z.pyNendswith)r   kvr#   r#   r$   	<genexpr>/       zDTestFinderTemplate.test_combine_namespaces_nested.<locals>.<genexpr>Nr   zdifferent_name.my_modulez different_name.subpkg.my_module2zsrc/my_package/my_module.pyzsrc2/my_package2/my_module2.pyr   r   )r@   rA   ZDirectoryStackr`   rB   r   r   rC   r
   nextZget_implementationr   r   r   r   r   r   r   r   r   r   __file__r   r   )rh   rH   r0   stackattrsrl   r   coder   r   r   r   r#   r#   r$   test_combine_namespaces_nested  s:   



Pz1TestFinderTemplate.test_combine_namespaces_nestedc              
   C  s  ddddiiiddddiiiddddiiid	}t jj||d
 i }dt|d gi}ttt ||}dd dD }t  t  dddg|R D ]	}t	j
|d  qM| | td}|jdksgJ tt td W d    n1 s{w   Y  t	jt|d  td}	|	jdksJ tt td W d    n1 sw   Y  t	jt|d  td}
|
jdksJ W d    n1 sw   Y  W d    d S W d    d S 1 sw   Y  d S )Nparentchildzone.pyx = 1ztwo.pyx = 2zthree.pyzx = 3)Zproject1project2project3r2   zproject1/parentc                 s  s    | ]}d | V  qdS )zparent.child.Nr#   )r   rd   r#   r#   r$   r   N      zCTestFinderTemplate.test_dynamic_path_computation.<locals>.<genexpr>)onetwothreezparent.childzparent.child.oner   zparent.child.twor      zparent.child.threer      )r@   rA   rB   rC   r   r
   r   r   r   r   r   r   r   r   xr]   raisesImportErrorrq   )rh   rH   r0   r   r   r   modsr   r   r   r   r#   r#   r$   test_dynamic_path_computationB  s8   


Pz0TestFinderTemplate.test_dynamic_path_computationc              
   C  s   dddii}t jj||d dt|d i}ttt |i }t L t / t	j
dd  | | tjtdd td W d    n1 sKw   Y  W d    n1 sZw   Y  W d    d S W d    d S 1 srw   Y  d S )NrN   r'   zfrom . import pkgr2   rV   r@   rA   rB   rC   r   r
   r   r   r   r   r   r   r   r]   r   r   r   rh   rH   r0   r   r   r#   r#   r$   test_no_recursionf  s    

Pz$TestFinderTemplate.test_no_recursionc              
   C  s  ddddidi}t jj||d dt|d i}ttt |i }t S t 6 t	j
dd  t	j
dd  | | tjtdd td W d    n1 sUw   Y  W d    n1 sdw   Y  W d    d S W d    d S 1 s|w   Y  d S )	Nfoor   r'   )r'   barr2   zfoo.barr:   rV   r   r   r#   r#   r$   test_similar_name{  s&   

Pz$TestFinderTemplate.test_similar_namec              
   C  s   dddddddi}t jj||d dt|d i}ttt |i }t  t  t	j
dd  | | tjtdd	 td
 W d    n1 sPw   Y  tjtdd	 td W d    n1 skw   Y  tjtdd	 td W d    n1 sw   Y  tjtdd	 td W d    n1 sw   Y  tjtdd	 td W d    n1 sw   Y  td}|jdksJ td}|jdksJ W d    n1 sw   Y  W d    d S W d    d S 1 sw   Y  d S )Nr   r   r   r   )r'   lowercase.py)r'   r   r   r2   z'FOO'rV   ZFOOz'foo\.LOWERCASE'zfoo.LOWERCASEz'foo\.bar\.Lowercase'zfoo.bar.Lowercasez
'foo\.BAR'zfoo.BAR.lowercasezFOO.bar.lowercasezfoo.lowercaser   zfoo.bar.lowercaser   )r@   rA   rB   rC   r   r
   r   r   r   r   r   r   r   r]   r   r   r   r   )rh   rH   r0   r   r   r   r#   r#   r$   test_case_sensitivity  sF   






Pz(TestFinderTemplate.test_case_sensitivityc              
   C  s  ddddddi}t jj||d dt|d i}d	g i}ttt ||}t  t  d
D ]	}t	j
|d  q3| | td}t|d  }t|| |jdksZJ td}	|	jdkseJ td}
|
jdkspJ tjtdd td W d    n1 sw   Y  tjtdd td W d    n1 sw   Y  tjtdd td W d    n1 sw   Y  W d    n1 sw   Y  W d    d S W d    d S 1 sw   Y  d S )NrN   r   r   zc = 42)r'   zbar.py)r'   r   r2   r   rp   r   r   zns.othername.foor   zns.othername.foo.barr   z'NS'rV   zNS.othername.fooz'ns\.othername\.FOO\'zns.othername.FOOz'ns\.othername\.foo\.BAR\'zns.othername.foo.BAR)r@   rA   rB   rC   r   r
   r   r   r   r   r   r   r   r   r   r   r   r   cr]   r   r   )rh   rH   r0   r   r   r   r   rN   r   r   r   r#   r#   r$   test_namespace_case_sensitivity  sD   	




Pz2TestFinderTemplate.test_namespace_case_sensitivityc              
   C  s2  dddddddidii}t jj||d	 dt|d
 i}ttt |i }t e t H dD ]	}t	j
|d q2| | td}|jdksLJ td}|jdksWJ tt td W d   n1 skw   Y  W d   n1 szw   Y  W d   dS W d   dS 1 sw   Y  dS )z
        The finder should not import ``fullname`` if the intermediate segments
        don't exist (see pypa/setuptools#4019).
        r+   r&   r   r   zb = 13	config.pyza = 37)r'   r   zhelloworld.py
componentsr2   z	src/mypkg)r&   zmypkg.configmypkg.helloworldzmypkg.componentsmypkg.components.configmypkg.components.helloworldNr  r   r  r   r  )r@   rA   rB   rC   r   r
   r   r   r   r   r   r   r   r   r   r   r]   r   r   )rh   rH   r0   r   r   r   r\   Z
helloworldr#   r#   r$   test_intermediate_packages  s4   

Pz-TestFinderTemplate.test_intermediate_packagesN)rw   rx   ry   __doc__r   r   r   r   r   r   r   r   r   r   r  r#   r#   r#   r$   r     s     +$))r   c              	   C  s   ddidddddiddd	dd
iiiddiddiddid}t jj|| d dddd}g d}t||| }|t| d t| d t| d t| d t| d t| d dks\J ttt||}|ddhksmJ tt|}|h dks{J dS )r   r'   zab = 1r   )r   r'   zd = 1zde = 1)r'   eghzfgh = 1zabc = 1z
abcxyz = 1z	mnopq = 1)r   dfotheranotheryet_anotherr2   r  r  r  )a.b.ca.b.c.x.y.z	m.n.o.p.q)r   a.br  	a.b.c.x.yr  r
  zd.er  f.gzf.g.hr  r   r
  r  )r   r  r  r
  r  r  r  >   mzm.nzm.n.oza.b.c.xr  zm.n.o.pr  N)	r@   rA   rB   r   rC   setr   r   r   )rH   r0   r   r   rootsrp   r#   r#   r$   test_pkg_roots  s4   





	r  c                
   @  s   e Zd ZU dZeeed ddddddddd	Zd
ed< eeeed dded ideeed ed dded d ded d deeed dded d ed d diddZe	j
jejdkdde	j
de dd ZdS )TestOverallBehaviourz        [build-system]
        requires = ["setuptools"]
        build-backend = "setuptools.build_meta"

        [project]
        name = "mypkg"
        version = "3.14159"
        r*   r   zvar = 42zvar = 13resource 39)r'   r   zresource_file.txt)r'   r   
subpackage)r)   r*   otherfile.pyr&   zdict[str, Any]FLAT_LAYOUTr&   )r)   r*   r  r+   z                [tool.setuptools]
                packages = ["mypkg", "mypkg.subpackage"]

                [tool.setuptools.package-dir]
                "mypkg.subpackage" = "other"
                r   )r'   r   r  )r)   r*   r  r&   r  )r   r  )flat-layout
src-layoutcustom-layout	namespacer,   r-   r.   layoutc                 C  s<  t d||| j| g|R  \}}d}|ddt|g}d|v s"J d}	|ddt|	g}d|v s4J d}
|ddt|
g}d	|v sFJ t|d
}t|d}t|d}|jddd |jddd |jddd |ddt|	g}d|vsJ d|v sJ |ddt|
g}d	|vsJ d|v sJ d S )Nr&   zj        try:
            import otherfile
        except ImportError as ex:
            print(ex)
        r4   rO   zNo module named 'otherfile'zy        import mypkg, mypkg.mod1, mypkg.subpackage.mod2
        print(mypkg.mod1.var, mypkg.subpackage.mod2.var)
        z42 13z        import mypkg.subpackage
        from setuptools._importlib import resources as importlib_resources
        text = importlib_resources.files(mypkg.subpackage) / "resource_file.txt"
        print(text.read_text(encoding="utf-8"))
        r  
**/mod1.py
**/mod2.py**/resource_file.txtzvar = 17r;   r<   z	var = 781zresource 374z17 781)install_projectEXAMPLESrE   r   r   rf   rG   )rh   rH   rI   r"  r%   rJ   _cmd_import_errorr   Zcmd_get_varscmd_get_resourcer   r   resource_filer#   r#   r$   test_editable_install  s4   z*TestOverallBehaviour.test_editable_installN)rw   rx   ry   Z	PYPROJECTr   r   r  __annotations__r'  r]   rz   xfailr   r   r{   keysr,  r#   r#   r#   r$   r  C  sX   
 





(r  c                   @  sN   e Zd Zeejd Zed  ed7  < ded d d< dd	 Zd
d Z	dS )TestLinkTreer  r)   a[          [tool.setuptools]
        # Temporary workaround: both `include-package-data` and `package-data` configs
        # can be removed after #3260 is fixed.
        include-package-data = false
        package-data = {"*" = ["*.txt"]}

        [tool.setuptools.packages.find]
        where = ["src"]
        exclude = ["*.subpackage*"]
        r   r+   r&   resource.not_in_manifestc                 C  sJ  t jj| j|d t| d}tddi}|  t }|d }|d }|  |  |	d}d|_
t||_|  | }| }	t||||}
|
|||	 t|d	}|d
 }t|| t|dd d u soJ t|dd d u s{J t|dd d u sJ t|dd d u sJ W d    d S 1 sw   Y  d S )Nr2   zmypkg-3.14159r   r   z.auxz.buildbuild_pyTr#  zsrc/mypkg/mod1.pyz**/subpackager$  r%  z**/resource.not_in_manifest)r@   rA   rB   FILES_Pathr   Zparse_config_filesr	   r?   Zget_command_objZeditable_moderC   Z	build_libensure_finalizedZget_outputsZget_output_mappingr   r   rf   assert_link_to)rh   rH   rd   rl   wheelZauxrB   r2  ZoutputsZoutput_mappingZ	make_treer   r   r#   r#   r$   test_generated_tree  s4   



"z TestLinkTree.test_generated_treec                 C  s   ddg}t d||| jg|R   |g d}d|v sJ d}|ddt|g}d	|v s/J d
}|ddt|g}d|v sAJ d|v sGJ d S )Nr   r    r&   r4   rO   z(import mypkg.mod1; print(mypkg.mod1.var)rZ   zv        try:
            from mypkg import subpackage
        except ImportError as ex:
            print(ex)
        r4   rO   cannot import name 'subpackage'a8          import mypkg
        from setuptools._importlib import resources as importlib_resources
        try:
            text = importlib_resources.files(mypkg) / "resource.not_in_manifest"
            print(text.read_text(encoding="utf-8"))
        except FileNotFoundError as ex:
            print(ex)
        zNo such file or directoryr1  )r&  r3  rE   r   )rh   rH   rI   ru   r   r)  r*  r#   r#   r$   test_strict_install  s   	z TestLinkTree.test_strict_installN)
rw   rx   ry   r   r  r'  r3  r   r8  r;  r#   r#   r#   r$   r0    s    
"r0  z9ignore:.*compat.*:setuptools.SetuptoolsDeprecationWarningc                 C  s   ddg}t jd }td|| |g|R   |g d}d|v s!J tt| }dD ]}t|dd	|g}||v s;J q)d
}|dd	t|g}d|v sNJ d S )Nr   zeditable-mode=compatr   r&   r9  rZ   )z"import otherfile; print(otherfile)zimport other; print(other)zimport mypkg; print(mypkg)r4   rO   zc    try:
        from mypkg import subpackage;
    except ImportError as ex:
        print(ex)
    r:  )r  r'  r&  rE   comparable_pathrC   r   )rH   rI   ru   r0   r   Zexpected_pathrK   r#   r#   r$   test_compat_install  s   
r=  c                 C  s   t dt dt ddddddid	}|g d
 tjdd td|| |g|R   W d   n1 s6w   Y  |g d}d|v sHJ dS )z3Ensure editable installs work with pbr, issue #3500z            [build-system]
            requires = ["setuptools"]
            build-backend = "setuptools.build_meta"
            z            __import__('setuptools').setup(
                pbr=True,
                setup_requires=["pbr"],
            )
            z~            [metadata]
            name = mypkg

            [files]
            packages =
                mypkg
            r   zprint('Hello world!'))r'   zhello.pyztest.txtzAnother file in here.)r)   r1   z	setup.cfgr&   r  )r4   r5   r6   r7   Zpbrz0.42)ZPBR_VERSIONr&   N)r4   rO   zimport mypkg.hellozHello world!)r   rE   r   environmentr&  )rH   rI   r%   r0   r   r#   r#   r$   test_pbr_integration/  s(    r?  c                   @  s2   e Zd ZdZi ejd dediZdd ZdS )TestCustomBuildPya$  
    Issue #3501 indicates that some plugins/customizations might rely on:

    1. ``build_py`` not running
    2. ``build_py`` always copying files to ``build_lib``

    During the transition period setuptools should prevent potential errors from
    happening due to those assumptions.
    r  r1   af              import pathlib
            from setuptools import setup
            from setuptools.command.build_py import build_py as orig

            class my_build_py(orig):
                def run(self):
                    super().run()
                    raise ValueError("TEST_RAISE")

            setup(cmdclass={"build_py": my_build_py})
            c                 C  sJ   t d||| j\}}d|v sJ d|v sJ |g d}d|v s#J dS )z>Ensure that errors in custom build_py are reported as warningsr&   r   zValueError: TEST_RAISEr9  rZ   N)r&  r3  rE   )rh   rH   rI   r(  r   r#   r#   r$   test_safeguarded_from_errorsy  s
   z.TestCustomBuildPy.test_safeguarded_from_errorsN)	rw   rx   ry   r  r  r'  r   r3  rA  r#   r#   r#   r$   r@  Z  s    r@  c                   @  s   e Zd Zdd Zdd ZdS )TestCustomBuildWheelc                 C  s(   | d}G dd d|}||jd< d S )Nbdist_wheelc                      s   e Zd Z fddZ  ZS )zETestCustomBuildWheel.install_custom_build_wheel.<locals>.MyBdistWheelc                   s   | j drd}t  S )Nzmacosx-zmacOS platform)Z	plat_namer   superget_tag)rh   r(  	__class__r#   r$   rE    s   
zMTestCustomBuildWheel.install_custom_build_wheel.<locals>.MyBdistWheel.get_tag)rw   rx   ry   rE  __classcell__r#   r#   rF  r$   MyBdistWheel  s    rI  )Zget_command_classcmdclass)rh   rl   Zbdist_wheel_clsrI  r#   r#   r$   install_custom_build_wheel  s   
z/TestCustomBuildWheel.install_custom_build_wheelc                 C  sj   t jddi t }d|_|  | | t|}|  |	  t
tt d}d|v s3J d S )N	module.pyr>   r1   
dist/*.whleditable)r@   rA   rB   r   r   set_defaultsrK  r   r5  rE   rC   r   r   rf   )rh   
tmpdir_cwdrl   rK   
wheel_filer#   r#   r$   test_access_plat_name  s   
z*TestCustomBuildWheel.test_access_plat_nameN)rw   rx   ry   rK  rR  r#   r#   r#   r$   rB    s    rB  c                   @  s2   e Zd Zdd Zejjejdkdddd Z	dS )	TestCustomBuildExtc                 C  s*   ddl m} G dd d|}||jd< d S )Nr   )	build_extc                   @  s   e Zd ZdS )zITestCustomBuildExt.install_custom_build_ext_distutils.<locals>.MyBuildExtN)rw   rx   ry   r#   r#   r#   r$   
MyBuildExt  s    rU  rT  )Zdistutils.command.build_extrT  rJ  )rh   rl   Zbuild_ext_clsrU  r#   r#   r$   "install_custom_build_ext_distutils  s   z5TestCustomBuildExt.install_custom_build_ext_distutilslinuxz(compilers may fail without correct setupr.   c                   s   t jddi dtddggi}t|}d|_|  | | t|}|	  |
  ttt d}d|v s=J dd	 t d
D }t|dksPJ |d j t fddtD sbJ d S )Nzmodule.cr   Zext_modulesmoduler1   rM  rN  c                 S  s   g | ]	}|j d kr|qS )z.c)suffix)r   pr#   r#   r$   r     s    zITestCustomBuildExt.test_distutils_leave_inplace_files.<locals>.<listcomp>zmodule.*r   r   c                 3  s    | ]}  |V  qd S Nr   )r   extrd   r#   r$   r     r   zHTestCustomBuildExt.test_distutils_leave_inplace_files.<locals>.<genexpr>)r@   rA   rB   r   r   r   rO  rV  r   r5  rE   rC   r   r   rf   rg   rd   anyr   )rh   rP  r   rl   rK   rQ  r0   r#   r]  r$   "test_distutils_leave_inplace_files  s    

z5TestCustomBuildExt.test_distutils_leave_inplace_filesN)
rw   rx   ry   rV  r]   rz   Zskipifr   r   r_  r#   r#   r#   r$   rS    s    
rS  c              	   C  s   t jddi t }d|_|  t|}|  tdt	fi }t
| d}||d| d}t|, tjt|d |  W d	   n1 sLw   Y  W d	   d	S W d	   d	S 1 sdw   Y  d	S )
z7Make sure to display useful debugging tips to the user.rL  r>   r1   SimulatedErr)Zside_effectrc   z-following steps are recommended to help debugrV   N)r@   rA   rB   r   r   rO  r   r5  type	Exceptionr	   setattrr]   r   r^   r   rE   )rP  ri   rl   rK   r`  Zsimulated_failureZexpected_msgr#   r#   r$   test_debugging_tips  s   
Prd  errorc                  C  s   t d} t| tsJ dS )z>Ensure _encode_pth function does not produce encoding warningsu   tkmilan_ç_utf8N)r   
isinstancebytes)contentr#   r#   r$   test_encode_pth  s   ri  c              	   G  sZ   ||  }|   tjj||d g |d}|jddddddt|g|tjd	}||fS )
Nr2   r8   r4   r5   r6   r   r7   r9   )stderr)r?   r@   rA   rB   rE   rC   r   STDOUT)rd   rI   rH   r0   ru   rJ   r   r#   r#   r$   r&    s   r&  c                 C  s6   d dtdd | D  }| d d j|dd d	S )
a5  To use this function, it is necessary to insert new_dir in front of sys.path.
    The Python process will try to import a ``sitecustomize`` module on startup.
    If we manipulate sys.path/PYTHONPATH, we can force it to run our code,
    which invokes ``addsitedir`` and ensure ``.pth`` files are loaded.
    
)zimport sitec                 s  s"    | ]}d t |dV  qdS )zsite.addsitedir()N)r   fspath)r   Znew_dirr#   r#   r$   r     r   z_addsitedirs.<locals>.<genexpr>r   zsitecustomize.pyr;   r<   N)r   tuplerG   )Znew_dirsrh  r#   r#   r$   r     s   r   c                 C  s>   | j rtt| j d }|rtt| |ksJ d S d S d S r[  )__path__r   iterrC   r   r   )rN   r   rA   r#   r#   r$   r     s   r   filer   r  returnNonec                 C  sl   |   rt|  t| ksJ d S |  }| }|tj |tj ks(J |tj |tj ks4J d S r[  )
is_symlinkrC   r   statST_INOST_DEV)rr  r  Z	file_statZ
other_statr#   r#   r$   r6    s    r6  str_with_pathrC   c                 C  s   |   tjdddS )N/z//)lowerreplacer   sep)ry  r#   r#   r$   r<    s   r<  )rr  r   r  r   rs  rt  )ry  rC   rs  rC   )T
__future__r   r   r   rv  r   r   copyr   	importlibr   Zimportlib.machineryr   pathlibr   textwrapr   typingr   Zunittest.mockr	   uuidr
   Zjaraco.envsr@   Zjaraco.pathr]   rA   r4  Zsetuptools._importlibr   r   Z!setuptools.command.editable_wheelr   r   r   r   r   r   r   r   r   Zsetuptools.distr   Zsetuptools.extensionr   Zsetuptools.warningsr   r   r   r   Zdistutils.corer   Zfixturer%   rF   r   ZSETUP_SCRIPT_STUBrz   r.  r{   rL   rR   rT   rU   r|   r   r   r  r  r0  filterwarningsr=  r?  r@  rB  rS  rd  ri  r&  r   r   r6  r<  r#   r#   r#   r$   <module>   s    ,

G(&Be(  Z1x
S
 +* 



