
    YHh                    J   d Z 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	m
Z
mZ ddlmZ ddlmZ ddlmZ ddlmZmZ dd	lmZ dd
lmZ ddlmZ ddlmZmZmZmZ ddl m!Z!m"Z"m#Z#m$Z$m%Z%m&Z& ddl#m'Z' ddl(m)Z)m*Z* ddl+m,Z, ddl-m.Z. ddl/m0Z0m1Z1 ddl2m2Z3 ddl4m4Z5 ddl6m6Z7 ddl8m8Z9 ddl:m:Z; ddl<m<Z= erddl>m?Z? ddl@mAZA  ede'      ZB ej                  eD      ZE G d d e      ZFd!ZGd"ZH G d# d$e!      ZI G d% d&e      ZJ G d' d(      ZK G d) d*eK      ZL G d+ d,      ZMd@d-ZNdAd.ZO	 	 	 	 	 	 	 	 dBd/ZPd0 ZQdCd1ZRdCd2ZS	 	 	 	 	 	 	 	 dDd3ZTdEd4ZUdFd5ZV	 	 	 	 	 	 dGd6ZWdHd7ZXdId8ZYdJd9ZZ G d: d;e&j                        Z\d<Z]	 	 	 	 	 	 	 	 dKd=Z^ G d> d?e%j                        Z`y)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                  .    e Zd ZdZdZdZdZedd       Zy)_EditableModea  
    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                    |st         j                  S |j                         }|t         j                  vrt	        j
                  d|d      |dk(  rt        j                  ddd       t         |   S )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      Z/var/www/html/planif/env/lib/python3.12/site-packages/setuptools/command/editable_wheel.pyconvertz_EditableMode.convert@   sv     (((

111$$'>thFV%WXXH(--* ;  U##    N)r;   
str | Nonereturnr.   )	__name__
__module____qualname____doc__STRICTr5   r3   classmethodr>    r?   r=   r.   r.   4   s*     FGF$ $r?   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                      e Zd ZdZdZdddd eej                  xs d      fgZd Zdd	Z	dd
Z
d Zd ZddZ	 	 	 	 	 	 	 	 ddZd ZddZ	 	 	 	 	 	 	 	 	 	 ddZddZddZd ZddZ	 	 	 	 	 	 	 	 ddZy)editable_wheelzBuild '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                <    d | _         d | _        d | _        d | _        y N)dist_dirdist_info_dirproject_dirr;   selfs    r=   initialize_optionsz!editable_wheel.initialize_optionsu   s     !	r?   c                   | j                   }|j                  xs t        j                  | _        |j
                  xs i | _        t        | j                  xs* t        j                  j                  | j                  d            | _        y )Ndist)
distributionsrc_rootoscurdirrR   package_dirr   rP   pathjoin)rT   rW   s     r=   finalize_optionszeditable_wheel.finalize_options{   s_      ==5BII++1rT]]Tbggll4;K;KV.TUr?   c                   	 | j                   j                  d       | j                          | j                  d       | j	                  d      }|j                  | j                         | j                  |       y # t        $ rR}| j                  j                  xs | j                  j                         }t        j                  |d| d        d }~ww xY w)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)rP   mkdir_ensure_dist_inforeinitialize_commandget_finalized_commandwrite_wheelfilerQ   _create_wheel_file	ExceptionrX   nameget_namer   add_note)rT   rb   exprojects       r=   runzeditable_wheel.run   s    	MM.""$ %%m444]CK''(:(:;##K0 	'',,L0A0A0J0J0LGNNEgY Of f 	s   A:A= =	CACCc                x   | j                   bt        t        | j                  d            }| j                  |_        |j                          |j                          |j                   | _         y t        | j                         j                  d      sJ t        | j                   d      j                         sJ y )Nr$   z
.dist-infoMETADATA)rQ   r   dist_info_clsre   rP   
output_dirensure_finalizedro   strendswithr   exists)rT   r$   s     r=   rd   z editable_wheel._ensure_dist_info   s    %]D,E,Ek,RSI#'==I &&(MMO!*!8!8Dt))*33LAAA**J7>>@@@r?   c                    | j                   }|j                  sy t        | j                  | j                  j                  dd            j                         }t        ||||      }|j                          y )NrM   .)	rX   namespace_packagesr   rR   r\   getresolve_NamespaceInstallerinstall_namespaces)rT   installation_dir
pth_prefixrW   rY   	installers         r=   _install_namespacesz"editable_wheel._install_namespaces   sd      &&(($*:*:*>*>r3*GHPPR'.>
HU	$$&r?   c                    | j                   rt        | j                         j                  n	t               }t        t        |j                  d            }t        |d       S )Nz
*.egg-info)rQ   r   parentmapru   globnext)rT   
parent_dir
candidatess      r=   _find_egg_info_dirz!editable_wheel._find_egg_info_dir   sH    8<8J8JT$,,-44PTPV
jool;<
J%%r?   c                   | j                   }t        |      }t        |      }t        t        || dd            }t        t        || dd            }t        t        || dd            }	t        t        |j                  dd            }
t        |      |
_        d|
_        t        t        |j                  dd            }t        t        |j                  d	d            }|x|_
        x|_        |_        |x|_        x|_        |_        |	x|_        |_        ||_        ||_        |j)                  d
      }d|_        t        t,        |j)                  d            }d|_        t        |      |_        t        t2        |j)                  d            }d|_        | j7                         |_        | j;                          |j=                          |j=                          y)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)rX   ru   r   r   egg_info_clsre   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_modert   )rT   rj   unpacked_wheelr   tmp_dirrW   wheelr   r   r   r%   r"   r&   r   r'   r#   s                   r=   _configure_buildzeditable_wheel._configure_build   s      N#	N	44&?@d>dV5>9EFd>dV5>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&!   "r?   c                    | j                   }|j                  d      }|j                         D ];  }|j                  |      }t        |d      rd|_        (t        |d      s5d|_        = y)z8Set the ``editable_mode`` flag in the build sub-commandsr"   editable_modeTinplaceN)rX   r   get_sub_commandshasattrr   r   )rT   rW   r"   cmd_namecmds        r=   r   z!editable_wheel._set_editable_mode   sh      $$W-..0 	#H&&x0CsO,$(!i("	#r?   c                >   g }i }| j                  d      }|j                         D ]r  }| j                  |      }t        |d      r#|j                  |j	                         xs g        t        |d      sP|j                  |j                         xs i        t ||fS )Nr"   get_outputsget_output_mapping)rf   r   r   extendr   updater   )rT   filesmappingr"   r   r   s         r=   _collect_build_outputsz%editable_wheel._collect_build_outputs   s    "$**73..0 	?H,,X6CsM*S__.4"5s01s557=2>	? g~r?   c                    | j                  ||||       | j                          | j                         \  }}| j                  d       | j                  d       | j                  d       ||fS )Nr   r   r   )r   _run_build_subcommandsr   _run_install)rT   	dist_namer   r   r   r   r   s          r=   _run_build_commandsz"editable_wheel._run_build_commands  sj     	iGL##%446w)$)$&!g~r?   c                    | j                  d      }|j                         D ]L  }| j                  |      }|dk(  r#t        |      t        ur| j	                  |       <| j                  |       N y)a}  
        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)rf   r   typer   _safely_runrun_command)rT   r"   rj   r   s       r=   r   z%editable_wheel._run_build_subcommands  sk     **73**, 	'D,,T2Cz!d3i|&C  &  &	'r?   c                    	 | j                  |      S # t        $ r5 t        j                  ddt	        j
                          d| d| d       Y y w xY w)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   ri   r    r9   	traceback
format_exc)rT   r   s     r=   r   zeditable_wheel._safely_run-  sp    	##H-- 	(--B%%'( )8 9Az B-
 .6J 7	s    ;AAc           
        ddl m} | j                  d      }|j                  }dj	                  |j                               }d}| d| d| d}t        | j                  |      }|j                         r|j                          t        |      }	t        d      }
t        d	      }|	5 }|
5 }|5 }t        |t        | j                        j                        }t        j                  | j                  |       | j                  ||       | j                  ||||      \  }}| j!                  |||      }|5   ||d
      5 } ||||       |j#                  |       d d d        d d d        d d d        d d d        d d d        |S # 1 sw Y   +xY w# 1 sw Y   /xY w# 1 sw Y   3xY w# 1 sw Y   7xY w# 1 sw Y   |S xY w)Nr   r)   r$   -z
0.editablez.whl)suffixz
.build-libz.build-tempw)wheel.wheelfiler*   rf   rj   r^   get_tagr   rP   rw   unlinkr   rQ   shutilcopytreer   r   _select_strategywrite_files)rT   rb   r*   r$   r   tag	build_tagarchive_name
wheel_pathr   r   	build_tmpunpackedlibtmpunpacked_dist_infor   r   strategy	wheel_objs                       r=   rh   z!editable_wheel._create_wheel_fileI  s   -..{;	NN	hh{**,- 	#Ai[#d;$--6
+<@&l;	&m<	 	0x 	0c9 	0!%hT5G5G0H0M0M!NOOD..0BC$$Xy9!55i3PSTNE7,,YSAH 09Z5 0E73%%h/0 0	0 	0 	0 	0 0 0 0	0 	0 	0 	0 	0 sm   ,F:/F.2BF":
F	F
 F	(F"0F.8F:
FF	FF""F+'F..F7	3F::Gc                    t        | j                  d| d       }|r6 |       r.t        j                  d| d       | j	                  d|        y y y )Nhas_zInstalling z as non editableinstall_)getattrrX   _loggerinfor   )rT   categoryhas_categorys      r=   r   zeditable_wheel._run_installe  sV    t00D
2CTJLNLL;xj0@ABxz23 +<r?   c                l   d| d| }t        | j                        }t        j                  | j                        }|t        j
                  u r8t        t        | j                  d|            }t        | j                  |||      S t        | j                        }t        || j                  |      }	|t        j                  u }
t        | j                        dhk(  r|	s|
r>| j                  j                  dd      }t        | j                  |t        ||      g      S t!        | j                  |      S )zDDecides which strategy to use to implement an editable installation.__editable__.r   r"   rM   ry   )r   rR   r.   r>   r;   rF   
_empty_dir	_LinkTreerX   _find_packages_simple_layoutr\   r3   setr{   
_StaticPth_TopLevelFinder)rT   rj   r   r   
build_namerR   r;   auxiliary_dirpackageshas_simple_layoutis_compat_modesrc_dirs               r=   r   zeditable_wheel._select_strategyk  s    %TF!C51
4++,$$TYY/='''&tD,<,<gz'RSMT..mYOO!$"3"34*8T5E5E{S!5!55t RD(->.&&**2s3Gd//['8R7STT t00$77r?   rA   None)rA   r@   )rj   ru   r   r   r   r   r   r   )rA    tuple[list[str], dict[str, str]])
r   ru   r   r   r   r   r   r   rA   r   )r   ru   )r   ru   )rj   ru   r   ru   r   r   rA   EditableStrategy)rB   rC   rD   rE   descriptionr	   r.   user_optionsrU   r_   ro   rd   r   r   r   r   r   r   r   r   rh   r   r   rH   r?   r=   rJ   rJ   g   s    
 WK 	LK	$!6!6!<"=>LV*	A'&
=#=#)0=#=D=#OV=#~	#   	
  
*',88488 8 	8
 
8r?   rJ   c                  D    e Zd Z	 	 	 	 	 	 	 	 ddZddZ	 	 	 	 	 	 	 	 ddZy)r   c                     y rO   rH   )rT   r   r   r   s       r=   __call__zEditableStrategy.__call__  s    r?   c                     y rO   rH   rS   s    r=   	__enter__zEditableStrategy.__enter__  s    r?   c                     y rO   rH   rT   	_exc_type
_exc_value
_tracebacks       r=   __exit__zEditableStrategy.__exit__  s    
 r?   N)r   r*   r   	list[str]r   Mapping[str, str]rA   objectrA   r(   )r  ztype[BaseException] | Noner  zBaseException | Noner  zTracebackType | NonerA   r  )rB   rC   rD   r   r   r  rH   r?   r=   r   r     sW    '0;L	 %- ) )	
 
r?   r   c                  <    e Zd ZddZddZddZ	 	 	 	 	 	 	 	 d	dZy)
r   c                .    || _         || _        || _        y rO   )rW   rj   path_entries)rT   rW   rj   r  s       r=   __init__z_StaticPth.__init__  s    		(r?   c                    dj                  d | j                  D              }t        | d      }|j                  d| j                   d|       y )N
c              3  N   K   | ]  }t        |j                                 y wrO   )ru   r|   ).0ps     r=   	<genexpr>z&_StaticPth.__call__.<locals>.<genexpr>  s     HC		,Hs   #%r   .pth)r^   r  _encode_pthwritestrrj   )rT   r   r   r   entriescontentss         r=   r   z_StaticPth.__call__  sG    ))Hd6G6GHH'"~.tyyk6Ar?   c                    dt        t        t        j                  | j                              d}t
        j                  |t        z          | S )Nz_
        Editable install will be performed using .pth file to extend `sys.path` with:
        z	
        )listr   rZ   fspathr  r   warning_LENIENT_WARNINGrT   msgs     r=   r   z_StaticPth.__enter__  sH    		c"))T../	03 4	 	../r?   c                     y rO   rH   r   s       r=   r  z_StaticPth.__exit__  s     	r?   N)rW   r   rj   ru   r  z
list[Path]rA   r   r   r*   r   r  r   r  r  r  r  r  r  r  r  rA   r   )rB   rC   rD   r  r   r   r  rH   r?   r=   r   r     s=    )
B
  	
 
r?   r   c                  ~     e Zd ZdZ	 	 	 	 	 	 	 	 	 	 d	 fdZd
 fdZddZdddZddZddZ		 	 	 	 	 	 	 	 ddZ
 xZS )r   a`  
    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                    t        |      | _        t        |      j                         | _        |j	                  d      j
                  | _        t        | !  ||| j                  g       y )Nr#   )	r   r   r|   r   r   	copy_file_filesuperr  )rT   rW   rj   r   r   	__class__s        r=   r  z_LinkTree.__init__  sX     "-0i002))*5??
td&8&8%9:r?   c                L    | j                  ||       t        | 	  |||       y rO   )_create_linksr&  r   )rT   r   r   r   r'  s       r=   r   z_LinkTree.__call__  s$    5'*w/r?   c                   t        t              5  t        |      j                         j	                  | j
                        }t        |      j                  t        j                  d      cd d d        S # 1 sw Y   y xY w)N/)
r   
ValueErrorr   r|   relative_tor   ru   replacerZ   sep)rT   filer]   s      r=   _normalize_outputz_LinkTree._normalize_output  s]    j! 	2:%%'33DNNCDt9$$RVVS1	2 	2 	2 s   AA55A>c                    | j                   |z  }|j                  j                         s|j                  j                  d       | j	                  |||       y )NT)parentslink)r   r   is_dirrc   r%  )rT   relative_outputsrc_filer5  dests        r=   _create_filez_LinkTree._create_file  sI    !!O3{{!!#KKd+

8T
-r?   c                     j                   j                  dd       t         j                         rdnd} fd|j                         D        }|D ci c]  \  }}|	|| }}}|D ]-  } j	                  |      }	|	s|	|vs j                  |	|       / |j                         D ]  \  }	}
 j                  |	|
|        y c c}}w )NT)r3  ra   symhardc              3  J   K   | ]  \  }}j                  |      |f  y wrO   )r1  )r  kvrT   s      r=   r  z*_LinkTree._create_links.<locals>.<genexpr>  s%     XAt--a0!4Xs    #r4  )r   rc   _can_symlink_filesitemsr1  r:  )rT   outputsoutput_mapping	link_type
normalisedr?  r@  mappingsoutputrelativesrcs   `          r=   r)  z_LinkTree._create_links  s       =/0B0BCE	XAUAUAWX
%/ATQ1=AqDAA 	4F--f5HHH4!!(F3	4
 &^^- 	=MHch)<	= Bs   
C!Cc                B    d}t         j                  |t        z          | S )Nz=Strict editable install will be performed using a link tree.
)r   r  _STRICT_WARNINGr  s     r=   r   z_LinkTree.__enter__  s    No-.r?   c                P    d| j                    d}t        j                  d|       y )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   r9   rT   r  r  r  r  s        r=   r  z_LinkTree.__exit__  s2      !	 	5s;r?   )
rW   r   rj   ru   r   r   r   r   rA   r   r   )r0  ru   rA   r@   rO   )r7  ru   r8  ru   )rD  r  r  r!  )rB   rC   rD   rE   r  r   r1  r:  r)  r   r  __classcell__)r'  s   @r=   r   r     s    
;
; 
; 	
;
 
; 

;0.=
<< < 	<
 
<r?   r   c                  L    e Zd ZddZd	dZd
dZddZddZ	 	 	 	 	 	 	 	 ddZy)r   c                     || _         || _        y rO   )rW   rj   )rT   rW   rj   s      r=   r  z_TopLevelFinder.__init__  s    		r?   c           
        | j                   j                  xs t        j                  }t	        t        | j                         t        | j                               }| j                   j                  xs i }t        |||      }t        t	        t        | j                   j                  xs g |      d t        |      D                    }| j                   j                  xs g D ci c](  }|t        ||| j                   j                  xs d      * }}i ||}d| j                   d}	t!        j"                  |	      }
|
|	||fS c c}w )Nc              3  $   K   | ]  }|g f 
 y wrO   rH   )r  nss     r=   r  z0_TopLevelFinder.template_vars.<locals>.<genexpr>	  s     Db"bDs   rM   r   z.finder)rW   rY   rZ   r[   r
   r   _find_top_level_modulesr\   _find_package_rootsdict_find_namespacesr   _find_virtual_namespacesrz   r   rj   r   safe_identifier)rT   rY   	top_levelr\   rootsnamespaces_pkglegacy_namespacesr   rj   finders              r=   template_varsz_TopLevelFinder.template_vars   s+   99%%2.35LTYY5WX	ii++1r#I{HE !3!3!9r5AD$<U$CD
 yy339r
 "3tyy/A/A/GRHH
 

 1U0/0
 tyyk1//5tWk11
s   %-Ec              #     K   | j                         \  }}}}t        t        |||      d      }| d|f t        d| d| d      }d| j                   d|f y w)Nutf-8z.pyzimport z; z
.install()r   r  )rb  bytes_finder_templater  rj   )rT   ra  rj   r   r^  contents         r=   get_implementationz"_TopLevelFinder.get_implementation  su     -1-?-?-A*g{(wDgN~w''xr&DEtyyk.88s   AAc                X    | j                         D ]  \  }}|j                  ||        y rO   )rh  r  )rT   r   r   r   r0  rg  s         r=   r   z_TopLevelFinder.__call__$  s,    !446 	*MD'NN4)	*r?   c                B    d}t         j                  |t        z          | S )Nz=Editable install will be performed using a meta path finder.
)r   r  r  r  s     r=   r   z_TopLevelFinder.__enter__(  s    N../r?   c                4    d}t        j                  d|       y )Nz

        Please be careful with folders in your working directory with the same
        name as your package as they may take precedence during imports.
        rN  )r   r9   rO  s        r=   r  z_TopLevelFinder.__exit__-  s     	5s;r?   N)rW   r   rj   ru   rA   r   )rA   z5tuple[str, str, dict[str, str], dict[str, list[str]]])rA   zIterator[tuple[str, bytes]]r   r  r!  )	rB   rC   rD   r  rb  rh  r   r   r  rH   r?   r=   r   r     sF    269*

<
< 
< 	
<
 

<r?   r   c                $   t        j                         5 }t        j                  |t        j                        }|j                  |        |j                          |j                  d       |j                         cddd       S # 1 sw Y   yxY w)a  
    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)rg  bufferwrappers      r=   r  r  :  se     
 ""6E4F4FGgA{{}  s   A'BBc                .   t        t        | j                                     5 }t        |d      t        |d      }}|j	                  dd       t        t        t        t              5  t        j                  ||       |j                         r'|j                  d      dk(  r	 d d d        d d d        yd d d        	 t        j                  ||       	 d d d        y	# 1 sw Y   *xY w# t        $ r}d}t        |      |d }~ww xY w# 1 sw Y   y xY w)
N)dirz	file1.txtz	file2.txtfile1rd  rm  TzFile system does not seem to support either symlinks or hard links. Strict editable installs require one of them to be supported.F)r   ru   r|   r   
write_textr   AttributeErrorNotImplementedErrorOSErrorrZ   symlink
is_symlink	read_textr5  ri   LinksNotSupported)base_dirr   path1path2rm   r  s         r=   rA  rA  O  s   	H$4$4$6 7	8 CC-tC/Eu73n&97C 	JJue$!eoowo&G7&R	 	
	1GGE5! ! 	 	  	1P  $C(b0	1 sN   AD)=C &D7D C,D C)	%D,	D5DDDDc           	     "   | D ci c]  }|t        |||       }}|st        |      i dhfv S t        j                  j	                  t        t        |j                                     t        fd|j                         D              S c c}w )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
    rM   c           	   3     K   | ]6  \  }}t        j                  t        g|j                  d        |       8 ywry   N)r   	same_pathr   split)r  keyvaluer   s      r=   r  z!_simple_layout.<locals>.<genexpr>  s:      C 	V5ciin5u=s   <?)	r   r   rZ   r]   
commonpathr   _parent_pathrB  all)r   r\   rR   r_  layoutr   s        @r=   r   r   c  s    > PXXc$S+{CCXFX;B:--WWflln EFF  ,,.  	 Ys   Bc                    |j                  |       r|dt        |         n|}|j                  dt        j                  z         S )a7  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'
    Nr+  )rv   lenrstriprZ   r/  )r_  pkg_pathr   s      r=   r  r    s<     '/&7&7&<XkS	"(F==rvv&&r?   c              #    K   t        | j                  xs g       E d {    | j                  xs g }|D cg c]	  }d|v s| }}| j                  r| j                   n<| j                  xs g }||D cg c]  }d|j
                  v s|j
                   c}z  }|D ]  }|j                  d      \  }}}|  y 7 c c}w c c}w w)Nry   )iterr   
py_modulesext_packageext_modulesrj   
rpartition)	rW   r  modnested_modulesr  xmodulepackage_s	            r=   r   r     s     DMM'R(((&BJ%/>c3#:c>N>&&,";Ha#-166HH  ))#.A ) ?
 Is8   CC C	CC2C8CC'C
Cc              #     K   | j                   xs g }d |D        E d {    | j                  s"| j                  xs g }d |D        E d {    y y 7 37 w)Nc              3  *   K   | ]  }d |vs|  ywr  rH   )r  r  s     r=   r  z*_find_top_level_modules.<locals>.<genexpr>  s     <S^<s   	c              3  R   K   | ]  }d |j                   vs|j                    ! ywr  )rj   )r  r  s     r=   r  z*_find_top_level_modules.<locals>.<genexpr>  s     Eq3aff3DAFFEs   '')r  r  r  )rW   r  r  s      r=   rV  rV    sZ     &BJ<z<<<&&,"EKEEE  = 	Fs!   AA,AAAAc                |    t        |       D ci c]  }|t        t        |||             }}t        |      S c c}w rO   )sorted_absolute_rootr   _remove_nested)r   r\   rY   r_  	pkg_rootss        r=   rW  rW    sL     (#! 	^-c;IJJ!I !
 )$$!s   9c                    t        |       }|j                  }|j                         rt        |j	                               S t        |j	                         |j
                  z        S )z(Works for packages and top-level modules)r   r   rw   ru   r|   rj   )r]   path_r   s      r=   r  r    sI    JE\\F||~5==?##6>>#ejj011r?   c           	   #    K   | D ]y  }d|vr|j                  d      }t        t        |      dz
  dd      D ]E  }dj                  |d|       }t	        t        || d            }|j                         r|| vsB| G { yw)a8  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.
    ry   r!   r   NrM   )r  ranger  r^   r   r   rw   )r  r_  partsipartial_namer]   s         r=   rZ  rZ    s       	#c>		#s5zA~q"- 	#A88E"1I.L),	2FGD;;=L	$A""	#		#s   A6B9	Bc              #     K   | D ]K  }t        ||d      }t        |      j                         s*t        |d      j                         rE||gf M y w)NrM   z__init__.py)r   r   rw   )r   r  r_  r]   s       r=   rY  rY    sS         i4:tD-'@'G'G'I- s   ,AA

Ac                    t        | j                               }t        t        | j	                                     D ]:  \  t        fd| j	                         D              s*|j                         < |S )Nc              3  N   K   | ]  \  }}|k7  xr t        ||        y wrO   )
_is_nested)r  other
other_pathr]   r_  s      r=   r  z!_remove_nested.<locals>.<genexpr>  s4      
!z 5LEZT5*EE
s   "%)rX  copyreversedr  rB  anypop)r  rH  r]   r_  s     @@r=   r  r    sh    ).."#Fd9??#456 	T 
%.__%6
 
 JJsO Mr?   c                    t        j                  |      }| j                  |dd      j                  d      j	                  d      }| j                  |      xr" |t        j                  t        |g|       k(  S )a  
    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
    rM   r!   ry   )r   normpathr.  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 ' r?   c                ^    t        j                  | d       t        j                  |        | S )zFCreate a directory ensured to be empty. Existing files may be removed.T)ignore_errors)r   rmtreerZ   makedirs)dir_s    r=   r   r     s!    NN4t,KKKr?   c                       e Zd ZddZd Zd Zy)r}   c                X    || _         || _        || _        || _        g | _        d| _        y )NF)rX   rY   r   editable_namerC  dry_run)rT   rX   r   r  rY   s        r=   r  z_NamespaceInstaller.__init__  s/    (  0*"$r?   c                    t         j                  j                  | j                  | j                  | j
                  z         S )zInstallation target.)rZ   r]   r^   r   r  	nspkg_extrS   s    r=   _get_nspkg_filez#_NamespaceInstaller._get_nspkg_file  s,    ww||D1143E3E3VWWr?   c                >    t        t        | j                              S )z1Where the modules/packages should be loaded from.)reprru   rY   rS   s    r=   	_get_rootz_NamespaceInstaller._get_root#  s    C&''r?   Nr   )rB   rC   rD   r  r  r  rH   r?   r=   r}   r}     s    X(r?   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                |    t        t        |j                         d             }t        j	                  | ||      S )z_Create a string containing the code for the``MetaPathFinder`` and
    ``PathEntryFinder``.
    c                    | d   S )Nr   rH   )r  s    r=   <lambda>z"_finder_template.<locals>.<lambda>  s
    1 r?   )r  rj   r   r   )rX  r  rB  _FINDER_TEMPLATEformatr  s      r=   rf  rf    s3     6'--/~>?G""g*"UUr?   c                      e Zd ZdZy)r  zCFile system does not seem to support either symlinks or hard links.N)rB   rC   rD   rE   rH   r?   r=   r  r    s    Mr?   r  )rg  ru   rA   re  )r  r   rA   bool)r   Iterable[str]r\   dict[str, str]rR   r   rA   r  )rW   r   rA   Iterator[str])r   r  r\   r  rY   r   rA   r  )r]   r   rA   ru   )r  r  rA   r  )r   r  r  r  rA   zIterator[tuple[str, list[str]]])r  r  rA   r  )
r_  ru   r  ru   r   ru   r  ru   rA   r  )r  r+   rA   r+   )rj   ru   r   r  r   zdict[str, list[str]]rA   ru   )arE   
__future__r   ro  loggingrZ   r   r   collections.abcr   r   r   
contextlibr   enumr   inspectr	   	itertoolsr
   r   pathlibr   tempfiler   typesr   typingr   r   r   r   rM   r   r   r   r   r   r   r   r1   r   r   	discoveryr   rW   r   warningsr   r    r"   r   r#   r   r$   rr   r%   r   r&   r   r'   r   typing_extensionsr(   _vendor.wheel.wheelfiler*   r+   	getLoggerrB   r   r.   rL  r  rJ   r   r   r   r   r  rA  r   r  r   rV  rW  r  rZ  rY  r  r  r   	Installerr}   r  rf  	FileErrorr  rH   r?   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r?   