
    YHh{              
         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jh                  ddg      d        Z5 ed       ed      jm                         ddd ed       ed      ddd id!Z7d"Z8ejr                  ju                  ej                  d#k(  d$%      ejr                  jw                  d&i e7d'e8ie7g      d(               Z<d) Z=d* Z> G d+ d,      Z? G d- d.      Z@d/ ZA G d0 d1      ZBd2 ZC G d3 d4      ZD G d5 d6      ZEejr                  j                  d7      d8        ZGejr                  j                  d9        ZI G d: d;      ZJ G d< d=      ZK G d> d?      ZLd@ ZMejr                  j                  dA      dB        ZNdC ZOdD ZPdE ZQdHdFZRdIdGZSy)J    )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                ,    | j                   dk(  rddgS g S )Nr   --config-settingseditable-mode=strict)param)requests    _/var/www/html/planif/env/lib/python3.12/site-packages/setuptools/tests/test_editable_install.pyeditable_optsr%   *   s    }} #%;<<I    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           	        | dz  }|j                          t        j                  j                  ||       ddddddt	        |      g|}t        |j                  |             g d	}|j                  |      j                         d
k(  sJ |dz  j                  dd       |dz  j                  dd       |j                  |      j                         dk(  sJ y )Nr'   prefixpython-mpipinstall--no-build-isolation-e)r6   r7   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venvr1   r%   projectcmds         r$   test_editable_with_pyprojectrN   {   s      GMMO
KKeG, 	G	 
	C 
$((3-
#C88C= $????##//7/K!!--h-I88C= $====r&   c           	     "   dt        d      ddiddi}t        j                  j                  ||        | dz  }dd	d
dddt	        |      g|}t        |j                  |             g d}|j                  |      j                         dk(  sJ y )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)   r4   r6   r7   r8   r9   r:   r;   )r6   -cz$import pkg, mod; print(pkg.a, mod.b)z4 2r   rB   rC   rD   rE   rF   rG   rH   rJ   rK   r%   r1   rL   rM   s         r$   test_editable_with_flat_layoutrU      s    $ "7+#
E* KKeH- G 	G	 
	C 
$((3-
BC88C= E)))r&   c           	        dt        d      ddi}t        j                  j                  ||        | dz  }dddd	d
dt	        |      g|}t        |j                  |             g d}|j                  |      j                         dk(  sJ y )Nr'   a>                  [build-system]
                requires = ["setuptools", "wheel"]
                build-backend = "setuptools.build_meta"

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

                [tool.setuptools]
                py-modules = ["mod"]
                rP   )r*   r)   r4   r6   r7   r8   r9   r:   r;   )r6   rR   zimport mod; print(mod.b)2rS   rT   s         r$    test_editable_with_single_modulerX      s    $ 
E& KKeH- G 	G	 
	C 
$((3-
6C88C= C'''r&   c                      e Zd Zd Zej
                  j                  dd      ej
                  j                  dd      d               Zy)TestLegacyNamespacesc                P   t        j                  t        d      }|dz  }|j                          d}|D ]  }t	        j
                  ||d      }|5  |j                         5 }|j                  |       t        dd	      }	t        |	      }
|
j                          |
j                  d
      j                  }|
j                  ||       d d d        d d d         t        |j                  d            }t!        |      t!        |      k(  sJ y # 1 sw Y   GxY w# 1 sw Y   xY w)Nz .*namespace_packages parameter.*matchz.installation_dir)z	myns.pkgAz	myns.pkgBmyns.n.pkgAmyns.n.pkgB42)versionr2   config)
stop_after	dist_infoz*-nspkg.pth)pytestwarnsr   rA   r   build_namespace_packagecontextchdirr   r   finalize_optionsget_finalized_commandname_install_namespaceslistgloblen)selfrJ   monkeypatchdeprecationinstallation_direxamplesrl   rQ   ctxdistrM   editable_namer1   s                r$   test_nspkg_file_is_uniquez.TestLegacyNamespaces.test_nspkg_file_is_unique   s(   ll(0R
 $&99 
  	ID44XtTRC Ik113 Is		# A$T*$$& # 9 9+ F K K''(8-HI I I	I %**=9:5zS]***I I I Is%   D#A'D
DDDD%	impl)pkg_resourcesns)zmyns.nc           
        d}t        j                  || d|      }t        j                  || d|      }|dz  j                  |d       |dz  j                  |d       |dd }	|	j                  d	       |j	                  d
dddt        |      g|	       |j	                  d
ddddt        |      g|	       |j	                  d
dd| d| dg       |j	                  g d       y)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)rz   z.pkgBr*   r=   r>   Nr:   r6   r7   r8   r9   r;   rR   zimport z.pkgA; import )r6   rR   zimport pkg_resources)r   rg   rI   appendrG   rE   )
rq   rK   rJ   r|   rz   r%   build_systempkg_Apkg_Boptss
             r$   !test_namespace_package_importablez6TestLegacyNamespaces.test_namespace_package_importable  s    $
 228t5\PTU228t5\PTU	!	!--lW-M	!	!--lW-MQ*+(D%CJFFG(D%D#e*LtLM(DGB4~bT"GHI9:r&   N)__name__
__module____qualname__ry   re   markparametrizer    r&   r$   rZ   rZ      sM    +4 [[	
 [[T;/; 0;r&   rZ   c                      e Zd Zd Zd Zd Zy)TestPep420Namespacesc           
     4   t        j                  |d      }t        j                  |d      }|dd }|j                  d       |j                  ddddt	        |      g|       |j                  ddddd	t	        |      g|       |j                  g d
       y)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.
        r^   r_   Nr:   r6   r7   r8   r9   r;   )r6   rR   z&import myns.n.pkgA; import myns.n.pkgB)r   build_pep420_namespace_packager~   rG   rE   )rq   rK   rJ   r%   r   r   r   s          r$   r   z6TestPep420Namespaces.test_namespace_package_importable-  s     99(MR99(MRQ*+(D%CJFFG(D%D#e*LtLMKLr&   c           
        dt        d      ddidi}t        j                  j                  ||       |dz  }t	        j
                  |d      }t	        j
                  |d      }|d	d	 }|j                  d
       |j                  ddddt        |      g|       |j                  dddddt        |      g|       |j                  dddddt        |      g|       |j                  g d       y	)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,   r4   r_   zmyns.n.pkgCNr:   r6   r7   r8   r9   r;   )r6   rR   z#from myns.n import pkgA, pkgB, pkgC)	r   rB   rC   rD   r   r   r~   rG   rE   )	rq   rK   rJ   r%   r1   r   r   pkg_Cr   s	            r$   &test_namespace_created_via_package_dirz;TestPep420Namespaces.test_namespace_created_via_package_dir<  s     "(# &w/
& 	%16!99(MR99(MR Q*+(D%CJFFG(D%D#e*LtLM(D%D#e*LtLMHIr&   c                t   dt        d      ddddddt        d   d	i}t        j                  j	                  ||
       |dz  }dg}|j                  ddddddt        |      g|       |j                  g d      }|j                         dk(  sJ d}|j                  ddt        |      g      }d|v sJ y)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+   r4   r:   r6   r7   r8   -vr9   r;   )r6   rR   z'from mypkg.n import pkgA; print(pkgA.a)1z}        try:
            import mypkg.other
        except ImportError:
            print("mypkg.other not defined")
        rR   zmypkg.other not definedN)r   EXAMPLErB   rC   rD   rG   rE   rH   )rq   rK   rJ   r1   r   r   outrM   s           r$   0test_namespace_accidental_config_in_lenient_modezETestPep420Namespaces.test_namespace_accidental_config_in_lenient_mode^  s     "(# $& '')#*  '}5/
6 	%16! ''(D%y$E
RTRShhRSyy{c!!! hh$s45(C///r&   N)r   r   r   r   r   r   r   r&   r$   r   r   ,  s    M JD00r&   r   c           
        | dz  }t         j                  D cg c]P  }d|v rJ|j                  t         j                        r+|t	        |      j                  t         j                        z  R }}|D ]  }|j                  d        t        |       t        t        j                  t        j                  j                  t        t        |                  }t         j                  dddd	t        |      d
t        |      dg	|}t!        j"                  ||       t%        j&                         dk(  rdnd}	||	z  dz  }
t!        j"                  |
g|       yc c}w )z>
    Editable install to a prefix should be discoverable.
    r5   zsite-packagesT)parents)
PYTHONPATHr7   r8   r9   
--editablez--prefixr:   )envWindowsScriptsbinsampleN)sysrC   
startswithr5   r   relative_torA   _addsitedirsdictosenvironpathsepjoinmaprE   
executable
subprocess
check_callplatformsystem)rJ   sample_projectr%   r5   rC   site_packages_allspr   rM   r   exes              r$   test_editable_with_prefixr     s7     F
 HHd"tszz'B 	d''

33    
 "#
rzzbjjooc#?P6Q&R
SCNF 
C #3'  (I5)5C
3,
!C3%S)=s   AEc                  R    e Zd ZdZd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zd Zd Zy)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                6    i }t        |||        |d           y )Nr9   )exec)rq   finderlocs      r$   install_finderz!TestFinderTemplate.install_finder  s    VS#Ir&   c                   ddddididdid}t         j                  j                  ||	       t        |d
z        t        |dz        d}t	        t        t                     |i       }t        j                         5  t        j                         5  dD ]"  }t        j                  j                  |d        $ | j                  |       t        d      }t        d      }t        d      }|j                  dk(  sJ |j                  dk(  sJ t        |dz  j                               }	t!        ||	       d d d        d d d        y # 1 sw Y   xY w# 1 sw Y   y xY w)Npkg1r   mod1.pyza = 42)r(   subpkgmod2.pyza = 43src1src2r4   z	src1/pkg1z	src2/mod2)r   mod2)r   pkg1.subpkgpkg1.subpkg.mod1r   r   r   r   *   +   zsrc1/pkg1/subpkg)rB   rC   rD   rE   r   r   r   
save_pathssave_sys_modulesr   modulespopr   r   aresolveassert_path)
rq   rJ   r1   mappingtemplatemodmod1r   r   expecteds
             r$   test_packagesz TestFinderTemplate.test_packages  sS    #%((3 )
 	%1 ;./;./
 $CL'2>  " 	*H$=$=$? 	*J +T*+ ) !34D (D"=1F66R<<66R<<H'99BBDEH)	* 	* 	* 	* 	* 	*s%   ?EB$E	8E	E	EEc                   ddddi}t         j                  j                  ||       dt        |dz        i}dg i}t	        t        t                     ||      }t        j                         5  t        j                         5  dD ]"  }t        j                  j                  |d        $ | j                  |       t        d      }t        j                  |      d	z  }t        |dz  j!                               }	t#        ||	       |j$                  d
k(  sJ |j'                  d      dk(  sJ 	 d d d        d d d        y # 1 sw Y   xY w# 1 sw Y   y xY w)NrQ   a = 13abc)r(   text.txtr4   ns.othernamer|   r|   r   r      r=   r>   )rB   rC   rD   rE   r   r   r   r   r   r   r   r   r   r   importlib_resourcesr1   r   r   r   	read_text)
rq   rJ   r1   r   r   r   r   rQ   textr   s
             r$   test_namespacez!TestFinderTemplate.test_namespace  s7   eDE%1!3x%'7#89BZ
#CL':F  " 	=H$=$=$? 	=- +T*+ )/C&,,S1J>DHu,5578HX&55B;; >>7>3u<<<	= 	= 	= 	= 	= 	=s%   /EB,E1EE	EEc                   ddddiiidddiid}t         j                  j                  ||       t        |d	z        t        |d
z        d}dt        |dz        t        |dz        gi}t	        t        t                     ||      }t        j                         5  t        j                         5  dD ]"  }t        j                  j                  |d        $ | j                  |       t        d      }t        d      }t        |d	z  j                               }	t        ||	       |j                   dk(  sJ |j"                  dk(  sJ 	 d d d        d d d        y # 1 sw Y   xY w# 1 sw Y   y xY w)Nr|   r   r(   r   r   b = 37r   r4   zsrc1/ns/pkg1zsrc2/ns)ns.pkgAr|   r   r   )r|   r   ns.mod2r   r   r   %   )rB   rC   rD   rE   r   r   r   r   r   r   r   r   r   r   r   r   r   b)
rq   rJ   r1   r   namespaces_r   r   r   r   r   s
             r$   test_combine_namespacesz*TestFinderTemplate.test_combine_namespaces  se   F]H$=>?Ix01
 	%1 8n45h*+
 c(V"34c(V:K6LMN#CL';G  " 	 H$=$=$? 	 3 +T*+ ) +D +DH~5>>@AHh'66R<<66R<<	  	  	  	  	  	 s%   E*3BEE*E'	#E**E3c                L   dddiidddiid}t         j                  j                         }|j                  |      5  t         j                  j	                  |       dd	d
dddgd}t        |      }t        |t        t                           }t        d |j                         D              }ddd       t        j                         5  t        j                         5  d   D ]"  }t        j                  j!                  |d       $ | j#                         t%        d      }	t%        d      }
t        |dz  j'                               }t        t)        |	j*                        j'                               |k(  sJ t        |dz  j'                               }t        t)        |
j*                        j'                               |k(  sJ |	j,                  dk(  sJ |
j.                  dk(  sJ 	 ddd       ddd       y# 1 sw Y   SxY w# 1 sw Y   xY w# 1 sw Y   yxY w)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              3  J   K   | ]  \  }}|j                  d       s|  yw)z.pyNendswith).0kvs      r$   	<genexpr>zDTestFinderTemplate.test_combine_namespaces_nested.<locals>.<genexpr>.  s      WdaQZZPUEVWs   ##Nr   zdifferent_name.my_modulez different_name.subpkg.my_module2zsrc/my_package/my_module.pyzsrc2/my_package2/my_module2.pyr   r   )rB   rC   DirectoryStackrh   rD   r   r   rE   r   nextget_implementationr   r   r   r   r   r   r   r   r   r   __file__r   r   )rq   rJ   r1   stackattrsrw   r   coder   r   r   r   s               r$   test_combine_namespaces_nestedz1TestFinderTemplate.test_combine_namespaces_nested  s    !>8"<="_h$?@

 **,]]8$ 	XKKe$*&6-?  ./FGE  &D$T3uw<8FWf&?&?&AWWD	X   " 	 H$=$=$? 	 Z( +T*+ % !;<D !CDDH'DDMMOPHtDMM*2245AAAH'GGPPRSHtDMM*2245AAA66R<<66R<<	  	  	 	X 	X	  	  	  	 s1   A3HH!DH0HHH	HH#c                D   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                  ||
       i }dt        |dz        gi}t	        t        t                     ||      }d dD        }t        j                         5  t        j                         5  dddg|D ]"  }t        j                  j                  |d        $ | j                  |       t        d      }|j                  dk(  sJ t        j                   t"              5  t        d       d d d        t        j                  j%                  t        |dz               t        d      }	|	j                  dk(  sJ t        j                   t"              5  t        d       d d d        t        j                  j%                  t        |dz               t        d      }
|
j                  dk(  sJ 	 d d d        d d d        y # 1 sw Y   xY w# 1 sw Y   nxY w# 1 sw Y   *xY w# 1 sw Y   y xY w)Nparentchildzone.pyx = 1ztwo.pyx = 2zthree.pyzx = 3)project1project2project3r4   zproject1/parentc              3  &   K   | ]	  }d |   yw)zparent.child.Nr   )r   rl   s     r$   r   zCTestFinderTemplate.test_dynamic_path_computation.<locals>.<genexpr>M  s     K4-v&Ks   )onetwothreezparent.childzparent.child.oner   zparent.child.twor     zparent.child.threer     )rB   rC   rD   rE   r   r   r   r   r   r   r   r   r   r   xre   raisesImportErrorr~   )rq   rJ   r1   r   r   r   modsr   r  r  r  s              r$   test_dynamic_path_computationz0TestFinderTemplate.test_dynamic_path_computationA  s    "Gh-@#AB!Gh-@#AB!Gj'-B#CD

 	%1#h1B&B"C!DE#CL';GK3JK  " 	 H$=$=$? 	  ..H4H +T*+ ) 23C55A::{+ 2012 HHOOC: 567 23C55A::{+ 4234 HHOOC: 567!"67E77a<<+	  	  	 2 24 4!	  	  	  	 sW   HA4H
G2A(H
G>AH
!H2G;7H
>HH

H	HHc                *   dddii}t         j                  j                  ||       dt        |dz        i}t	        t        t                     |i       }t        j                         5  t        j                         5  t        j                  j                  dd        | j                  |       t        j                  t        d      5  t!        d       d d d        d d d        d d d        y # 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   y xY w)NrQ   r(   zfrom . import pkgr4   r\   rB   rC   rD   rE   r   r   r   r   r   r   r   r   r   re   r  r  r   rq   rJ   r1   r   r   s        r$   test_no_recursionz$TestFinderTemplate.test_no_recursione  s     2

 	%1 3x%'(
 $CL'2>  " 	%H$=$=$? 	%KKOOE4(){%8 %e$%		% 	% 	%% %		% 	% 	% 	%s=   *D	?AC=C1C= D	1C:6C==D	D		Dc                p   ddddidi}t         j                  j                  ||       dt        |dz        i}t	        t        t                     |i       }t        j                         5  t        j                         5  t        j                  j                  dd        t        j                  j                  dd        | j                  |       t        j                  t        d      5  t!        d       d d d        d d d        d d d        y # 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   y xY w)	Nfoor   r(   )r(   barr4   zfoo.barr<   r\   r  r  s        r$   test_similar_namez$TestFinderTemplate.test_similar_namez  s   !!2
 	%1 3x%'(
 $CL'2>  " 	(H$=$=$? 	(KKOOE4(KKOOIt,){(; (h'(	( 	( 	(
( (	( 	( 	( 	(s=   -D,A-D /D;D D,DD  D)	%D,,D5c                   dddddddi}t         j                  j                  ||       dt        |dz        i}t	        t        t                     |i       }t        j                         5  t        j                         5  t        j                  j                  dd        | j                  |       t        j                  t        d	      5  t!        d
       d d d        t        j                  t        d	      5  t!        d       d d d        t        j                  t        d	      5  t!        d       d d d        t        j                  t        d	      5  t!        d       d d d        t        j                  t        d	      5  t!        d       d d d        t!        d      }|j"                  dk(  sJ t!        d      }|j"                  dk(  sJ 	 d d d        d d d        y # 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   OxY w# 1 sw Y   y xY w)Nr  r   r  r	  )r(   lowercase.py)r(   r!  r  r4   z'FOO'r\   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  )rB   rC   rD   rE   r   r   r   r   r   r   r   r   r   re   r  r  r   r  )rq   rJ   r1   r   r   r   s         r$   test_case_sensitivityz(TestFinderTemplate.test_case_sensitivity  s   ! '#%$+	
 	%13x%'(
 $CL'2>  " 	H$=$=$? 	KKOOE4(){': %e$% {2EF /o./ {2KL 3123 {-@ 3123 {': 3123  0C55A:: 34C55A::/	 	 	% %/ /3 33 33 3!	 	 	 	s   /H4AH(G+#H( G8#H(/H;#H(H*#H(HA H(H4+G50H(8H=H(H	H(HH(H%!H((H1	-H44H=c                ,   ddddddi}t         j                  j                  ||       dt        |dz        i}d	g i}t	        t        t                     ||      }t        j                         5  t        j                         5  d
D ]"  }t        j                  j                  |d        $ | j                  |       t        d      }t        |dz  j                               }t        ||       |j                   dk(  sJ t        d      }	|	j"                  dk(  sJ t        d      }
|
j$                  dk(  sJ t'        j(                  t*        d      5  t        d       d d d        t'        j(                  t*        d      5  t        d       d d d        t'        j(                  t*        d      5  t        d       d d d        d d d        d d d        y # 1 sw Y   xxY w# 1 sw Y   UxY w# 1 sw Y   2xY w# 1 sw Y   6xY w# 1 sw Y   y xY w)NrQ   r   r   zc = 42)r(   zbar.py)r(   r  r4   r   r|   r   r   zns.othername.foor   zns.othername.foo.barr   z'NS'r\   zNS.othername.fooz'ns\.othername\.FOO\'zns.othername.FOOz'ns\.othername\.foo\.BAR\'zns.othername.foo.BAR)rB   rC   rD   rE   r   r   r   r   r   r   r   r   r   r   r   r   r   r   cre   r  r  )rq   rJ   r1   r   r   r   r   rQ   r   r  r  s              r$   test_namespace_case_sensitivityz2TestFinderTemplate.test_namespace_case_sensitivity  s   '#+&
 	%1!3x%'7#89BZ
#CL':F  " 	6H$=$=$? 	6- +T*+ )/CHu,5578HX&55B;; 23C55B;; 67C55B;;{&9 2012 {2LM 2012 {2RS 6456-	6 	6 	6 2 22 26 6-	6 	6 	6 	6sm   2H
CG>G##G>G&#G>5G2G>	H
G#G>&G/+G>2G;7G>>H	H

Hc                   dddddddidii}t         j                  j                  ||	       dt        |d
z        i}t	        t        t                     |i       }t        j                         5  t        j                         5  dD ]"  }t        j                  j                  |d       $ | j                  |       t        d      }|j                  dk(  sJ t        d      }|j                  dk(  sJ t!        j"                  t$              5  t        d       ddd       ddd       ddd       y# 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   yxY w)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
componentsr4   z	src/mypkg)r'   zmypkg.configmypkg.helloworldzmypkg.componentsmypkg.components.configmypkg.components.helloworldNr+  r   r*  r   r,  )rB   rC   rD   rE   r   r   r   r   r   r   r   r   r   r   r   r   re   r  r  )rq   rJ   r1   r   r   r   rb   
helloworlds           r$   test_intermediate_packagesz-TestFinderTemplate.test_intermediate_packages  sL    #%!)%-#X#		
 	%1C; 678#CL'2>  " 	=H$=$=$? 	= + T*+ )"#<=F88r>!>&'9:J<<2%%%{+ =;<='	= 	= 	=&= ='	= 	= 	= 	=s=   1EB
ED5E$E5D>:EE
	EEN)r   r   r   __doc__r   r   r   r   r  r  r  r  r#  r&  r.  r   r&   r$   r   r     sC    

*@=. 6) V" H%*(0'R'6R*=r&   r   c           
        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}g d}t        |||       }|t	        | dz        t	        | dz        t	        | dz        t	        | dz        t	        | dz        t	        | dz        dk(  sJ t        t        t        ||                  }|ddhk(  sJ t        t        |            }|h dk(  sJ y)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_anotherr4   r6  r7  r8  )a.b.ca.b.c.x.y.z	m.n.o.p.q)r   a.br9  	a.b.c.x.yr:  r4  zd.er5  f.gzf.g.hr;  r   r4  r5  )r   r9  r:  r4  r5  r;  r>  >   m.nm.n.oa.b.c.xm.n.o.pmr<  r=  N)	rB   rC   rD   r   rE   setr   r   r   )rJ   r1   r   r   rootsr|   s         r$   test_pkg_rootsrF    s;    "8,WE$M8+DEC-345+!<0%{3E KKeH- "K
H  +x@EC X'(8i/0C C M12    
T"8U34	5B#u	%e,	-BPPPPr&   c            
         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      z   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      e	j                  j                  dej                               d               Zy)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+   rK  r,   z                [tool.setuptools]
                packages = ["mypkg", "mypkg.subpackage"]

                [tool.setuptools.package-dir]
                "mypkg.subpackage" = "other"
                r   )r(   r   rJ  )r*   r+   rK  r'   r6  )r   rJ  )flat-layout
src-layoutcustom-layout	namespacer-   r.   r/   layoutc                   t        d||| j                  |   g| \  }}d}|j                  ddt        |      g      }d|v sJ d}	|j                  ddt        |	      g      }d|v sJ d}
|j                  ddt        |
      g      }d	|v sJ t	        |j                  d
            }t	        |j                  d            }t	        |j                  d            }|j                  dd       |j                  dd       |j                  dd       |j                  ddt        |	      g      }d|vsJ d|v sJ |j                  ddt        |
      g      }d	|vsJ d|v sJ y )Nr'   zj        try:
            import otherfile
        except ImportError as ex:
            print(ex)
        r6   rR   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"))
        rI  
**/mod1.py
**/mod2.py**/resource_file.txtzvar = 17r=   r>   z	var = 781zresource 374z17 781)install_projectEXAMPLESrG   r   r   ro   rI   )rq   rJ   rK   rQ  r%   rL   _cmd_import_errorr   cmd_get_varscmd_get_resourcer   r   resource_files                 r$   test_editable_installz*TestOverallBehaviour.test_editable_install  s    %T8T]]6%:
=J


 hh$/?(@AB,333 hh$|(<=>#~~ hh$/?(@AB### GLL./GLL./W\\*@AB
W5g6  ' Bhh$|(<=>c!!!3hh$/?(@ABC'''$$$r&   N)r   r   r   	PYPROJECTr   r   rL  __annotations__rW  re   r   xfailr   r   r   keysr]  r   r&   r$   rH  rH  B  s\   I !+}-!!%%2
	#K   #$Y/"=1[12	
 %Y/	 #=1!&w/	: !),7#
( %Y/"=1*73I>"-g"6|"D	

7&HP [[s||x/8NO[[Xx}}70% 8 P0%r&   rH  c                  ~    e Zd Z eej
                  d         Zedxx    ed      z  cc<   ded   d   d<   d Zd	 Z	y
)TestLinkTreerN  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                `   t         j                  j                  | j                  |       t	        |      5  d}t        ddi      }|j                          t               }|dz  }|dz  }|j                          |j                          |j                  d      }d|_
        t        |      |_        |j                          |j                         }|j                         }	t!        ||||      }
 |
|||	       t#        |j%                  d	            }|d
z  }t'        ||       t#        |j%                  d      d       J t#        |j%                  d      d       J t#        |j%                  d      d       J t#        |j%                  d      d       J 	 d d d        y # 1 sw Y   y xY w)Nr4   zmypkg-3.14159r   r   z.auxz.buildbuild_pyTrS  zsrc/mypkg/mod1.pyz**/subpackagerT  rU  z**/resource.not_in_manifest)rB   rC   rD   FILES_Pathr   parse_config_filesr
   rA   get_command_objeditable_moderE   	build_libensure_finalizedget_outputsget_output_mappingr   r   ro   assert_link_to)rq   rJ   rl   rw   wheelauxrD   rf  outputsoutput_mapping	make_treer   r   s                r$   test_generated_treez TestLinkTree.test_generated_tree  s   $**X68_ 	O"D <=D##%FEV#Cx'EIIKKKM++J7H%)H"!$UH%%'**,G%88:N!$c59IeWn5./D"55H4*148@@@.5===!78$?GGG!>?FNNN;	O 	O 	Os   E#F$$F-c                   ddg}t        d||| j                  g|  |j                  g d      }d|v sJ d}|j                  ddt        |      g      }d	|v sJ d
}|j                  ddt        |      g      }d|v sJ d|v sJ y )Nr    r!   r'   r6   rR   z(import mypkg.mod1; print(mypkg.mod1.var)r`   zv        try:
            from mypkg import subpackage
        except ImportError as ex:
            print(ex)
        r6   rR   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 directoryrd  )rV  rg  rG   r   )rq   rJ   rK   r   r   rY  r[  s          r$   test_strict_installz TestLinkTree.test_strict_install  s    #%;<xCdChhSTs{{ hh$/?(@AB0C777 hh$/?(@AB*c111)S000r&   N)
r   r   r   r   rH  rW  rg  r   rv  rz  r   r&   r$   rc  rc    sW    )22<@AE	
v
	   9>E%L45 OD1r&   rc  z9ignore:.*compat.*:setuptools.SetuptoolsDeprecationWarningc                H   ddg}t         j                  d   }t        d|| |g|  |j                  g d      }d|v sJ t	        t        |             }dD ]%  }t	        |j                  dd	|g            }||v r%J  d
}|j                  dd	t        |      g      }d|v sJ y )Nr    zeditable-mode=compatrO  r'   rx  r`   )z"import otherfile; print(otherfile)zimport other; print(other)zimport mypkg; print(mypkg)r6   rR   zc    try:
        from mypkg import subpackage;
    except ImportError as ex:
        print(ex)
    ry  )rH  rW  rV  rG   comparable_pathrE   r   )rJ   rK   r   r1   r   expected_pathrM   s          r$   test_compat_installr~    s      !78D ))/:EGT8U:T:
((O
PC3;;#CM2M $
 dhh$'<=>###$C ((HdF3K0
1C,333r&   c                    dddddd| g|}|j                  |t        j                         |j                  g d      }d	|v sJ y
)z3Ensure editable installs work with pbr, issue #3500r6   r7   r8   r   r9   r   stderr)r6   rR   zimport mypkg.hellozHello world!N)rG   r   STDOUT)pbr_packagerK   r%   rM   r   s        r$   test_pbr_integrationr  .  s_     		 
	C 	HHS**H+
((9
:CS   r&   c                  L    e Zd ZdZi ej
                  d   d ed      iZd Zy)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.
    rM  r2   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                    t        d||| j                        \  }}d|v sJ d|v sJ |j                  g d      }d|v sJ y)z>Ensure that errors in custom build_py are reported as warningsr'   r   zValueError: TEST_RAISErx  r`   N)rV  rg  rG   )rq   rJ   rK   rX  r   s        r$   test_safeguarded_from_errorsz.TestCustomBuildPy.test_safeguarded_from_errors_  sS     !$$**E3-444'3...hhSTs{{r&   N)	r   r   r   r/  rH  rW  r   rg  r  r   r&   r$   r  r  @  s:    

'
'
6F
E$r&   r  c                      e Zd Zd Zd Zy)TestCustomBuildWheelc                Z    |j                  d      } G d d|      }||j                  d<   y )Nbdist_wheelc                       e Zd Z fdZ xZS )ETestCustomBuildWheel.install_custom_build_wheel.<locals>.MyBdistWheelc                Z    | j                   j                  d      rd}t        |          S )Nzmacosx-zmacOS platform)	plat_namer   superget_tag)rq   rX  	__class__s     r$   r  zMTestCustomBuildWheel.install_custom_build_wheel.<locals>.MyBdistWheel.get_tago  s)     >>,,Y7(Aw((r&   )r   r   r   r  __classcell__)r  s   @r$   MyBdistWheelr  n  s    ) )r&   r  )get_command_classcmdclass)rq   rw   bdist_wheel_clsr  s       r$   install_custom_build_wheelz/TestCustomBuildWheel.install_custom_build_wheelk  s.    00?	)? 	) (4m$r&   c                b   t         j                  j                  ddi       t               }d|_        |j                          | j                  |       t        |      }|j                          |j                          t        t        t               j                  d                  }d|v sJ y )N	module.pyr@   r2   
dist/*.whleditable)rB   rC   rD   r   r   set_defaultsr  r   rm  rG   rE   r   r   ro   )rq   
tmpdir_cwdrw   rM   
wheel_files        r$   test_access_plat_namez*TestCustomBuildWheel.test_access_plat_namex  s     	;12~%''-T"	dfkk,789
Z'''r&   N)r   r   r   r  r  r   r&   r$   r  r  j  s    4(r&   r  c                  r    e Zd Zd Zej
                  j                  ej                  dk7  d      d        Z	y)TestCustomBuildExtc                D    ddl m}  G d d|      }||j                  d<   y )Nr   )	build_extc                      e Zd Zy)ITestCustomBuildExt.install_custom_build_ext_distutils.<locals>.MyBuildExtN)r   r   r   r   r&   r$   
MyBuildExtr    s    r&   r  r  )distutils.command.build_extr  r  )rq   rw   build_ext_clsr  s       r$   "install_custom_build_ext_distutilsz5TestCustomBuildExt.install_custom_build_ext_distutils  s!    J	 	 &0k"r&   linuxz(compilers may fail without correct setupr/   c                n   t         j                  j                  ddi       dt        ddg      gi}t	        |      }d|_        |j                          | j                  |       t        |      }|j                          |j                          t        t        t               j                  d                  }d|v sJ t               j                  d      D cg c]  }|j                  d	k7  s| }}t!        |      d
k(  sJ |d   j"                  t%        fdt&        D              sJ y c c}w )Nzmodule.cr   ext_modulesmoduler2   r  r  zmodule.*z.cr   r   c              3  @   K   | ]  }j                  |        y wNr   )r   extrl   s     r$   r   zHTestCustomBuildExt.test_distutils_leave_inplace_files.<locals>.<genexpr>  s     D#4==%Ds   )rB   rC   rD   r   r   r   r  r  r   rm  rG   rE   r   r   ro   suffixrp   rl   anyr   )	rq   r  r  rw   rM   r  pr1   rl   s	           @r$   "test_distutils_leave_inplace_filesz5TestCustomBuildExt.test_distutils_leave_inplace_files  s
    	:r*+Ih=>
 E"%//5T"	dfkk,789
Z''' FKK
3Hqqxx47GHH5zQQx}}D1CDDDD Is   D22D2N)
r   r   r   r  re   r   skipifr   r   r  r   r&   r$   r  r    s@    0 [[(R  EEr&   r  c                   t         j                  j                  ddi       t               }d|_        |j                          t        |      }|j                          t        dt        fi       }t         |             }|j                  |d|       t        j                  |      5 }|j                          ddd       t        d j                   j"                  D              sJ y# 1 sw Y   2xY w)	z7Make sure to display useful debugging tips to the user.r  r@   r2   SimulatedErr)side_effectrk   Nc              3  $   K   | ]  }d |v  
 yw)zdebugging-tipsNr   )r   notes     r$   r   z&test_debugging_tips.<locals>.<genexpr>  s     HD4'Hs   )rB   rC   rD   r   r   r  r   rm  type	Exceptionr
   setattrre   r  rG   r  value	__notes__)r  rr   rw   rM   r  simulated_failurerv   s          r$   test_debugging_tipsr    s    
KK{H-.>D!D

Cb9L846GH	|	$ 	HCII4G4GHHHH s   )C++C4errorc                 >    t        d      } t        | t              sJ y)z>Ensure _encode_pth function does not produce encoding warningsu   tkmilan_ç_utf8N)r   
isinstancebytes)contents    r$   test_encode_pthr    s     +,Ggu%%%r&   c                    || z  }|j                          t        j                  j                  ||       g |d}|j	                  ddddddt        |      g|t        j                  	      }||fS )
Nr4   r:   r6   r7   r8   r   r9   r;   r  )rA   rB   rC   rD   rG   rE   r   r  )rl   rK   rJ   r1   r   rL   r   s          r$   rV  rV    s~    oGMMO
KKeG,*T*)*D
((	4is7|KdK    C C<r&   c                ~    dj                  dt        d | D              z         }| d   dz  j                  |d       y)	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              3  N   K   | ]  }d t        j                  |      d  yw)zsite.addsitedir()N)r   fspath)r   new_dirs     r$   r   z_addsitedirs.<locals>.<genexpr>  s$     Sw"299W#5"8:Ss   #%r   zsitecustomize.pyr=   r>   N)r   tuplerI   )new_dirsr  s     r$   r   r     sH     ii
S(S
S	TG a[%%11'G1Lr&   c                    | j                   rJt        t        | j                         d       }|r(t        t	        |      j                               |k(  sJ y y y r  )__path__r   iterrE   r   r   )rQ   r   rC   s      r$   r   r     sK    
||D&-tDz))+,888  r&   c                t   | j                         r6t        | j                               t        |j                               k(  sJ y | j                         }|j                         }|t        j                     |t        j                     k(  sJ |t        j
                     |t        j
                     k(  sJ y r  )
is_symlinkrE   r   statST_INOST_DEV)filer6  	file_stat
other_stats       r$   rp  rp    s    4<<>"c%--/&::::IIK	ZZ\
%DKK)@@@@%DKK)@@@@r&   c                ~    | j                         j                  t        j                  d      j                  dd      S )N/z//)lowerreplacer   sep)str_with_paths    r$   r|  r|    s/     ((5==dCHHr&   )r  r   r6  r   returnNone)r  rE   r  rE   )T
__future__r   r   r   r  r   r   copyr   	importlibr   importlib.machineryr   pathlibr   textwrapr   typingr	   unittest.mockr
   uuidr   jaraco.envsrB   jaraco.pathre   rC   rh  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%   rH   r   SETUP_SCRIPT_STUBr   r`  r   rN   rU   rX   rZ   r   r   r   rF  rH  rc  filterwarningsr~  uses_networkr  r  r  r  r  r  rV  r   r   rp  r|  r   r&   r$   <module>r     sZ   " 	    
  # 2          B	 	 	 ) * < " $ ),- . 	< 	 eg(6!
 "	 %/
SDN 7  3<<8+4JK272J 12> L>2%*P#(L?; ?;Db0 b0J%*PU= U=p
.Qbu% u%pP1 P1f WX4 Y4@ ! !"' 'T( (:E E@I$ G$& %&	
M 9AIr&   