
    n&ph                    h   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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  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-J.r.  SSK/J0r0J1r1  SSK2J2r3  SSK4J4r5  SSK6J6r7  SSK8J8r9  SSK:J:r;  SSK<J<r=  \(       a  SSK>J?r?  SSK@JArA  \" S\'S9rB\R                  " \D5      rE " S S \5      rFS!rGS"rH " S# S$\!5      rI " S% S&\5      rJ " S' S(5      rK " S) S*\K5      rL " S+ S,5      rMS@S- jrNSAS. jrO        SBS/ jrPS0 rQSCS1 jrRSCS2 jrS        SDS3 jrTSES4 jrUSFS5 jrV      SGS6 jrWSHS7 jrXSIS8 jrYSJS9 jrZ " S: S;\&R                  5      r\S<r]        SKS= jr^ " S> S?\%R                  5      r`g)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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)
_EditableMode4   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      T/var/www/html/venv/lib/python3.13/site-packages/setuptools/command/editable_wheel.pyconvert_EditableMode.convert@   sv     (((

111$$'>thFV%WXXH(--* ;  U##     N)r<   
str | Nonereturnr.   )__name__
__module____qualname____firstlineno____doc__STRICTr6   r4   classmethodr?   __static_attributes__rB   rA   r>   r.   r.   4   s*     FGF$ $rA   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	 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_wheelg   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 c                <    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_optionsu   s     !	rA   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curdirrW   package_dirr   rU   pathjoin)rY   r]   s     r>   finalize_optionseditable_wheel.finalize_options{   s_      ==5BII++1rT]]Tbggll4;K;KV.TUrA   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)rU   mkdir_ensure_dist_inforeinitialize_commandget_finalized_commandwrite_wheelfilerV   _create_wheel_file	Exceptionr^   nameget_namer   add_note)rY   ri   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)rV   r   dist_info_clsrl   rU   
output_dirensure_finalizedrv   strendswithr   exists)rY   r$   s     r>   rk    editable_wheel._ensure_dist_info   s    %]D,E,Ek,RSI#'==I &&(MMO!*!8!8Dt))*33LAAAA**J7>>@@@@rA   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 )NrR   .)	r^   namespace_packagesr   rW   rb   getresolve_NamespaceInstallerinstall_namespaces)rY   installation_dir
pth_prefixr]   r_   	installers         r>   _install_namespaces"editable_wheel._install_namespaces   s_      &&(($*:*:*>*>r3*GHPPR'
U	$$&rA   c                    U R                   (       a  [        U R                   5      R                  O	[        5       n[        [        UR                  S5      5      n[        US 5      $ )Nz
*.egg-info)rV   r   parentmapr}   globnext)rY   
parent_dir
candidatess      r>   _find_egg_info_dir!editable_wheel._find_egg_info_dir   sH    8<8J8JT$,,-44PTPV
jool;<
J%%rA   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_clsrl   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|   )rY   rq   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&!   "rA   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   )rY   r]   r"   cmd_namecmds        r>   r   !editable_wheel._set_editable_mode   si      $$W-..0H&&x0CsO,,$(!i((" 1rA   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)rm   r   r   extendr   updater   )rY   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 ~rA   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)rY   	dist_namer   r   r   r   r   s          r>   _run_build_commands"editable_wheel._run_build_commands  sb     	iL##%446)$)$&!~rA   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)rm   r   typer   _safely_runrun_command)rY   r"   rq   r   s       r>   r   %editable_wheel._run_build_subcommands  sf     **73**,D,,T2Cz!d3i|&C  &  & -rA   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   rp   r    r:   	traceback
format_exc)rY   r   s     r>   r   editable_wheel._safely_run-  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*   rm   rq   rd   get_tagr   rU   r   unlinkr   rV   shutilcopytreer   r   _select_strategywrite_files)rY   ri   r*   r$   r   tag	build_tagarchive_name
wheel_pathr   r   	build_tmpunpackedlibtmpunpacked_dist_infor   r   strategy	wheel_objs                       r>   ro   !editable_wheel._create_wheel_fileI  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   )rY   categoryhas_categorys      r>   r   editable_wheel._run_installe  sX    t00D
2CTJLNNLL;xj0@ABxz23 +<rA   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"   rR   r   )r   rW   r.   r?   r<   rJ   
_empty_dir	_LinkTreer^   _find_packages_simple_layoutrb   r4   setr   
_StaticPth_TopLevelFinder)rY   rq   r   r   
build_namerW   r<   auxiliary_dirpackageshas_simple_layoutis_compat_modesrc_dirs               r>   r   editable_wheel._select_strategyk  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7rA   )rU   rV   r<   rb   rW   rD   None)rD   rC   )rq   r}   r   r   r   r   r   r   )rD    tuple[list[str], dict[str, str]])
r   r}   r   r   r   r   r   r   rD   r
  )r   r}   )r   r}   )rq   r}   r   r}   r   r   rD   EditableStrategy)rE   rF   rG   rH   rI   descriptionr	   r.   user_optionsrZ   re   rv   rk   r   r   r   r   r   r   r   r   ro   r   r   rL   rB   rA   r>   rN   rN   g   s    
 WK 	LK	$!6!6!<"=>LV*	A'&
=#=#)0=#=D=#OV=#~	#   	
  
*',88488 8 	8
 
8rA   rN   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 rT   rB   )rY   r   r   r   s       r>   __call__EditableStrategy.__call__  s    rA   c                    g rT   rB   rX   s    r>   	__enter__EditableStrategy.__enter__  s    rA   c                    g rT   rB   rY   	_exc_type
_exc_value
_tracebacks       r>   __exit__EditableStrategy.__exit__  s    
 rA   rB   N)r   r*   r   	list[str]r   Mapping[str, str]rD   objectrD   r(   )r  ztype[BaseException] | Noner  zBaseException | Noner  zTracebackType | NonerD   r  )rE   rF   rG   rH   r  r  r  rL   rB   rA   r>   r  r    sW    '0;L	 %- ) )	
 
rA   r  c                  L    \ 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 rT   r]   rq   path_entries)rY   r]   rq   r#  s       r>   __init___StaticPth.__init__  s    		(rA   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rT   )r}   r   ).0ps     r>   	<genexpr>&_StaticPth.__call__.<locals>.<genexpr>  s      H6GC		,,6Gs   &(r   .pth)rd   r#  _encode_pthwritestrrq   )rY   r   r   r   entriescontentss         r>   r  _StaticPth.__call__  sG    ))Hd6G6GHH'"~.tyyk6ArA   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   r`   fspathr#  r   warning_LENIENT_WARNINGrY   msgs     r>   r  _StaticPth.__enter__  sH    		c"))T../	03 4	 	../rA   c                    g rT   rB   r  s       r>   r  _StaticPth.__exit__  s     	rA   r"  N)r]   r   rq   r}   r#  z
list[Path]rD   r	  r   r*   r   r  r   r  r  r  r  r  r  r  r  rD   r	  )	rE   rF   rG   rH   r$  r  r  r  rL   rB   rA   r>   r   r     s=    )
B
  	
 
rA   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$  )rY   r]   rq   r  r   	__class__s        r>   r$  _LinkTree.__init__  sV     "-0i002))*5??
d&8&8%9:rA   c                H   > U R                  X#5        [        TU ]	  XU5        g rT   )_create_linksrC  r  )rY   r   r   r   rD  s       r>   r  _LinkTree.__call__  s     5*w/rA   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}   replacer`   sep)rY   filerc   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_dirrj   rB  )rY   relative_outputsrc_filerU  dests        r>   _create_file_LinkTree._create_file  sJ    !!O3{{!!##KKd+

8
-rA   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)rS  rh   symhardc              3  N   >#    U  H  u  pTR                  U5      U4v   M     g 7frT   )rP  )r)  kvrY   s      r>   r+  *_LinkTree._create_links.<locals>.<genexpr>  s%     XAWt--a0!4AWs   "%rT  )r  rj   _can_symlink_filesitemsrP  rZ  )rY   outputsoutput_mapping	link_type
normalisedr`  ra  mappingsoutputrelativesrcs   `          r>   rG  _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   r6  _STRICT_WARNINGr8  s     r>   r  _LinkTree.__enter__  s    No-.rA   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:   rY   r  r  r  r9  s        r>   r  _LinkTree.__exit__  s2      !	 	5s;rA   )rB  r  r   )
r]   r   rq   r}   r  r   r   r   rD   r	  r=  )rO  r}   rD   rC   rT   )rW  r}   rX  r}   )rf  r  r  r>  )rE   rF   rG   rH   rI   r$  r  rP  rZ  rG  r  r  rL   __classcell__)rD  s   @r>   r   r     s    
;
; 
; 	
;
 
; 

;0.=
<< < 	<
 
< <rA   r   c                  `    \ 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 rT   r]   rq   )rY   r]   rq   s      r>   r$  _TopLevelFinder.__init__  s    		rA   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rT   rB   )r)  nss     r>   r+  0_TopLevelFinder.template_vars.<locals>.<genexpr>	  s     D$Cbb$Cs   rR   r   z.finder)r]   r_   r`   ra   r
   r   _find_top_level_modulesrb   _find_package_rootsdict_find_namespacesr  _find_virtual_namespacesr   r   rq   r   safe_identifier)rY   r_   	top_levelrb   rootsnamespaces_pkglegacy_namespacesr   rq   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_templater.  rq   )rY   r  rq   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 rT   )r  r/  )rY   r   r   r   rO  r  s         r>   r  _TopLevelFinder.__call__$  s#    !446MDNN4) 7rA   c                B    Sn[         R                  U[        -   5        U $ )Nz=Editable install will be performed using a meta path finder.
)r   r6  r7  r8  s     r>   r  _TopLevelFinder.__enter__(  s    N../rA   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.
        rr  )r   r:   rs  s        r>   r  _TopLevelFinder.__exit__-  s     	5s;rA   rx  N)r]   r   rq   r}   rD   r	  )rD   z5tuple[str, str, dict[str, str], dict[str, list[str]]])rD   zIterator[tuple[str, bytes]]r=  r  r>  )rE   rF   rG   rH   r$  r  r  r  r  r  rL   rB   rA   r>   r   r     sF    269*

<
< 
< 	
<
 

<rA   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>   r.  r.  :  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OSErrorr`   symlink
is_symlink	read_textrU  rp   LinksNotSupported)base_dirr   path1path2rt   r9  s         r>   rc  rc  O  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
rR   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   r`   rc   
commonpathr   _parent_pathrd  all)r  rb   rW   r  layoutr   s        @r>   r   r   c  s    > PXXx$S{CCxFX;B:--WWflln EFF  ,,.  	 Ys   Bc                    UR                  U 5      (       a  US[        U 5      *  OU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'
NrJ  )r~   lenrstripr`   rN  )r  pkg_pathr   s      r>   r  r    s?     '/&7&7&<&<XkS	"(F==rvv&&rA   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_modulesrq   
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  rB   )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  )rq   )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 rT   )sorted_absolute_rootr   _remove_nested)r  rb   r_   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   rq   )rc   path_r   s      r>   r  r    sK    JE\\F||~~5==?##6>>#ejj011rA   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   NrR   )r  ranger  rd   r   r   r   )r  r  partsipartial_namerc   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)NrR   z__init__.py)r   r   r   )r  r  r  rc   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rT   )
_is_nested)r)  other
other_pathrc   r  s      r>   r+  !_remove_nested.<locals>.<genexpr>  s0      
%6! 5LEZT5EE%6s   (+)r  copyreversedr4  rd  anypop)r  rj  rc   r  s     @@r>   r  r    sh    ).."#Fd9??#456	T 
%.__%6
 
 
 JJsO 7 MrA   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
rR   r!   r   )r   normpathrM  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 ' rA   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   rmtreer`   makedirs)dir_s    r>   r   r     s!    NN4t,KKKrA   c                  *    \ rS rSrSS jrS rS rSrg)r   i  c                P    Xl         X@l        X l        X0l        / U l        SU l        g )NF)r^   r_   r   editable_namere  dry_run)rY   r^   r   r  r_   s        r>   r$  _NamespaceInstaller.__init__  s'    (  0*"$rA   c                    [         R                  R                  U R                  U R                  U R
                  -   5      $ )zInstallation target.)r`   rc   rd   r   r  	nspkg_extrX   s    r>   _get_nspkg_file#_NamespaceInstaller._get_nspkg_file  s,    ww||D1143E3E3VWWrA   c                >    [        [        U R                  5      5      $ )z1Where the modules/packages should be loaded from.)reprr}   r_   rX   s    r>   	_get_root_NamespaceInstaller._get_root#  s    C&''rA   )r^   r  r  r   re  r_   Nr  )rE   rF   rG   rH   r$  r  r  rL   rB   rA   r>   r   r     s    X(rA   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                n    [        [        UR                  5       S S95      n[        R	                  XUS9$ )zWCreate a string containing the code for the``MetaPathFinder`` and
``PathEntryFinder``.
c                    U S   $ )Nr   rB   )r*  s    r>   <lambda>"_finder_template.<locals>.<lambda>  s    1rA   )r  rq   r   r   )r  r  rd  _FINDER_TEMPLATEformatr	  s      r>   r  r    s1     6'--/~>?G""*"UUrA   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.rB   N)rE   rF   rG   rH   rI   rL   rB   rA   r>   r  r    s    MrA   r  )r  r}   rD   r  )r  r   rD   bool)r  Iterable[str]rb   dict[str, str]rW   r   rD   r  )r]   r   rD   Iterator[str])r  r  rb   r  r_   r   rD   r  )rc   r   rD   r}   )r  r  rD   r  )r  r  r  r  rD   zIterator[tuple[str, list[str]]])r  r  rD   r  )
r  r}   r  r}   r   r}   r  r}   rD   r  )r  r+   rD   r+   )rq   r}   r   r  r   zdict[str, list[str]]rD   r}   )arI   
__future__r   r  loggingr`   r   r   collections.abcr   r   r   
contextlibr   enumr   inspectr	   	itertoolsr
   r   pathlibr   tempfiler   typesr   typingr   r   r   r   rR   r   r   r   r   r   r   r   r2   r   r   	discoveryr   r]   r   warningsr   r    r"   r   r#   r   r$   rz   r%   r   r&   r   r'   r   typing_extensionsr(   _vendor.wheel.wheelfiler*   r+   	getLoggerrE   r   r.   ro  r7  rN   r  r   r   r   r.  rc  r   r  r   r~  r  r  r  r  r  r  r   	Installerr   r
  r  	FileErrorr  rB   rA   r>   <module>r#     s  
 # 	  	   7 7    $  '  9 9 J J  ! )  D % . 1 . + C&3T!


H
%&$D &$R \8W \8~
x 
 8I<
 I<X<< <<~*(&&*8&GN&	&R' F
%
%"
% 
% 	
%2#0  $2 $ 
,(*.. ($V rV
V)V7KVVN(( NrA   