
    ,h              
         d dl mZ d dlZd dlZd dlZd dlZd dlZd dlmZ d dl	m
Z
 d dlmZ d dlmZ d dlmZ d dlmZ d d	lmZ d d
lmZ d dlZd dlZd dlZd dlmZ d dlmZ d dl m!Z!m"Z"m#Z#m$Z$m%Z%m&Z&m'Z'm(Z(m)Z) d dl*m+Z+ d dl,m-Z- d dl.m/Z/ ddl0m1Z1m2Z2 d dl3m4Z4  ejj                  ddg      d        Z6 ed       ed      jo                         ddd ed       ed      ddd id!Z8d"Z9ejt                  jw                  ej                  d#k(  d$%      ejt                  jy                  d&i e8d'e9ie8g      d(               Z=d) Z>d* Z? G d+ d,      Z@ G d- d.      ZAd/ ZB G d0 d1      ZCd2 ZD G d3 d4      ZE G d5 d6      ZFejt                  j                  d7      d8        ZHd9 ZI G d: d;      ZJ G d< d=      ZK G d> d?      ZLd@ ZMejt                  j                  dA      dB        ZNdC ZOdD ZPdE ZQdHdFZRdIdGZSy)J    )annotationsN)deepcopy)import_module)EXTENSION_SUFFIXES)Path)dedent)Any)Mock)uuid4)	resources)	_DebuggingTips_encode_pth_find_namespaces_find_package_roots_find_virtual_namespaces_finder_template	_LinkTree_TopLevelFindereditable_wheel)Distribution)	Extension)SetuptoolsDeprecationWarning   )contexts
namespaces)	run_setupstrictlenient)paramsc                ,    | j                   dk(  rddgS g S )Nr   --config-settingseditable-mode=strict)param)requests    h/var/www/html/Resume-Scraper/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)r7   r8   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venvr2   r&   projectcmds         r%   test_editable_with_pyprojectrO   |   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*   r5   r7   r8   r9   r:   r;   r<   )r7   -cz$import pkg, mod; print(pkg.a, mod.b)z4 2r   rC   rD   rE   rF   rG   rH   rI   rK   rL   r&   r2   rM   rN   s         r%   test_editable_with_flat_layoutrV      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"]
                rQ   )r+   r*   r5   r7   r8   r9   r:   r;   r<   )r7   rS   zimport mod; print(mod.b)2rT   rU   s         r%    test_editable_with_single_modulerY      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)versionr3   config)
stop_after	dist_infoz*-nspkg.pth)pytestwarnsr   rB   r   build_namespace_packagecontextchdirr   r   finalize_optionsget_finalized_commandname_install_namespaceslistgloblen)selfrK   monkeypatchdeprecationinstallation_direxamplesrm   rR   ctxdistrN   editable_namer2   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)r{   z.pkgBr+   r>   r?   Nr;   r7   r8   r9   r:   r<   rS   zimport z.pkgA; import )r7   rS   zimport pkg_resources)r   rh   rJ   appendrH   rF   )
rr   rL   rK   r}   r{   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__rz   rf   markparametrizer    r'   r%   r[   r[      sM    +4 [[	
 [[T;/; 0;r'   r[   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;   r7   r8   r9   r:   r<   )r7   rS   z&import myns.n.pkgA; import myns.n.pkgB)r   build_pep420_namespace_packager   rH   rF   )rr   rL   rK   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-   r5   r`   zmyns.n.pkgCNr;   r7   r8   r9   r:   r<   )r7   rS   z#from myns.n import pkgA, pkgB, pkgC)	r   rC   rD   rE   r   r   r   rH   rF   )	rr   rL   rK   r&   r2   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,   r5   r;   r7   r8   r9   -vr:   r<   )r7   rS   z'from mypkg.n import pkgA; print(pkgA.a)1z}        try:
            import mypkg.other
        except ImportError:
            print("mypkg.other not defined")
        rS   zmypkg.other not definedN)r   EXAMPLErC   rD   rE   rH   rF   rI   )rr   rL   rK   r2   r   r   outrN   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.
    r6   zsite-packagesT)parents)
PYTHONPATHr8   r9   r:   
--editablez--prefixr;   )envWindowsScriptsbinsampleN)sysrD   
startswithr6   r   relative_torB   _addsitedirsdictosenvironpathsepjoinmaprF   
executable
subprocess
check_callplatformsystem)rK   sample_projectr&   r6   rD   site_packages_allspr   rN   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 )Nr:   )exec)rr   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src2r5   z	src1/pkg1z	src2/mod2)r   mod2)r   pkg1.subpkgpkg1.subpkg.mod1r   r   r   r   *   +   zsrc1/pkg1/subpkg)rC   rD   rE   rF   r   r   r   
save_pathssave_sys_modulesr   modulespopr   r   aresolveassert_path)
rr   rK   r2   mappingtemplatemodmod1r   r   expecteds
             r%   test_packagesz TestFinderTemplate.test_packages  sO    #%((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)NrR   a = 13abc)r)   text.txtr5   ns.othernamer}   r}   r   r      r>   r?   )rC   rD   rE   rF   r   r   r   r   r   r   r   r   r   r   importlib_resourcesr2   r   r   r   	read_text)
rr   rK   r2   r   r   r   r   rR   textr   s
             r%   test_namespacez!TestFinderTemplate.test_namespace  s5   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   r5   zsrc1/ns/pkg1zsrc2/ns)ns.pkgAr}   r   r   )r}   r   ns.mod2r   r   r   %   )rC   rD   rE   rF   r   r   r   r   r   r   r   r   r   r   r   r   r   b)
rr   rK   r2   r   namespaces_r   r   r   r   r   s
             r%   test_combine_namespacesz*TestFinderTemplate.test_combine_namespaces  sc   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   )rC   rD   DirectoryStackri   rE   r   r   rF   r   nextget_implementationr   r   r   r   r   r   r   r   r   r   __file__r   r   )rr   rK   r2   stackattrsrx   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H'GGPPRSHtDMM*2245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project3r5   zproject1/parentc              3  &   K   | ]	  }d |   yw)zparent.child.Nr   )r   rm   s     r%   r   zCTestFinderTemplate.test_dynamic_path_computation.<locals>.<genexpr>N  s     K4-v&Ks   )onetwothreezparent.childzparent.child.oner   zparent.child.twor     zparent.child.threer     )rC   rD   rE   rF   r   r   r   r   r   r   r   r   r   r   xrf   raisesImportErrorr   )rr   rK   r2   r   r   r   modsr   r  r  r  s              r%   test_dynamic_path_computationz0TestFinderTemplate.test_dynamic_path_computationB  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)NrR   r)   zfrom . import pkgr5   r]   rC   rD   rE   rF   r   r   r   r   r   r   r   r   r   rf   r  r  r   rr   rK   r2   r   r   s        r%   test_no_recursionz$TestFinderTemplate.test_no_recursionf  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)   barr5   zfoo.barr=   r]   r  r  s        r%   test_similar_namez$TestFinderTemplate.test_similar_name{  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  r5   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  )rC   rD   rE   rF   r   r   r   r   r   r   r   r   r   rf   r  r  r   r  )rr   rK   r2   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)NrR   r   r   zc = 42)r)   zbar.py)r)   r  r5   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)rC   rD   rE   rF   r   r   r   r   r   r   r   r   r   r   r   r   r   r   crf   r  r  )rr   rK   r2   r   r   r   r   rR   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
componentsr5   z	src/mypkg)r(   zmypkg.configmypkg.helloworldzmypkg.componentsmypkg.components.configmypkg.components.helloworldNr,  r   r+  r   r-  )rC   rD   rE   rF   r   r   r   r   r   r   r   r   r   r   r   r   rf   r  r  )rr   rK   r2   r   r   r   rc   
helloworlds           r%   test_intermediate_packagesz-TestFinderTemplate.test_intermediate_packages  sG    #%!)%-#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_anotherr5   r7  r8  r9  )a.b.ca.b.c.x.y.z	m.n.o.p.q)r   a.br:  	a.b.c.x.yr;  r5  zd.er6  f.gzf.g.hr<  r   r5  r6  )r   r:  r;  r5  r6  r<  r?  >   m.nm.n.oa.b.c.xm.n.o.pmr=  r>  N)	rC   rD   rE   r   rF   setr   r   r   )rK   r2   r   r   rootsr}   s         r%   test_pkg_rootsrG    s3    "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,   rL  r-   z                [tool.setuptools]
                packages = ["mypkg", "mypkg.subpackage"]

                [tool.setuptools.package-dir]
                "mypkg.subpackage" = "other"
                r   )r)   r   rK  )r+   r,   rL  r(   r7  )r   rK  )flat-layout
src-layoutcustom-layout	namespacer.   r/   r0   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)
        r7   rS   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"))
        rJ  
**/mod1.py
**/mod2.py**/resource_file.txtzvar = 17r>   r?   z	var = 781zresource 374z17 781)install_projectEXAMPLESrH   r   r   rp   rJ   )rr   rK   rL   rR  r&   rM   _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 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   rM  __annotations__rX  rf   r   xfailr   r   r   keysr^  r   r'   r%   rI  rI  C  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'   rI  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
)TestLinkTreerO  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)Nr5   zmypkg-3.14159r   r   z.auxz.buildbuild_pyTrT  zsrc/mypkg/mod1.pyz**/subpackagerU  rV  z**/resource.not_in_manifest)rC   rD   rE   FILES_Pathr   parse_config_filesr
   rB   get_command_objeditable_moderF   	build_libensure_finalizedget_outputsget_output_mappingr   r   rp   assert_link_to)rr   rK   rm   rx   wheelauxrE   rg  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!>?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(   r7   rS   z(import mypkg.mod1; print(mypkg.mod1.var)ra   zv        try:
            from mypkg import subpackage
        except ImportError as ex:
            print(ex)
        r7   rS   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 directoryre  )rW  rh  rH   r   )rr   rK   rL   r   r   rZ  r\  s          r%   test_strict_installz TestLinkTree.test_strict_install  s    #%;<xCdChhSTs{ hh$/?(@AB0C77 hh$/?(@AB*c11)S000r'   N)
r   r   r   r   rI  rX  rh  r   rw  r{  r   r'   r%   rd  rd    sW    )22<@AE	
v
	   9>E%L45 OD1r'   rd  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=compatrP  r(   ry  ra   )z"import otherfile; print(otherfile)zimport other; print(other)zimport mypkg; print(mypkg)r7   rS   zc    try:
        from mypkg import subpackage;
    except ImportError as ex:
        print(ex)
    rz  )rI  rX  rW  rH   comparable_pathrF   r   )rK   rL   r   r2   r   expected_pathrN   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 #3500r7   r8   r9   r   r:   r   stderr)r7   rS   zimport mypkg.hellozHello world!N)rH   r   STDOUT)pbr_packagerL   r&   rN   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.
    rN  r3   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_RAISEry  ra   N)rW  rh  rH   )rr   rK   rL   rY  r   s        r%   test_safeguarded_from_errorsz.TestCustomBuildPy.test_safeguarded_from_errors_  sM     !$$**E3-44'3..hhSTs{{r'   N)	r   r   r   r0  rI  rX  r   rh  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)rr   rY  	__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)rr   rx   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.pyrA   r3   
dist/*.whleditable)rC   rD   rE   r   r   set_defaultsr  r   rn  rH   rF   r   r   rp   )rr   
tmpdir_cwdrx   rN   
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  )rr   rx   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 setupr0   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moduler3   r  r  zmodule.*z.cr   r   c              3  @   K   | ]  }j                  |        y wNr   )r   extrm   s     r%   r   zHTestCustomBuildExt.test_distutils_leave_inplace_files.<locals>.<genexpr>  s     D#4==%Ds   )rC   rD   rE   r   r   r   r  r  r   rn  rH   rF   r   r   rp   suffixrq   rm   anyr   )	rr   r  r  rx   rN   r  pr2   rm   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  rf   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  rA   r3   SimulatedErr)side_effectrl   z-following steps are recommended to help debugr]   N)rC   rD   rE   r   r   r  r   rn  type	Exceptionr
   setattrrf   r  rg   r   rH   )r  rs   rx   rN   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 )
Nr5   r;   r7   r8   r9   r   r:   r<   r  )rB   rC   rD   rE   rH   rF   r   r  )rm   rL   rK   r2   r   rM   r   s          r%   rW  rW    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   tuplerJ   )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   iterrF   r   r   )rR   r   rD   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_symlinkrF   r   statST_INOST_DEV)filer7  	file_stat
other_stats       r%   rq  rq    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   r7  r   returnNone)r  rF   r  rF   )T
__future__r   r   r   r  r   r   copyr   	importlibr   importlib.machineryr   pathlibr   textwrapr   typingr	   unittest.mockr
   uuidr   jaraco.envsrC   jaraco.pathrf   rD   ri  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&   rI   r   SETUP_SCRIPT_STUBr   ra  r   rO   rV   rY   r[   r   r   r   rG  rI  rd  filterwarningsr  r  r  r  r  r  r  rW  r   r   rq  r}  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u% u%pP1 P1f WX4 Y4@!"' 'T( (:E E@$ G$& %&	
M 9AIr'   