
    |g(              
          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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l,m-Z-m.Z. d dl/m0Z0  ejb                  ddg      d        Z2 ed       ed      jg                         ddd ed       ed      dddidZ4d Z5ejl                  jo                  ej                  d!k(  d"#      ejl                  jq                  d$i e4d%e5ie4g      d&               Z9d' Z:d( Z; G d) d*      Z< G d+ d,      Z=d- Z> G d. d/      Z?d0 Z@ G d1 d2      ZA G d3 d4      ZBejl                  j                  d5      d6        ZDd7 ZE G d8 d9      ZF G d: d;      ZG G d< d=      ZHd> ZIejl                  j                  d?      d@        ZJdA ZKdB ZLdC ZMdDedEefdFZNdGeOdHeOfdIZPy)J    N)deepcopy)import_module)EXTENSION_SUFFIXES)Path)dedent)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                 ,    | j                   dk(  rddgS g S )Nr   --config-settingseditable-mode=strict)param)requests    c/var/www/html/pythonbot/venv/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)r5   r6   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cmds         r#   test_editable_with_pyprojectrM   y   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(   r3   r5   r6   r7   r8   r9   r:   )r5   -cz$import pkg, mod; print(pkg.a, mod.b)z4 2r   rA   rB   rC   rD   rE   rF   rG   rI   rJ   r$   r0   rK   rL   s         r#   test_editable_with_flat_layoutrT      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"]
                rO   )r)   r(   r3   r5   r6   r7   r8   r9   r:   )r5   rQ   zimport mod; print(mod.b)2rR   rS   s         r#    test_editable_with_single_modulerW      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)versionr1   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)selfrI   monkeypatchdeprecationinstallation_direxamplesrk   rP   ctxdistrL   editable_namer0   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)ry   z.pkgBr)   r<   r=   Nr9   r5   r6   r7   r8   r:   rQ   zimport z.pkgA; import )r5   rQ   zimport pkg_resources)r   rf   rH   appendrF   rD   )
rp   rJ   rI   r{   ry   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__rx   rd   markparametrizer    r%   r#   rY   rY      sM    +4 [[	
 [[T;/; 0;r%   rY   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^   Nr9   r5   r6   r7   r8   r:   )r5   rQ   z&import myns.n.pkgA; import myns.n.pkgB)r   build_pep420_namespace_packager}   rF   rD   )rp   rJ   rI   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+   r3   r^   zmyns.n.pkgCNr9   r5   r6   r7   r8   r:   )r5   rQ   z#from myns.n import pkgA, pkgB, pkgC)	r   rA   rB   rC   r   r   r}   rF   rD   )	rp   rJ   rI   r$   r0   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*   r3   r9   r5   r6   r7   -vr8   r:   )r5   rQ   z'from mypkg.n import pkgA; print(pkgA.a)1z}        try:
            import mypkg.other
        except ImportError:
            print("mypkg.other not defined")
        rQ   zmypkg.other not definedN)r   EXAMPLErA   rB   rC   rF   rD   rG   )rp   rJ   rI   r0   r   r   outrL   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.
    r4   zsite-packagesT)parents)
PYTHONPATHr6   r7   r8   z
--editablez--prefixr9   )envWindowsScriptsbinsampleN)sysrB   
startswithr4   r   relative_tor@   _addsitedirsdictosenvironpathsepjoinmaprD   
executable
subprocess
check_callplatformsystem)rI   sample_projectr$   r4   rB   site_packages_allspr   rL   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 )Nr8   )exec)rp   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src2r3   z	src1/pkg1z	src2/mod2)r   mod2)r   pkg1.subpkgpkg1.subpkg.mod1r   r   r   r   *   +   zsrc1/pkg1/subpkg)rA   rB   rC   rD   r   r	   r   
save_pathssave_sys_modulesr   modulespopr   r   aresolveassert_path)
rp   rI   r0   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)NrP   a = 13abc)r'   text.txtr3   ns.othernamer{   r{   r   r      r<   r=   )rA   rB   rC   rD   r   r	   r   r   r   r   r   r   r   r   importlib_resourcesr0   r   r   r   	read_text)
rp   rI   r0   r   r   r   r   rP   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   r3   zsrc1/ns/pkg1zsrc2/ns)ns.pkgAr{   r   r   )r{   r   ns.mod2r   r   r   %   )rA   rB   rC   rD   r   r	   r   r   r   r   r   r   r   r   r   r   r   b)
rp   rI   r0   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   )rA   rB   DirectoryStackrg   rC   r   r   rD   r	   nextget_implementationr   r   r   r   r   r   r   r   r   r   __file__r   r   )rp   rI   r0   stackattrsrv   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project3r3   zproject1/parentc              3   &   K   | ]	  }d |   yw)zparent.child.Nr   )r   rk   s     r#   r   zCTestFinderTemplate.test_dynamic_path_computation.<locals>.<genexpr>K  s     K4-v&Ks   )onetwothreezparent.childzparent.child.oner   zparent.child.twor	     zparent.child.threer
     )rA   rB   rC   rD   r   r	   r   r   r   r   r   r   r   r   xrd   raisesImportErrorr}   )rp   rI   r0   r   r   r   modsr   r  r  r  s              r#   test_dynamic_path_computationz0TestFinderTemplate.test_dynamic_path_computation?  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)NrP   r'   zfrom . import pkgr3   r[   rA   rB   rC   rD   r   r	   r   r   r   r   r   r   r   rd   r  r  r   rp   rI   r0   r   r   s        r#   test_no_recursionz$TestFinderTemplate.test_no_recursionc  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'   barr3   zfoo.barr;   r[   r  r  s        r#   test_similar_namez$TestFinderTemplate.test_similar_namex  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  r3   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  )rA   rB   rC   rD   r   r	   r   r   r   r   r   r   r   rd   r  r  r   r  )rp   rI   r0   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)NrP   r   r   zc = 42)r'   zbar.py)r'   r  r3   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)rA   rB   rC   rD   r   r	   r   r   r   r   r   r   r   r   r   r   r   r   crd   r  r  )rp   rI   r0   r   r   r   r   rP   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
componentsr3   z	src/mypkg)r&   zmypkg.configmypkg.helloworldzmypkg.componentsmypkg.components.configmypkg.components.helloworldNr)  r   r(  r   r*  )rA   rB   rC   rD   r   r	   r   r   r   r   r   r   r   r   r   r   rd   r  r  )rp   rI   r0   r   r   r   ra   
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_anotherr3   r4  r5  r6  )a.b.ca.b.c.x.y.z	m.n.o.p.q)r   a.br7  	a.b.c.x.yr8  r2  zd.er3  f.gzf.g.hr9  r   r2  r3  )r   r7  r8  r2  r3  r9  r<  >   m.nm.n.oa.b.c.xm.n.o.pmr:  r;  N)	rA   rB   rC   r   rD   setr   r   r   )rI   r0   r   r   rootsr{   s         r#   test_pkg_rootsrD    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dZ ee      ed   ddddddddd	Z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&   r&   )r)   r*   rI  r+   z                [tool.setuptools]
                packages = ["mypkg", "mypkg.subpackage"]

                [tool.setuptools.package-dir]
                "mypkg.subpackage" = "other"
                r   )r'   r   rH  )r)   r*   rI  r&   r4  )r   rH  )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)
        r5   rQ   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"))
        rG  
**/mod1.py
**/mod2.py**/resource_file.txtzvar = 17r<   r=   z	var = 781zresource 374z17 781)install_projectEXAMPLESrF   r   r   rn   rH   )rp   rI   rJ   rN  r$   rK   _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   FLAT_LAYOUTrT  rd   r   xfailr   r   r   keysrZ  r   r%   r#   rF  rF  @  sU   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%   rF  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
)TestLinkTreerK  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)Nr3   zmypkg-3.14159r   r   z.auxz.buildbuild_pyTrP  zsrc/mypkg/mod1.pyz**/subpackagerQ  rR  z**/resource.not_in_manifest)rA   rB   rC   FILES_Pathr   parse_config_filesr   r@   get_command_objeditable_moderD   	build_libensure_finalizedget_outputsget_output_mappingr   r   rn   assert_link_to)rp   rI   rk   rv   wheelauxrC   rc  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&   r5   rQ   z(import mypkg.mod1; print(mypkg.mod1.var)r_   zv        try:
            from mypkg import subpackage
        except ImportError as ex:
            print(ex)
        r5   rQ   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 directoryra  )rS  rd  rF   r   )rp   rI   rJ   r   r   rV  rX  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   rF  rT  rd  r   rs  rw  r   r%   r#   r`  r`    sW    )22<@AE	
v
	   9>E%L45 OD1r%   r`  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=compatrL  r&   ru  r_   )z"import otherfile; print(otherfile)zimport other; print(other)zimport mypkg; print(mypkg)r5   rQ   zc    try:
        from mypkg import subpackage;
    except ImportError as ex:
        print(ex)
    rv  )rF  rT  rS  rF   comparable_pathrD   r   )rI   rJ   r   r0   r   expected_pathrL   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                     t        d      t        d      t        d      dddddid	}|j                  g d
       t        j                  d      5  t	        d|| |g|  ddd       |j                  g d      }d|v sJ y# 1 sw Y   #xY w)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&   r4  )r5   r6   r7   r8   pbrz0.42)PBR_VERSIONr&   N)r5   rQ   zimport mypkg.hellozHello world!)r   rF   r   environmentrS  )rI   rJ   r$   r0   r   s        r#   test_pbr_integrationr  +  s     !
 
 	
 /
 56=E@ 	HH67			&	1 HxGGH ((9
:CS   	H Hs   BB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.
    rJ  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                     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_RAISEru  r_   N)rS  rd  rF   )rp   rI   rJ   rU  r   s        r#   test_safeguarded_from_errorsz.TestCustomBuildPy.test_safeguarded_from_errorsu  sS     !$$**E3-444'3...hhSTs{{r%   N)	r   r   r   r-  rF  rT  r   rd  r  r   r%   r#   r  r  V  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)rp   rU  	__class__s     r#   r  zMTestCustomBuildWheel.install_custom_build_wheel.<locals>.MyBdistWheel.get_tag  s)     >>,,Y7(Aw((r%   )r   r   r   r  __classcell__)r  s   @r#   MyBdistWheelr    s    ) )r%   r  )get_command_classcmdclass)rp   rv   bdist_wheel_clsr  s       r#   install_custom_build_wheelz/TestCustomBuildWheel.install_custom_build_wheel  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?   r1   
dist/*.whleditable)rA   rB   rC   r   r   set_defaultsr  r   rj  rF   rD   r   r   rn   )rp   
tmpdir_cwdrv   rL   
wheel_files        r#   test_access_plat_namez*TestCustomBuildWheel.test_access_plat_name  s     	;12~%''-T"	dfkk,789
Z'''r%   N)r   r   r   r  r  r   r%   r#   r  r    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  )rp   rv   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moduler1   r  r  zmodule.*z.cr   r   c              3   @   K   | ]  }j                  |        y wNr   )r   extrk   s     r#   r   zHTestCustomBuildExt.test_distutils_leave_inplace_files.<locals>.<genexpr>  s     D#4==%Ds   )rA   rB   rC   r   r   r   r  r  r   rj  rF   rD   r   r   rn   suffixro   rk   anyr   )	rp   r  r   rv   rL   r  pr0   rk   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  rd   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|       d}t        j                  |      5  t        j                  t        |      5  |j!                          d	d	d	       d	d	d	       y	# 1 sw Y   xY w# 1 sw Y   y	xY w)
z7Make sure to display useful debugging tips to the user.r  r?   r1   SimulatedErr)side_effectrj   z-following steps are recommended to help debugr[   N)rA   rB   rC   r   r   r  r   rj  type	Exceptionr   setattrrd   r  re   r   rF   )r  rq   rv   rL   r  simulated_failureexpected_msgs          r#   test_debugging_tipsr    s    
KK{H-.>D!D

Cb9L846GHBL	|	$ fll>&V 	     s$   +C5C)C5)C2	.C55C>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 )
Nr3   r9   r5   r6   r7   r   r8   r:   )stderr)r@   rA   rB   rC   rF   rD   r   STDOUT)rk   rJ   rI   r0   r   rK   r   s          r#   rS  rS    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   tuplerH   )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   iterrD   r   r   )rP   r   rB   s      r#   r   r     sK    
||D&-tDz))+,888  r%   filer4  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_symlinkrD   r   statST_INOST_DEV)r  r4  	file_stat
other_stats       r#   rm  rm    s    4<<>"c%--/&::::IIK	ZZ\
%DKK)@@@@%DKK)@@@@r%   str_with_pathreturnc                 ~    | j                         j                  t        j                  d      j                  dd      S )N/z//)lowerreplacer   sep)r  s    r#   ry  ry    s/     ((5==dCHHr%   )Qr   r   r  r   r   copyr   	importlibr   importlib.machineryr   pathlibr   textwrapr   unittest.mockr   uuidr	   jaraco.envsrA   jaraco.pathrd   rB   re  setuptools._importlibr
   r   !setuptools.command.editable_wheelr   r   r   r   r   r   r   r   r   setuptools.distr   setuptools.extensionr   setuptools.warningsr   r   r   r   distutils.corer   fixturer$   rG   r   SETUP_SCRIPT_STUBr   r]  r   rM   rT   rW   rY   r   r   r   rD  rF  r`  filterwarningsr{  r  r  r  r  r  r  rS  r   r   rm  rD   ry  r   r%   r#   <module>r     s[   	    
  # 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t% t%nP1 P1f WX4 Y4@(!V' 'T( (:E E@$ G$& %&	
M 9A Ad AI3 I3 Ir%   