
    nj                    t   S r SSKJr  SSKrSSKrSSKrSSKrSSKrSSKrSSK	J
r
JrJr  SSKJr  SSKJr  SSKJr  SSKJrJr  SS	KJr  SS
KJr  SSKJr  SSKJrJrJrJ r J!r!  SSK"J#r#J$r$J%r%J&r&J'r'J(r(  SSK%J)r)  SSK*J+r+J,r,  SSK-J.r.  SSK/J0r0  SSK1J2r2J3r3  SSK4J4r5  SSK6J6r7  SSK8J8r9  SSK:J:r;  SSK<J<r=  SSK>J>r?  \(       a  SSK@JArA  SSKBJCrC  \ " S\)S9rD\R                  " \F5      rG " S S \5      rHS!rIS"rJ " S# S$\#5      rK " S% S&\5      rL " S' S(5      rM " S) S*\M5      rN " S+ S,5      rOS@S- jrPSAS. jrQ        SBS/ jrRS0 rSSCS1 jrTSCS2 jrU        SDS3 jrVSES4 jrWSFS5 jrX      SGS6 jrYSHS7 jrZSIS8 jr[SJS9 jr\ " S: S;\(R                  5      r^S<r_        SKS= jr` " S> S?\'R                  5      rbg)La  
Create a wheel that, when installed, will make the source package 'editable'
(add it to the interpreter's path, including metadata) per PEP 660. Replaces
'setup.py develop'.

.. note::
   One of the mechanisms briefly mentioned in PEP 660 to implement editable installs is
   to create a separated directory inside ``build`` and use a .pth file to point to that
   directory. In the context of this file such directory is referred as
   *auxiliary build directory* or ``auxiliary_dir``.
    )annotationsN)IterableIteratorMapping)suppress)Enum)cleandoc)chainstarmap)Path)TemporaryDirectory)TracebackType)TYPE_CHECKINGClassVarProtocolTypeVarcast   )Command_normalization_path_shutilerrors
namespaces)StrPath)py310py312)find_package_path)Distribution)InformationOnlySetuptoolsDeprecationWarning   )build)build_py)	dist_info)egg_info)install)install_scripts)Self	WheelFile_P)boundc                  8    \ rS rSrSrSrSrSr\S	S j5       r	Sr
g)
_EditableMode5   z
Possible editable installation modes:
`lenient` (new files automatically added to the package - DEFAULT);
`strict` (requires a new installation when files are added/removed); or
`compat` (attempts to emulate `python setup.py develop` - DEPRECATED).
strictlenientcompatc                    U(       d  [         R                  $ UR                  5       nU[         R                  ;  a  [        R
                  " SU< S35      eUS:X  a  [        R                  " SSSS9  [         U   $ )NzInvalid editable mode: z. Try: 'strict'.COMPATzCompat editable installsa
  
                The 'compat' editable mode is transitional and will be removed
                in future versions of `setuptools`.
                Please adapt your code accordingly to use either the 'strict' or the
                'lenient' modes.
                zuserguide/development_mode.html)see_docs)r/   LENIENTupper__members__r   OptionErrorr!   emit)clsmode_modes      ]/var/www/html/pdf-tiff/venv/lib/python3.13/site-packages/setuptools/command/editable_wheel.pyconvert_EditableMode.convertA   sv     (((

111$$'>thFV%WXXH(--* ;  U##     N)r=   
str | Nonereturnr/   )__name__
__module____qualname____firstlineno____doc__STRICTr7   r5   classmethodr@   __static_attributes__rC   rB   r?   r/   r/   5   s*     FGF$ $rB   r/   zU
New or renamed files may not be automatically picked up without a new installation.
zt
Options like `package-data`, `include/exclude-package-data` or
`packages.find.exclude/include` may have no effect.
c                      \ rS rSr% SrSrSSSS\" \R                  =(       d    S5      4/rS	\	S
'   S r
SS jrSS jrS rS rSS jr        SS jrS rSS jr          SS jrSS jrS S jrS rS!S jr        S"S jrSrg)#editable_wheelh   zBuild 'editable' wheel for development.
This command is private and reserved for internal use of setuptools,
users should rely on ``setuptools.build_meta`` APIs.
zBDO NOT CALL DIRECTLY, INTERNAL ONLY: create PEP 660 editable wheel)z	dist-dir=dz-directory to put final built distributions in)zdist-info-dir=Iz(path to a pre-build .dist-info directoryzmode=N zHClassVar[list[tuple[str, str, str]] | list[tuple[str, str | None, str]]]user_optionsc                <    S U l         S U l        S U l        S U l        g N)dist_dirdist_info_dirproject_dirr=   selfs    r?   initialize_options!editable_wheel.initialize_optionsx   s     !	rB   c                6   U R                   nUR                  =(       d    [        R                  U l        UR
                  =(       d    0 U l        [        U R                  =(       d*    [        R                  R                  U R                  S5      5      U l        g )Ndist)
distributionsrc_rootoscurdirrY   package_dirr   rW   pathjoin)r[   r_   s     r?   finalize_optionseditable_wheel.finalize_options~   s_      ==5BII++1rT]]Tbggll4;K;KV.TUrB   c                    U R                   R                  SS9  U R                  5         U R                  S5        U R	                  S5      nUR                  U R                  5        U R                  U5        g ! [         aX  nU R                  R                  =(       d    U R                  R                  5       n[        R                  " USU S35        e S nAff = f)NT)exist_okbdist_wheelz3An error occurred when building editable wheel for zl.
See debugging tips in: https://setuptools.pypa.io/en/latest/userguide/development_mode.html#debugging-tips)rW   mkdir_ensure_dist_inforeinitialize_commandget_finalized_commandwrite_wheelfilerX   _create_wheel_file	Exceptionr`   nameget_namer   add_note)r[   rk   exprojects       r?   runeditable_wheel.run   s    	MM.""$ %%m444]CK''(:(:;##K0 	'',,L0A0A0J0J0LGNNEgY Of f 	s   A7A: :
CACCc                   U R                   cb  [        [        U R                  S5      5      nU R                  Ul        UR                  5         UR                  5         UR                   U l         g [        U R                   5      R                  S5      (       d   e[        U R                   S5      R                  5       (       d   eg )Nr%   z
.dist-infoMETADATA)rX   r   dist_info_clsrn   rW   
output_dirensure_finalizedrx   strendswithr   exists)r[   r%   s     r?   rm    editable_wheel._ensure_dist_info   s    %]D,E,Ek,RSI#'==I &&(MMO!*!8!8Dt))*33LAAAA**J7>>@@@@rB   c                    U R                   nUR                  (       d  g [        U R                  U R                  R                  SS5      5      R                  5       n[        X1X$5      nUR                  5         g )NrS   .)	r`   namespace_packagesr   rY   rd   getresolve_NamespaceInstallerinstall_namespaces)r[   installation_dir
pth_prefixr_   ra   	installers         r?   _install_namespaces"editable_wheel._install_namespaces   s_      &&(($*:*:*>*>r3*GHPPR'
U	$$&rB   c                    U R                   (       a  [        U R                   5      R                  O	[        5       n[        [        UR                  S5      5      n[        US 5      $ )Nz
*.egg-info)rX   r   parentmapr   globnext)r[   
parent_dir
candidatess      r?   _find_egg_info_dir!editable_wheel._find_egg_info_dir   sH    8<8J8JT$,,-44PTPV
jool;<
J%%rB   c                   U R                   n[        U5      n[        U5      n[        [        X! S3S5      5      n[        [        X! S3S5      5      n[        [        X! S3S5      5      n	[        [        UR                  SSS95      n
[        U5      U
l        SU
l        [        [        UR                  SSS95      n[        [        UR                  S	SS95      nU=Ul
        =Ul        Ul        U=Ul        =Ul        Ul        U	=Ul        Ul        Xl        X|l        UR)                  S
5      nSUl        [        [,        UR)                  S5      5      nSUl        [        U5      Ul        [        [2        UR)                  S5      5      nSUl        U R7                  5       Ul        U R;                  5         UR=                  5         UR=                  5         g)a  Configure commands to behave in the following ways:

- Build commands can write to ``build_lib`` if they really want to...
  (but this folder is expected to be ignored and modules are expected to live
  in the project directory...)
- Binary extensions should be built in-place (editable_mode = True)
- Data/header/script files are not part of the "editable" specification
  so they are written directly to the unpacked_wheel directory.
z.datadataheadersscriptsr&   T)reinit_subcommandsr#   r'   build_scriptspythonr(   r$   FN)r`   r   r   r   egg_info_clsrn   egg_baseignore_egg_info_in_manifest	build_clsinstall_clsbuild_platlibbuild_purelib	build_libinstall_purelibinstall_platlibinstall_libr(   r   install_headersinstall_dataget_command_obj
executableinstall_scripts_clsno_ep
build_tempbuild_py_clscompiler   existing_egg_info_dir_set_editable_moder~   )r[   rs   unpacked_wheelr   tmp_dirr_   wheelr   r   r   r&   r#   r'   r   r(   r$   s                   r?   _configure_buildeditable_wheel._configure_build   s      N#	N	4&?@d>V5>9EFd>V5>9EF $33JSW3X
  L/3,t00T0R
 229QU2V
 GPOOe1EORWWW'"9G<O8??%"5")# ,,_=#+ !5!56G!H
 !%w<d&:&::&FG )-)@)@)B&!   "rB   c                    U R                   nUR                  S5      nUR                  5        HH  nUR                  U5      n[        US5      (       a	  SUl        M.  [        US5      (       d  MA  SUl        MJ     g)z8Set the ``editable_mode`` flag in the build sub-commandsr#   editable_modeTinplaceN)r`   r   get_sub_commandshasattrr   r   )r[   r_   r#   cmd_namecmds        r?   r   !editable_wheel._set_editable_mode   si      $$W-..0H&&x0CsO,,$(!i((" 1rB   c                j   / n0 nU R                  S5      nUR                  5        H  nU R                  U5      n[        US5      (       a(  UR                  UR	                  5       =(       d    / 5        [        US5      (       d  M`  UR                  UR                  5       =(       d    0 5        M     X4$ )Nr#   get_outputsget_output_mapping)ro   r   r   extendr   updater   )r[   filesmappingr#   r   r   s         r?   _collect_build_outputs%editable_wheel._collect_build_outputs   s    "$**73..0H,,X6CsM**S__.4"5s011s557=2> 1 ~rB   c                    U R                  XX45        U R                  5         U R                  5       u  pVU R                  S5        U R                  S5        U R                  S5        XV4$ )Nr   r   r   )r   _run_build_subcommandsr   _run_install)r[   	dist_namer   r   r   r   r   s          r?   _run_build_commands"editable_wheel._run_build_commands  sb     	iL##%446)$)$&!~rB   c                    U R                  S5      nUR                  5        HP  nU R                  U5      nUS:X  a%  [        U5      [        La  U R	                  U5        M?  U R                  U5        MR     g)aE  
Issue #3501 indicates that some plugins/customizations might rely on:

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

However both these assumptions may be false in editable_wheel.
This method implements a temporary workaround to support the ecosystem
while the implementations catch up.
r#   r$   N)ro   r   typer   _safely_runrun_command)r[   r#   rs   r   s       r?   r   %editable_wheel._run_build_subcommands  sf     **73**,D,,T2Cz!d3i|&C  &  & -rB   c                     U R                  U5      $ ! [         a7    [        R                  " SS[        R
                  " 5        SU SU S35         g f = f)Nz0Customization incompatible with editable installz
                z

                If you are seeing this warning it is very likely that a setuptools
                plugin or customization overrides the `a  ` command, without
                taking into consideration how editable installs run build steps
                starting from setuptools v64.0.0.

                Plugin authors and developers relying on custom build steps are
                encouraged to update their `aa  ` implementation considering the
                information about editable installs in
                https://setuptools.pypa.io/en/latest/userguide/extension.html.

                For the time being `setuptools` will silence this error and ignore
                the faulty command, but this behavior will change in future versions.
                )r   rr   r!   r;   	traceback
format_exc)r[   r   s     r?   r   editable_wheel._safely_run0  sp    	##H-- 	(--B%%'( )8 9Az B-
 .6J 7	s    >AAc           
        SSK Jn  U R                  S5      nUR                  nSR	                  UR                  5       5      nSnU SU SU S3n[        U R                  U5      nUR                  5       (       a  UR                  5         [        US9n	[        SS9n
[        S	S9nU	 o o n[        U[        U R                  5      R                  5      n[        R                  " U R                  U5        U R                  X5        U R                  XLX5      u  nnU R!                  XEU5      nU   U" US
5       nU" UUU5        UR#                  U5        S S S 5        S S S 5        S S S 5        S S S 5        S S S 5        U$ ! , (       d  f       N0= f! , (       d  f       N9= f! , (       d  f       NB= f! , (       d  f       NK= f! , (       d  f       U$ = f)Nr   r*   r%   -z
0.editablez.whl)suffixz
.build-libz.build-tempw)wheel.wheelfiler+   ro   rs   rf   get_tagr   rW   r   unlinkr   rX   shutilcopytreer   r   _select_strategywrite_files)r[   rk   r+   r%   r   tag	build_tagarchive_name
wheel_pathr   r   	build_tmpunpackedlibtmpunpacked_dist_infor   r   strategy	wheel_objs                       r?   rq   !editable_wheel._create_wheel_fileL  s{   -..{;	NN	hh{**,- 	#Ai[#d;$--6
+<@&l;	&m<	xc9!%hT5G5G0H0M0M!NOOD..0BC$$X9!55i3TNE7,,YSAH9Z5E73%%h/ 6 <E^ 	 65 <E9^^ sm   (G*F4,BF#1
F	;FF	F#'F4/G
FF	
F F##
F1-F44
G	>G
Gc                    [        U R                  SU 3S 5      nU(       a;  U" 5       (       a.  [        R                  SU S35        U R	                  SU 35        g g g )Nhas_zInstalling z as non editableinstall_)getattrr`   _loggerinfor   )r[   categoryhas_categorys      r?   r   editable_wheel._run_installh  sX    t00D
2CTJLNNLL;xj0@ABxz23 +<rB   c                ~   SU SU 3n[        U R                  5      n[        R                  U R                  5      nU[        R
                  L a7  [        [        U R                  SU5      5      n[        U R                  XU5      $ [        U R                  5      n[        XR                  U5      n	U[        R                  L n
[        U R                  5      S1:X  a  U	(       d  U
(       a=  U R                  R                  SS5      n[        U R                  U[        X[5      /5      $ [!        U R                  U5      $ )zDDecides which strategy to use to implement an editable installation.__editable__.r   r#   rS   r   )r   rY   r/   r@   r=   rK   
_empty_dir	_LinkTreer`   _find_packages_simple_layoutrd   r5   setr   
_StaticPth_TopLevelFinder)r[   rs   r   r   
build_namerY   r=   auxiliary_dirpackageshas_simple_layoutis_compat_modesrc_dirs               r?   r   editable_wheel._select_strategyn  s    %TF!C51
4++,$$TYY/='''&tD,<,<gz'RSMT..YOO!$"3"34*85E5E{S!5!55t RD(->.&&**2s3Gd//[8R7STT t00$77rB   )rW   rX   r=   rd   rY   rE   None)rE   rD   )rs   r   r   r   r   r   r   r   )rE    tuple[list[str], dict[str, str]])
r   r   r   r   r   r   r   r   rE   r  )r   r   )r   r   )rs   r   r   r   r   r   rE   EditableStrategy)rF   rG   rH   rI   rJ   descriptionr	   r/   rT   __annotations__r\   rg   rx   rm   r   r   r   r   r   r   r   r   rq   r   r   rM   rC   rB   r?   rO   rO   h   s
   
 WK
 	LK	$!6!6!<"=>	   V*	A'&
=#=#)0=#=D=#OV=#~	#   	
  
*',88488 8 	8
 
8rB   rO   c                  R    \ rS rSr        SS jrSS jr        S	S jrSrg)
r  i  c                    g rV   rC   )r[   r   r   r   s       r?   __call__EditableStrategy.__call__  s    rB   c                    g rV   rC   rZ   s    r?   	__enter__EditableStrategy.__enter__  s    rB   c                    g rV   rC   r[   	_exc_type
_exc_value
_tracebacks       r?   __exit__EditableStrategy.__exit__  s    
 rB   rC   N)r   r+   r   	list[str]r   Mapping[str, str]rE   objectrE   r)   )r  ztype[BaseException] | Noner  zBaseException | Noner  zTracebackType | NonerE   r   )rF   rG   rH   rI   r  r  r  rM   rC   rB   r?   r  r    sW    '0;L	 %- ) )	
 
rB   r  c                  \    \ rS rSrSS jr        S	S jrS
S jr        SS jrSrg)r  i  c                (    Xl         X l        X0l        g rV   r_   rs   path_entries)r[   r_   rs   r%  s       r?   __init___StaticPth.__init__  s    		(rB   c                    SR                  S U R                   5       5      n[        U S35      nUR                  SU R                   S3U5        g )N
c              3  T   #    U  H  n[        UR                  5       5      v   M      g 7frV   )r   r   ).0ps     r?   	<genexpr>&_StaticPth.__call__.<locals>.<genexpr>  s      H6GC		,,6Gs   &(r   .pth)rf   r%  _encode_pthwritestrrs   )r[   r   r   r   entriescontentss         r?   r  _StaticPth.__call__  sI     ))Hd6G6GHH'"~.tyyk6ArB   c                    S[        [        [        R                  U R                  5      5      < S3n[
        R                  U[        -   5        U $ )Nz_
        Editable install will be performed using .pth file to extend `sys.path` with:
        z	
        )listr   rb   fspathr%  r   warning_LENIENT_WARNINGr[   msgs     r?   r  _StaticPth.__enter__  sH    		c"))T../	03 4	 	../rB   c                    g rV   rC   r  s       r?   r  _StaticPth.__exit__  s     	rB   r$  N)r_   r   rs   r   r%  z
list[Path]rE   r  r   r+   r   r  r   r  rE   r  r!  r  r   r  r   r  r   rE   r  )	rF   rG   rH   rI   r&  r  r  r  rM   rC   rB   r?   r  r    sa    )
BB'0B;LB	B  	
 
rB   r  c                     ^  \ rS rSrSr          SU 4S jjr        SU 4S jjrSS jrSSS jjrSS jr	SS jr
        SS	 jrS
rU =r$ )r   i  aH  
Creates a ``.pth`` file that points to a link tree in the ``auxiliary_dir``.

This strategy will only link files (not dirs), so it can be implemented in
any OS, even if that means using hardlinks instead of symlinks.

By collocating ``auxiliary_dir`` and the original source code, limitations
with hardlinks should be avoided.
c                   > [        U5      U l        [        U5      R                  5       U l        UR	                  S5      R
                  U l        [        TU ]!  XU R                  /5        g )Nr$   )	r   r  r   r   r   	copy_file_filesuperr&  )r[   r_   rs   r  r   	__class__s        r?   r&  _LinkTree.__init__  sV     "-0i002))*5??
d&8&8%9:rB   c                H   > U R                  X#5        [        TU ]	  XU5        g rV   )_create_linksrE  r  )r[   r   r   r   rF  s       r?   r  _LinkTree.__call__  s"     	5*w/rB   c                   [        [        5         [        U5      R                  5       R	                  U R
                  5      n[        U5      R                  [        R                  S5      sS S S 5        $ ! , (       d  f       g = f)N/)
r   
ValueErrorr   r   relative_tor   r   replacerb   sep)r[   filere   s      r?   _normalize_output_LinkTree._normalize_output  sT    j!:%%'33DNNCDt9$$RVVS1 "!! s   AA55
Bc                    U R                   U-  nUR                  R                  5       (       d  UR                  R                  SS9  U R	                  X$US9  g )NT)parentslink)r  r   is_dirrl   rD  )r[   relative_outputsrc_filerW  dests        r?   _create_file_LinkTree._create_file  sJ    !!O3{{!!##KKd+

8
-rB   c                  ^  T R                   R                  SSS9  [        T R                   5      (       a  SOSnU 4S jUR                  5        5       nU VVs0 s H  u  pVUc  M
  XV_M     nnnU H5  nT R	                  U5      n	U	(       d  M  X;  d  M$  T R                  X5        M7     UR                  5        H  u  pT R                  XUS9  M     g s  snnf )NT)rU  rj   symhardc              3  N   >#    U  H  u  pTR                  U5      U4v   M     g 7frV   )rR  )r+  kvr[   s      r?   r-  *_LinkTree._create_links.<locals>.<genexpr>  s%     XAWt--a0!4AWs   "%rV  )r  rl   _can_symlink_filesitemsrR  r\  )r[   outputsoutput_mapping	link_type
normalisedrb  rc  mappingsoutputrelativesrcs   `          r?   rI  _LinkTree._create_links  s       =/0B0BCCE	XAUAUAWX
%/AZTQ1DADZAF--f5HxH4!!(3 
 &^^-MHh)< . Bs   	C&Cc                B    Sn[         R                  U[        -   5        U $ )Nz=Strict editable install will be performed using a link tree.
)r   r8  _STRICT_WARNINGr:  s     r?   r  _LinkTree.__enter__  s    No-.rB   c                R    SU R                    S3n[        R                  " SU5        g )Nz\

        Strict editable installation performed using the auxiliary directory:
            z

        Please be careful to not remove this directory, otherwise you might not be able
        to import/use your package.
        Editable installation.)r  r    r;   r[   r  r  r  r;  s        r?   r  _LinkTree.__exit__  s2      !	 	5s;rB   )rD  r  r   )
r_   r   rs   r   r  r   r   r   rE   r  r?  )rQ  r   rE   rD   rV   )rY  r   rZ  r   )rh  r  r!  r@  )rF   rG   rH   rI   rJ   r&  r  rR  r\  rI  r  r  rM   __classcell__)rF  s   @r?   r   r     s    
;
; 
; 	
;
 
; 

;00'00;L0	0.=
<< < 	<
 
< <rB   r   c                  p    \ rS rSrS
S jrSS jrSS jr        SS jrSS jr        SS jr	Sr
g	)r  i  c                    Xl         X l        g rV   r_   rs   )r[   r_   rs   s      r?   r&  _TopLevelFinder.__init__  s    		rB   c           
        U R                   R                  =(       d    [        R                  n[	        [        U R                   5      [        U R                   5      5      nU R                   R                  =(       d    0 n[        X#U5      n[        [	        [        U R                   R                  =(       d    / U5      S [        U5       5       5      5      nU R                   R                  =(       d    /  Vs0 s H-  nU[        XdU R                   R                  =(       d    S5      _M/     nn0 UEUEnSU R                   S3n	[         R"                  " U	5      n
XX4$ s  snf )Nc              3  (   #    U  H  o/ 4v   M
     g 7frV   rC   )r+  nss     r?   r-  0_TopLevelFinder.template_vars.<locals>.<genexpr>  s     D$Cbb$Cs   rS   r   z.finder)r_   ra   rb   rc   r
   r   _find_top_level_modulesrd   _find_package_rootsdict_find_namespacesr  _find_virtual_namespacesr   r   rs   r   safe_identifier)r[   ra   	top_levelrd   rootsnamespaces_pkglegacy_namespacesr   rs   finders              r?   template_vars_TopLevelFinder.template_vars  s(   99%%2.35LTYY5WX	ii++1r#IHE !3!3!9r5AD$<U$CD
 yy339r9
9 "3tyy/A/A/GRHH9 	 

 1U0/0
 tyyk1//5W11
s   84Ec              #     #    U R                  5       u  pp4[        [        X#U5      S5      nU S3U4v   [        SU SU S35      nSU R                   S3U4v   g 7f)Nutf-8z.pyzimport z; z
.install()r   r/  )r  bytes_finder_templater0  rs   )r[   r  rs   r   r  contents         r?   get_implementation"_TopLevelFinder.get_implementation"  sn     -1-?-?-A*g(DgN~w''xr&DEtyyk.88s   AAc                X    U R                  5        H  u  pEUR                  XE5        M     g rV   )r  r1  )r[   r   r   r   rQ  r  s         r?   r  _TopLevelFinder.__call__+  s%     "446MDNN4) 7rB   c                B    Sn[         R                  U[        -   5        U $ )Nz=Editable install will be performed using a meta path finder.
)r   r8  r9  r:  s     r?   r  _TopLevelFinder.__enter__1  s    N../rB   c                6    Sn[         R                  " SU5        g )Nz

        Please be careful with folders in your working directory with the same
        name as your package as they may take precedence during imports.
        rt  )r    r;   ru  s        r?   r  _TopLevelFinder.__exit__6  s     	5s;rB   rz  N)r_   r   rs   r   rE   r  )rE   z5tuple[str, str, dict[str, str], dict[str, list[str]]])rE   zIterator[tuple[str, bytes]]r?  r!  r@  )rF   rG   rH   rI   r&  r  r  r  r  r  rM   rC   rB   r?   r  r    sf    269**'0*;L*	*

<
< 
< 	
<
 

<rB   r  c                ,   [         R                  " 5        n[         R                  " U[        R                  S9nUR                  U 5        UR                  5         UR                  S5        UR                  5       sSSS5        $ ! , (       d  f       g= f)al  
Prior to Python 3.13 (see https://github.com/python/cpython/issues/77102),
.pth files are always read with 'locale' encoding, the recommendation
from the cpython core developers is to write them as ``open(path, "w")``
and ignore warnings (see python/cpython#77102, pypa/setuptools#3937).
This function tries to simulate this behavior without having to create an
actual file, in a way that supports a range of active Python versions.
(There seems to be some variety in the way different version of Python handle
``encoding=None``, not all of them use ``locale.getpreferredencoding(False)``
or ``locale.getencoding()``).
encodingr   N)	ioBytesIOTextIOWrapperr   PTH_ENCODINGwriteflushseekread)r  bufferwrappers      r?   r0  r0  C  sZ     
""6E4F4FGgA{{} 
s   A%B
Bc                <   [        [        U R                  5       5      S9 n[        US5      [        US5      p2UR	                  SSS9  [        [        [        [        5         [        R                  " X#5        UR                  5       (       a%  UR                  SS9S:X  a   S S S 5        S S S 5        gS S S 5         [        R                  " X#5         S S S 5        g	! , (       d  f       N/= f! [         a  nSn[        U5      UeS nAff = f! , (       d  f       g = f)
N)dirz	file1.txtz	file2.txtfile1r  r  TzFile system does not seem to support either symlinks or hard links. Strict editable installs require one of them to be supported.F)r   r   r   r   
write_textr   AttributeErrorNotImplementedErrorOSErrorrb   symlink
is_symlink	read_textrW  rr   LinksNotSupported)base_dirr   path1path2rv   r;  s         r?   re  re  X  s    	H$4$4$6 7	8CC-tC/Eu73n&97CJJu$!!eoowo&G7&R D 
9	8 D
	1GGE! ! 
9	8 DC  	1P  $C(b0	1 
9	8sO   AD"A C"D3D<C-D
C*	&D-
D
7DD

D
Dc           	     2  ^ U  Vs0 s H  o3[        X1U5      _M     nnU(       d  [        U5      0 S14;   $ [        R                  R	                  [        [        UR                  5       5      5      m[        U4S jUR                  5        5       5      $ s  snf )a  Return ``True`` if:
- all packages are contained by the same parent directory, **and**
- all packages become importable if the parent directory is added to ``sys.path``.

>>> _simple_layout(['a'], {"": "src"}, "/tmp/myproj")
True
>>> _simple_layout(['a', 'a.b'], {"": "src"}, "/tmp/myproj")
True
>>> _simple_layout(['a', 'a.b'], {}, "/tmp/myproj")
True
>>> _simple_layout(['a', 'a.a1', 'a.a1.a2', 'b'], {"": "src"}, "/tmp/myproj")
True
>>> _simple_layout(['a', 'a.a1', 'a.a1.a2', 'b'], {"a": "a", "b": "b"}, ".")
True
>>> _simple_layout(['a', 'a.a1', 'a.a1.a2', 'b'], {"a": "_a", "b": "_b"}, ".")
False
>>> _simple_layout(['a', 'a.a1', 'a.a1.a2', 'b'], {"a": "_a"}, "/tmp/myproj")
False
>>> _simple_layout(['a', 'a.a1', 'a.a1.a2', 'b'], {"a.a1.a2": "_a2"}, ".")
False
>>> _simple_layout(['a', 'a.b'], {"": "src", "a.b": "_ab"}, "/tmp/myproj")
False
>>> # Special cases, no packages yet:
>>> _simple_layout([], {"": "src"}, "/tmp/myproj")
True
>>> _simple_layout([], {"a": "_a", "": "src"}, "/tmp/myproj")
False
rS   c           	   3     >#    U  H7  u  p[         R                  " [        T/UR                  S 5      Q76 U5      v   M9     g7fr   N)r   	same_pathr   split)r+  keyvaluer   s      r?   r-  !_simple_layout.<locals>.<genexpr>  s:      (JC 	V5ciin5u==(s   ?A)	r   r   rb   re   
commonpathr   _parent_pathrf  all)r  rd   rY   r  layoutr   s        @r?   r   r   l  s    > PXXx$S{CCxFX;B:--WWflln EFF  ,,.  	 Ys   Bc                h    UR                  U 5      nUR                  S[        R                  -   5      $ )a  Infer the parent path containing a package, that if added to ``sys.path`` would
allow importing that package.
When ``pkg`` is directly mapped into a directory with a different name, return its
own path.
>>> _parent_path("a", "src/a")
'src'
>>> _parent_path("b", "src/c")
'src/c'
rL  )removesuffixrstriprb   rP  )r  pkg_pathr   s      r?   r  r    s+     ""3'F==rvv&&rB   c              #    #    [        U R                  =(       d    / 5       S h  vN   U R                  =(       d    / nU Vs/ s H  nSU;   d  M  UPM     nnU R                  (       a  U R                  v   OFU R                  =(       d    / nX4 Vs/ s H!  nSUR
                  ;   d  M  UR
                  PM#     sn-  nU H  nUR                  S5      u  n  nUv   M     g  Ns  snf s  snf 7f)Nr   )iterr  
py_modulesext_packageext_modulesrs   
rpartition)	r_   r  modnested_modulesr  xmodulepackage_s	            r?   r   r     s     DMM'R(((&BJ%/>Zc3#:cZN>&&,";H;a#-6166;HH ))#.A ! ) ?
 Is9   "C-C!C-
C#C#;C-C()C(9)C-#
C-c              #     #    U R                   =(       d    / nS U 5        S h  vN   U R                  (       d'  U R                  =(       d    / nS U 5        S h  vN   g g  N= N7f)Nc              3  6   #    U  H  nS U;  d  M  Uv   M     g7fr  rC   )r+  r  s     r?   r-  *_find_top_level_modules.<locals>.<genexpr>  s     <zS^zs   
	c              3  ^   #    U  H#  nS UR                   ;  d  M  UR                   v   M%     g7fr  )rs   )r+  r  s     r?   r-  r    s!     EKq3aff3DFAFFKs   --)r  r  r  )r_   r  r  s      r?   r  r    sX     &BJ<z<<<&&,"EKEEE  = 	Fs!   "A&A"6A&A$A&$A&c                    [        U 5       Vs0 s H  nU[        [        X1U5      5      _M     nn[        U5      $ s  snf rV   )sorted_absolute_rootr   _remove_nested)r  rd   ra   r  	pkg_rootss        r?   r  r    sM     (#!#C 	^-cIJJ#  !
 )$$!s    ;c                    [        U 5      nUR                  nUR                  5       (       a  [        UR	                  5       5      $ [        UR	                  5       UR
                  -  5      $ )z(Works for packages and top-level modules)r   r   r   r   r   rs   )re   path_r   s      r?   r  r    sK    JE\\F||~~5==?##6>>#ejj011rB   c           	   #  "  #    U  H  nSU;  a  M  UR                  S5      n[        [        U5      S-
  SS5       HL  nSR                  USU 5      n[	        [        X@S5      5      nUR                  5       (       a  X@;  d  MH  Uv   MN     M     g7f)a  By carefully designing ``package_dir``, it is possible to implement the logical
structure of PEP 420 in a package without the corresponding directories.

Moreover a parent package can be purposefully/accidentally skipped in the discovery
phase (e.g. ``find_packages(include=["mypkg.*"])``, when ``mypkg.foo`` is included
by ``mypkg`` itself is not).
We consider this case to also be a virtual namespace (ignoring the original
directory) to emulate a non-editable installation.

This function will try to find these kinds of namespaces.
r   r"   r   NrS   )r  rangelenrf   r   r   r   )r  r  partsipartial_namere   s         r?   r  r    s      c>		#s5zA~q"-A88E"1I.L),2FGD;;==L$A"" .	 s   A<BBc              #     #    U  HV  n[        X!S5      n[        U5      R                  5       (       d  M/  [        US5      R                  5       (       a  MP  X#/4v   MX     g 7f)NrS   z__init__.py)r   r   r   )r  r  r  re   s       r?   r  r    sO       4:tD-'@'G'G'I'I- s   .A A A c                  ^^ [        U R                  5       5      n[        [        U R	                  5       5      5       HB  u  mm[        UU4S jU R	                  5        5       5      (       d  M1  UR                  T5        MD     U$ )Nc              3  Z   >#    U  H   u  pTU:g  =(       a    [        TTX5      v   M"     g 7frV   )
_is_nested)r+  other
other_pathre   r  s      r?   r-  !_remove_nested.<locals>.<genexpr>  s0      
%6! 5LEZT5EE%6s   (+)r  copyreversedr6  rf  anypop)r  rl  re   r  s     @@r?   r  r    sh    ).."#Fd9??#456	T 
%.__%6
 
 
 JJsO 7 MrB   c                   [         R                  " U5      nU R                  USS5      R                  S5      R	                  S5      nU R                  U5      =(       a#    U[         R                  " [        U/UQ76 5      :H  $ )au  
Return ``True`` if ``pkg`` is nested inside ``parent`` both logically and in the
file system.
>>> _is_nested("a.b", "path/a/b", "a", "path/a")
True
>>> _is_nested("a.b", "path/a/b", "a", "otherpath/a")
False
>>> _is_nested("a.b", "path/a/b", "c", "path/c")
False
>>> _is_nested("a.a", "path/a/a", "a", "path/a")
True
>>> _is_nested("b.a", "path/b/a", "a", "path/a")
False
rS   r"   r   )r   normpathrO  stripr  
startswithr   )r  r  r   parent_pathnorm_pkg_pathrests         r?   r  r    so     NN8,M;;vr1%++C066s;D>>&! mu~~[ 4 8 ' rB   c                \    [         R                  " U SS9  [        R                  " U 5        U $ )zFCreate a directory ensured to be empty. Existing files may be removed.T)ignore_errors)r   rmtreerb   makedirs)dir_s    r?   r   r     s!    NN4t,KKKrB   c                  *    \ rS rSrSS jrS rS rSrg)r   i  c                B    Xl         X@l        X l        X0l        / U l        g rV   )r`   ra   r   editable_namerg  )r[   r`   r   r  ra   s        r?   r&  _NamespaceInstaller.__init__   s     (  0*"$rB   c                    [         R                  R                  U R                  U R                  U R
                  -   5      $ )zInstallation target.)rb   re   rf   r   r  	nspkg_extrZ   s    r?   _get_nspkg_file#_NamespaceInstaller._get_nspkg_file'  s,    ww||D1143E3E3VWWrB   c                >    [        [        U R                  5      5      $ )z1Where the modules/packages should be loaded from.)reprr   ra   rZ   s    r?   	_get_root_NamespaceInstaller._get_root+  s    C&''rB   )r`   r  r   rg  ra   Nr
  )rF   rG   rH   rI   r&  r  r  rM   rC   rB   r?   r   r     s    %X(rB   r   a  from __future__ import annotations
import sys
from importlib.machinery import ModuleSpec, PathFinder
from importlib.machinery import all_suffixes as module_suffixes
from importlib.util import spec_from_file_location
from itertools import chain
from pathlib import Path

MAPPING: dict[str, str] = {mapping!r}
NAMESPACES: dict[str, list[str]] = {namespaces!r}
PATH_PLACEHOLDER = {name!r} + ".__path_hook__"


class _EditableFinder:  # MetaPathFinder
    @classmethod
    def find_spec(cls, fullname: str, path=None, target=None) -> ModuleSpec | None:  # type: ignore
        # Top-level packages and modules (we know these exist in the FS)
        if fullname in MAPPING:
            pkg_path = MAPPING[fullname]
            return cls._find_spec(fullname, Path(pkg_path))

        # Handle immediate children modules (required for namespaces to work)
        # To avoid problems with case sensitivity in the file system we delegate
        # to the importlib.machinery implementation.
        parent, _, child = fullname.rpartition(".")
        if parent and parent in MAPPING:
            return PathFinder.find_spec(fullname, path=[MAPPING[parent]])

        # Other levels of nesting should be handled automatically by importlib
        # using the parent path.
        return None

    @classmethod
    def _find_spec(cls, fullname: str, candidate_path: Path) -> ModuleSpec | None:
        init = candidate_path / "__init__.py"
        candidates = (candidate_path.with_suffix(x) for x in module_suffixes())
        for candidate in chain([init], candidates):
            if candidate.exists():
                return spec_from_file_location(fullname, candidate)
        return None


class _EditableNamespaceFinder:  # PathEntryFinder
    @classmethod
    def _path_hook(cls, path) -> type[_EditableNamespaceFinder]:
        if path == PATH_PLACEHOLDER:
            return cls
        raise ImportError

    @classmethod
    def _paths(cls, fullname: str) -> list[str]:
        paths = NAMESPACES[fullname]
        if not paths and fullname in MAPPING:
            paths = [MAPPING[fullname]]
        # Always add placeholder, for 2 reasons:
        # 1. __path__ cannot be empty for the spec to be considered namespace.
        # 2. In the case of nested namespaces, we need to force
        #    import machinery to query _EditableNamespaceFinder again.
        return [*paths, PATH_PLACEHOLDER]

    @classmethod
    def find_spec(cls, fullname: str, target=None) -> ModuleSpec | None:  # type: ignore
        if fullname in NAMESPACES:
            spec = ModuleSpec(fullname, None, is_package=True)
            spec.submodule_search_locations = cls._paths(fullname)
            return spec
        return None

    @classmethod
    def find_module(cls, _fullname) -> None:
        return None


def install():
    if not any(finder == _EditableFinder for finder in sys.meta_path):
        sys.meta_path.append(_EditableFinder)

    if not NAMESPACES:
        return

    if not any(hook == _EditableNamespaceFinder._path_hook for hook in sys.path_hooks):
        # PathEntryFinder is needed to create NamespaceSpec without private APIS
        sys.path_hooks.append(_EditableNamespaceFinder._path_hook)
    if PATH_PLACEHOLDER not in sys.path:
        sys.path.append(PATH_PLACEHOLDER)  # Used just to trigger the path hook
c                    [        [        UR                  5       [        R                  " S5      S95      n[
        R                  XUS9$ )zWCreate a string containing the code for the``MetaPathFinder`` and
``PathEntryFinder``.
r   )r  rs   r   r   )r  r  rf  operator
itemgetter_FINDER_TEMPLATEformatr  s      r?   r  r    s<     6'--/x/B/B1/EFGG""*"UUrB   c                      \ rS rSrSrSrg)r  i  zCFile system does not seem to support either symlinks or hard links.rC   N)rF   rG   rH   rI   rJ   rM   rC   rB   r?   r  r    s    MrB   r  )r  r   rE   r  )r  r   rE   bool)r  Iterable[str]rd   dict[str, str]rY   r   rE   r  )r_   r   rE   Iterator[str])r  r  rd   r  ra   r   rE   r  )re   r   rE   r   )r  r  rE   r  )r  r  r  r  rE   zIterator[tuple[str, list[str]]])r  r  rE   r  )
r  r   r  r   r   r   r  r   rE   r  )r  r,   rE   r,   )rs   r   r   r  r   zdict[str, list[str]]rE   r   )crJ   
__future__r   r  loggingr	  rb   r   r   collections.abcr   r   r   
contextlibr   enumr   inspectr	   	itertoolsr
   r   pathlibr   tempfiler   typesr   typingr   r   r   r   r   rS   r   r   r   r   r   r   r   r3   r   r   	discoveryr   r_   r   warningsr    r!   r#   r   r$   r   r%   r|   r&   r   r'   r   r(   r   typing_extensionsr)   _vendor.wheel.wheelfiler+   r,   	getLoggerrF   r   r/   rq  r9  rO   r  r  r   r  r0  re  r   r  r   r  r  r  r  r  r  r  r   	Installerr   r  r  	FileErrorr  rC   rB   r?   <module>r$     s  
 # 	   	   7 7    $  '  C C J J  ! )  D % . 1 . + C&3T!


H
%&$D &$R ^8W ^8B	
x 
 <K<
 K<\>< ><B*(&&*8&GN&	&R' F
%
%"
% 
% 	
%2#0  $2 $ 
,(*.. ("V rV
V)V7KVVN(( NrB   