o
    LK&h{                  
   @  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( d dl)m*Z* d dl+m,Z, d dl-m.Z. ddl/m0Z0m1Z1 d dl2m3Z3 ej4ddgddd Z5eded6 dddededdd d!id"Z7d#Z8ej9j:ejd$kd%d&ej9;d'i e7d(e8ie7gd)d* Z<d+d, Z=d-d. Z>G d/d0 d0Z?G d1d2 d2Z@d3d4 ZAG d5d6 d6ZBd7d8 ZCG d9d: d:ZDG d;d< d<ZEej9Fd=d>d? ZGej9jHd@dA ZIG dBdC dCZJG dDdE dEZKG dFdG dGZLdHdI ZMej9FdJdKdL ZNdMdN ZOdOdP ZPdQdR ZQd^dXdYZRd_d\d]ZSdS )`    )annotationsN)deepcopy)import_module)EXTENSION_SUFFIXES)Path)dedent)Any)Mock)uuid4)	resources)_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"   Y/var/www/html/venv/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)r3   r4   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venvr/   r$   projectcmdr"   r"   r#   test_editable_with_pyproject{   s&   	
rK   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'   r1   r3   r4   r5   r6   r7   r8   )r3   -cz$import pkg, mod; print(pkg.a, mod.b)z4 2r   r?   r@   rA   rB   rC   rD   rE   rG   rH   r$   r/   rI   rJ   r"   r"   r#   test_editable_with_flat_layout   s.   
rQ   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"]
                rL   )r(   r'   r1   r3   r4   r5   r6   r7   r8   )r3   rN   zimport mod; print(mod.b)2rO   rP   r"   r"   r#    test_editable_with_single_module   s,   
rS   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)versionr0   config)
stop_after	dist_infoz*-nspkg.pth)pytestwarnsr   r>   r   build_namespace_packagecontextchdirr   r   finalize_optionsget_finalized_commandname_install_namespaceslistgloblen)selfrG   monkeypatchdeprecationinstallation_direxamplesre   rM   ctxdistrJ   editable_namer/   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)rs   z.pkgBr(   r:   r;   Nr7   r3   r4   r5   r6   r8   rN   zimport z.pkgA; import )r3   rN   zimport pkg_resources)r   r`   rF   appendrD   rB   )
rj   rH   rG   ru   rs   r$   build_systempkg_Apkg_Boptsr"   r"   r#   !test_namespace_package_importable  s   
z6TestLegacyNamespaces.test_namespace_package_importableN)__name__
__module____qualname__rr   r^   markparametrizer{   r"   r"   r"   r#   rT      s    rT   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.
        rW   rX   Nr7   r3   r4   r5   r6   r8   )r3   rN   z&import myns.n.pkgA; import myns.n.pkgB)r   build_pep420_namespace_packagerv   rD   rB   )rj   rH   rG   r$   rx   ry   rz   r"   r"   r#   r{   -  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*   r1   rX   zmyns.n.pkgCNr7   r3   r4   r5   r6   r8   )r3   rN   z#from myns.n import pkgA, pkgB, pkgC)	r   r?   r@   rA   r   r   rv   rD   rB   )	rj   rH   rG   r$   r/   rx   ry   pkg_Crz   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)   r1   r7   r3   r4   r5   -vr6   r8   )r3   rN   z'from mypkg.n import pkgA; print(pkgA.a)1z}        try:
            import mypkg.other
        except ImportError:
            print("mypkg.other not defined")
        rN   zmypkg.other not definedN)r   EXAMPLEr?   r@   rA   rD   rB   rE   )rj   rH   rG   r/   rx   rz   outrJ   r"   r"   r#   0test_namespace_accidental_config_in_lenient_mode^  s,    zETestPep420Namespaces.test_namespace_accidental_config_in_lenient_modeN)r|   r}   r~   r{   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.
    r2   c                   s4   g | ]}d |v r| tjr t|tj qS )zsite-packages)
startswithsysr2   r   relative_to).0r@   r1   r"   r#   
<listcomp>  s
    z-test_editable_with_prefix.<locals>.<listcomp>T)parents)
PYTHONPATHr4   r5   r6   
--editablez--prefixr7   )envWindowsScriptsbinsampleN)r   r@   r>   _addsitedirsdictosenvironpathsepjoinmaprB   
executable
subprocess
check_callplatformsystem)	rG   sample_projectr$   site_packages_allspr   rJ   r   exer"   r1   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 )Nr6   )exec)rj   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src2r1   z	src1/pkg1z	src2/mod2)r   mod2)r   pkg1.subpkgpkg1.subpkg.mod1r   r   r   r   *   +   zsrc1/pkg1/subpkg)r?   r@   rA   rB   r   r
   r   
save_pathssave_sys_modulesr   modulespopr   r   aresolveassert_path)
rj   rG   r/   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 )NrM   a = 13abc)r&   text.txtr1   ns.othernameru   ru   r   r      r:   r;   )r?   r@   rA   rB   r   r
   r   r   r   r   r   r   r   r   importlib_resourcesr/   r   r   r   	read_text)
rj   rG   r/   r   r   r   r   rM   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 )Nru   r   r&   r   r   b = 37r   r1   zsrc1/ns/pkg1zsrc2/ns)ns.pkgAru   r   r   )ru   r   ns.mod2r   r   r   %   )r?   r@   rA   rB   r   r
   r   r   r   r   r   r   r   r   r   r   r   b)
rj   rG   r/   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.
        
my_packagezmy_module.pyr   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?   r@   DirectoryStackra   rA   r   r   rB   r
   nextget_implementationr   r   r   r   r   r   r   r   r   r   __file__r   r   )rj   rG   r/   stackattrsrp   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)project1project2project3r1   zproject1/parentc                 s  s    | ]}d | V  qdS )zparent.child.Nr"   )r   re   r"   r"   r#   r   M      zCTestFinderTemplate.test_dynamic_path_computation.<locals>.<genexpr>)onetwothreezparent.childzparent.child.oner   zparent.child.twor      zparent.child.threer      )r?   r@   rA   rB   r   r
   r   r   r   r   r   r   r   r   xr^   raisesImportErrorrv   )rj   rG   r/   r   r   r   modsr   r   r   r   r"   r"   r#   test_dynamic_path_computationA  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 )NrM   r&   zfrom . import pkgr1   rU   r?   r@   rA   rB   r   r
   r   r   r   r   r   r   r   r^   r   r  r   rj   rG   r/   r   r   r"   r"   r#   test_no_recursione  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&   barr1   zfoo.barr9   rU   r  r  r"   r"   r#   test_similar_namez  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  r1   z'FOO'rU   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?   r@   rA   rB   r   r
   r   r   r   r   r   r   r   r^   r   r  r   r   )rj   rG   r/   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 )NrM   r   r   zc = 42)r&   zbar.py)r&   r  r1   r   ru   r   r   zns.othername.foor   zns.othername.foo.barr   z'NS'rU   zNS.othername.fooz'ns\.othername\.FOO\'zns.othername.FOOz'ns\.othername\.foo\.BAR\'zns.othername.foo.BAR)r?   r@   rA   rB   r   r
   r   r   r   r   r   r   r   r   r   r   r   r   cr^   r   r  )rj   rG   r/   r   r   r   r   rM   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
componentsr1   z	src/mypkg)r%   zmypkg.configmypkg.helloworldzmypkg.componentsmypkg.components.configmypkg.components.helloworldNr  r   r  r   r  )r?   r@   rA   rB   r   r
   r   r   r   r   r   r   r   r   r   r   r^   r   r  )rj   rG   r/   r   r   r   r[   
helloworldr"   r"   r#   test_intermediate_packages  s4   

Pz-TestFinderTemplate.test_intermediate_packagesN)r|   r}   r~   __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_anotherr1   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$  >   m.nm.n.oa.b.c.xm.n.o.pmr"  r#  N)	r?   r@   rA   r   rB   setr   r   r   )rG   r/   r   r   rootsru   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)   r0  r*   z                [tool.setuptools]
                packages = ["mypkg", "mypkg.subpackage"]

                [tool.setuptools.package-dir]
                "mypkg.subpackage" = "other"
                r   )r&   r   r/  )r(   r)   r0  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)
        r3   rN   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EXAMPLESrD   r   r   rh   rF   )rj   rG   rH   r6  r$   rI   _cmd_import_errorr   cmd_get_varscmd_get_resourcer   r   resource_filer"   r"   r#   test_editable_install  s4   z*TestOverallBehaviour.test_editable_installN)r|   r}   r~   	PYPROJECTr   r   r1  __annotations__r;  r^   r   xfailr   r   r   keysrA  r"   r"   r"   r#   r-  B  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 )TestLinkTreer3  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 )Nr1   zmypkg-3.14159r   r   z.auxz.buildbuild_pyTr7  zsrc/mypkg/mod1.pyz**/subpackager8  r9  z**/resource.not_in_manifest)r?   r@   rA   FILES_Pathr   parse_config_filesr	   r>   get_command_objeditable_moderB   	build_libensure_finalizedget_outputsget_output_mappingr   r   rh   assert_link_to)rj   rG   re   rp   wheelauxrA   rH  outputsoutput_mapping	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%   r3   rN   z(import mypkg.mod1; print(mypkg.mod1.var)rY   zv        try:
            from mypkg import subpackage
        except ImportError as ex:
            print(ex)
        r3   rN   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 directoryrG  )r:  rI  rD   r   )rj   rG   rH   rz   r   r=  r?  r"   r"   r#   test_strict_install  s   	z TestLinkTree.test_strict_installN)
r|   r}   r~   r   r-  r;  rI  r   rX  r[  r"   r"   r"   r#   rF    s    
"rF  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=compatr4  r%   rY  rY   )z"import otherfile; print(otherfile)zimport other; print(other)zimport mypkg; print(mypkg)r3   rN   zc    try:
        from mypkg import subpackage;
    except ImportError as ex:
        print(ex)
    rZ  )r-  r;  r:  rD   comparable_pathrB   r   )rG   rH   rz   r/   r   expected_pathrJ   r"   r"   r#   test_compat_install  s   
r^  c                 C  sD   dddddd| g|}|j |tjd | g d}d	|v s J d
S )z3Ensure editable installs work with pbr, issue #3500r3   r4   r5   r   r6   r   stderr)r3   rN   zimport mypkg.hellozHello world!N)rD   r   STDOUT)pbr_packagerH   r$   rJ   r   r"   r"   r#   test_pbr_integration.  s   
rc  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.
    r2  r0   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_RAISErY  rY   N)r:  rI  rD   )rj   rG   rH   r<  r   r"   r"   r#   test_safeguarded_from_errors_  s
   z.TestCustomBuildPy.test_safeguarded_from_errorsN)	r|   r}   r~   r  r-  r;  r   rI  re  r"   r"   r"   r#   rd  @  s    rd  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)	plat_namer   superget_tag)rj   r<  	__class__r"   r#   rj  o  s   
zMTestCustomBuildWheel.install_custom_build_wheel.<locals>.MyBdistWheel.get_tag)r|   r}   r~   rj  __classcell__r"   r"   rk  r#   MyBdistWheeln  s    rn  )get_command_classcmdclass)rj   rp   bdist_wheel_clsrn  r"   r"   r#   install_custom_build_wheelk  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=   r0   
dist/*.whleditable)r?   r@   rA   r   r   set_defaultsrr  r   rO  rD   rB   r   r   rh   )rj   
tmpdir_cwdrp   rJ   
wheel_filer"   r"   r#   test_access_plat_namex  s   
z*TestCustomBuildWheel.test_access_plat_nameN)r|   r}   r~   rr  ry  r"   r"   r"   r#   rf  j  s    rf  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)r|   r}   r~   r"   r"   r"   r#   
MyBuildExt  s    r|  r{  )distutils.command.build_extr{  rp  )rj   rp   build_ext_clsr|  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   ext_modulesmoduler0   rt  ru  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re   r"   r#   r     r   zHTestCustomBuildExt.test_distutils_leave_inplace_files.<locals>.<genexpr>)r?   r@   rA   r   r   r   rv  r  r   rO  rD   rB   r   r   rh   ri   re   anyr   )rj   rw  r   rp   rJ   rx  r/   r"   r  r#   "test_distutils_leave_inplace_files  s    

z5TestCustomBuildExt.test_distutils_leave_inplace_filesN)
r|   r}   r~   r  r^   r   skipifr   r   r  r"   r"   r"   r#   rz    s    
rz  c                 C  s   t jddi t }d|_|  t|}|  tdt	fi }t
| d}||d| t|}|  W d   n1 sBw   Y  tdd	 |jjD sTJ dS )
z7Make sure to display useful debugging tips to the user.rs  r=   r0   SimulatedErr)side_effectrd   Nc                 s  s    | ]}d |v V  qdS )zdebugging-tipsNr"   )r   noter"   r"   r#   r     s    z&test_debugging_tips.<locals>.<genexpr>)r?   r@   rA   r   r   rv  r   rO  type	Exceptionr	   setattrr^   r   rD   r  value	__notes__)rw  rk   rp   rJ   r  simulated_failurero   r"   r"   r#   test_debugging_tips  s   
r  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   r  c              	   G  sZ   ||  }|   tjj||d g |d}|jddddddt|g|tjd	}||fS )
Nr1   r7   r3   r4   r5   r   r6   r8   r_  )r>   r?   r@   rA   rD   rB   r   ra  )re   rH   rG   r/   rz   rI   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   new_dirr"   r"   r#   r     r   z_addsitedirs.<locals>.<genexpr>r   zsitecustomize.pyr:   r;   N)r   tuplerF   )new_dirsr  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   iterrB   r   r   )rM   r   r@   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_symlinkrB   r   statST_INOST_DEV)r  r  	file_stat
other_statr"   r"   r#   rR    s    rR  str_with_pathrB   c                 C  s   |   tjdddS )N/z//)lowerreplacer   sep)r  r"   r"   r#   r\    s   r\  )r  r   r  r   r  r  )r  rB   r  rB   )T
__future__r   r   r   r  r   r   copyr   	importlibr   importlib.machineryr   pathlibr   textwrapr   typingr   unittest.mockr	   uuidr
   jaraco.envsr?   jaraco.pathr^   r@   rJ  setuptools._importlibr   r   !setuptools.command.editable_wheelr   r   r   r   r   r   r   r   setuptools.distr   setuptools.extensionr   setuptools.warningsr   r   r   r   distutils.corer   fixturer$   rE   r   SETUP_SCRIPT_STUBr   rD  r   rK   rQ   rS   rT   r   r   r   r,  r-  rF  filterwarningsr^  uses_networkrc  rd  rf  rz  r  r  r:  r   r   rR  r\  r"   r"   r"   r#   <module>   s    (


G(&Be(  Z1x
S
 
* 



