
    ;ȋh                    .   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jC        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_d1ZNd`d5ZOdad<ZPd= ZQdbdAZRdbdBZSdcdEZTdddGZUdedIZVdfdLZWdgdMZXdhdRZYdidTZZ G dU dVe&j[                  Z\dWZ]djd\Z^ G d] d^e%j_                  Z`dS )ka  
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                  6    e Zd ZdZdZdZdZed
d            Zd	S )_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compatmode
str | Nonereturnc                    |st           j        S |                                }|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)clsr3   _modes      ^/var/www/pixelcanvas.ch/venv/lib/python3.11/site-packages/setuptools/command/editable_wheel.pyconvertz_EditableMode.convert@   s     	) ((

111$%Wt%W%W%WXXXH(-* ;     U##    N)r3   r4   r5   r/   )	__name__
__module____qualname____doc__STRICTr9   r7   classmethodrA    rB   r@   r/   r/   4   sM          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                      e Zd ZdZdZdddd eej        p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dS ).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 | _        d S N)dist_dirdist_info_dirproject_dirr3   selfs    r@   initialize_optionsz!editable_wheel.initialize_optionsu   s$    !			rB   r5   Nonec                    | j         }|j        pt          j        | _        |j        pi | _        t          | j        p$t          j        	                    | j        d                    | _        d S )Ndist)
distributionsrc_rootoscurdirrS   package_dirr   rQ   pathjoin)rU   rY   s     r@   finalize_optionszeditable_wheel.finalize_options{   sX     =5BI+1rT]Tbgll4;KV.T.TUUrB   c                   	 | j                             d           |                                  |                     d           |                     d          }|                    | j                   |                     |           d S # t          $ rD}| j	        j
        p| 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)rQ   mkdir_ensure_dist_inforeinitialize_commandget_finalized_commandwrite_wheelfilerR   _create_wheel_file	ExceptionrZ   nameget_namer   add_note)rU   rd   exprojects       r@   runzeditable_wheel.run   s    	M...""$$$ %%m44444]CCK''(:;;;##K00000 	 	 	',L0A0J0J0L0LGNfg f f f   	s   BB 
C?CCc                   | j         jt          t          |                     d                    }| j        |_        |                                 |                                 |j         | _         d S t          | j                   	                    d          sJ t          | j         d                                          sJ d S )Nr%   z
.dist-infoMETADATA)rR   r   dist_info_clsrg   rQ   
output_dirensure_finalizedrq   strendswithr   exists)rU   r%   s     r@   rf   z editable_wheel._ensure_dist_info   s    %]D,E,Ek,R,RSSI#'=I &&(((MMOOO!*!8Dt)**33LAAAAA*J77>>@@@@@@@rB   c                    | j         }|j        sd S t          | j        | j                            dd                                                    }t          ||||          }|                                 d S )NrN   .)	rZ   namespace_packagesr   rS   r^   getresolve_NamespaceInstallerinstall_namespaces)rU   installation_dir
pth_prefixrY   r[   	installers         r@   _install_namespacesz"editable_wheel._install_namespaces   sw     & 	F($*:*>*>r3*G*GHHPPRR'.>
HUU	$$&&&&&rB   r4   c                    | j         rt          | j                   j        nt                      }t          t          |                    d                    }t          |d           S )Nz
*.egg-info)rR   r   parentmaprw   globnext)rU   
parent_dir
candidatess      r@   _find_egg_info_dirz!editable_wheel._find_egg_info_dir   sT    8<8JVT$,--44PTPVPV
jool;;<<
J%%%rB   rl   rw   unpacked_wheelr   	build_libtmp_dirc                   | j         }t          |          }t          |          }t          t          || dd                    }t          t          || dd                    }t          t          || dd                    }	t          t          |                    dd                    }
t          |          |
_        d|
_        t          t          |                    dd                    }t          t          |                    d	d                    }|x|_
        x|_        |_        |x|_        x|_        |_        |	x|_        |_        ||_        ||_        |                    d
          }d|_        t          t,          |                    d                    }d|_        t          |          |_        t          t2          |                    d                    }d|_        |                                 |_        |                                  |                                 |                                 dS )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)rZ   rw   r   r   egg_info_clsrg   egg_baseignore_egg_info_in_manifest	build_clsinstall_clsbuild_platlibbuild_purelibr   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_moderv   )rU   rl   r   r   r   rY   wheelr   r   r   r&   r#   r'   r   r(   r$   s                   r@   _configure_buildzeditable_wheel._configure_build   s4     N##	NN	44??@@d>d>>>9EEFFd>d>>>9EEFF $33JSW3XX
 
  LL/3,t00T0RR
 
 229QU2VV
 
 GPOOe1EORWWW'"9G<O8??%"5")# ,,_==#+ !5!56G!H!H
 
 !%w<<d&:&::&F&FGG )-)@)@)B)B&!!!     """""rB   c                    | j         }|                    d          }|                                D ]F}|                    |          }t          |d          rd|_        /t          |d          rd|_        GdS )z8Set the ``editable_mode`` flag in the build sub-commandsr#   editable_modeTinplaceN)rZ   r   get_sub_commandshasattrr   r   )rU   rY   r#   cmd_namecmds        r@   r   z!editable_wheel._set_editable_mode   s     $$W--..00 	# 	#H&&x00CsO,, #$(!!i(( #"	# 	#rB    tuple[list[str], dict[str, str]]c                x   g }i }|                      d          }|                                D ]}|                      |          }t          |d          r)|                    |                                pg            t          |d          r)|                    |                                pi            ||fS )Nr#   get_outputsget_output_mapping)rh   r   r   extendr   updater   )rU   filesmappingr#   r   r   s         r@   _collect_build_outputsz%editable_wheel._collect_build_outputs   s    "$**733..00 	? 	?H,,X66CsM** 6S__..4"555s011 ?s5577=2>>>g~rB   	dist_namec                   |                      ||||           |                                  |                                 \  }}|                     d           |                     d           |                     d           ||fS )Nr   r   r   )r   _run_build_subcommandsr   _run_install)rU   r   r   r   r   r   r   s          r@   _run_build_commandsz"editable_wheel._run_build_commands  s     	iGLLL##%%%4466w)$$$)$$$&!!!g~rB   c                   |                      d          }|                                D ]^}|                      |          }|dk    r,t          |          t          ur|                     |           I|                     |           _dS )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)rh   r   typer   _safely_runrun_command)rU   r#   rl   r   s       r@   r   z%editable_wheel._run_build_subcommands  s     **733**,, 	' 	'D,,T22Cz!!d3ii|&C&C  &&&&  &&&&	' 	'rB   r   c                    	 |                      |          S # t          $ r4 t          j        ddt	          j                     d| d| d           Y d S 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   rk   r!   r=   	traceback
format_exc)rU   r   s     r@   r   zeditable_wheel._safely_run-  s    	##H--- 	 	 	(-B%''  9A	  .6       	s    :AAc           
        ddl m} |                     d          }|j        }d                    |                                          }d}| d| d| d}t          | j        |          }|                                r|	                                 t          |          }	t          d          }
t          d	          }|	5 }|
5 }|5 }t          |t          | j                  j                  }t          j        | j        |           |                     ||           |                     ||||          \  }}|                     |||          }|5   ||d
          5 } ||||           |                    |           d d d            n# 1 swxY w Y   d d d            n# 1 swxY w Y   d d d            n# 1 swxY w Y   d d d            n# 1 swxY w Y   d d d            n# 1 swxY w Y   |S )Nr   r*   r%   -z
0.editablez.whl)suffixz
.build-libz.build-tempw)wheel.wheelfiler+   rh   rl   r`   get_tagr   rQ   ry   unlinkr   rR   shutilcopytreer   r   _select_strategywrite_files)rU   rd   r+   r%   r   tag	build_tagarchive_name
wheel_pathr   r   	build_tmpunpackedlibtmpunpacked_dist_infor   r   strategy	wheel_objs                       r@   rj   z!editable_wheel._create_wheel_fileI  sH   ------..{;;	N	hh{**,,-- 	#;;i;;#;;;$-66
 	 +<@@@&l;;;	&m<<<	 	0x 	0c9 	0!%hT5G0H0H0M!N!NOD.0BCCC$$Xy999!55i3PSTTNE7,,YSAAH 0 099Z55 0E7333%%h///0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 s   G0	GBGF+	%#FF+	FF+	FF+	G+F//G2F/3G6GGG	G
GG0G	G0 G	!G00G47G4categoryc                    t          | j        d| d           }|rB |            r:t                              d| d           |                     d|            d S d S d S )Nhas_zInstalling z as non editableinstall_)getattrrZ   _loggerinfor   )rU   r   has_categorys      r@   r   zeditable_wheel._run_installe  s    t02C2C2CTJJ 	4LLNN 	4LLAxAAABBB22233333	4 	4 	4 	4rB   r   EditableStrategyc                \   d| d| }t          | j                  }t                              | j                  }|t          j        u r:t          t          | j        d|                    }t          | j        |||          S t          | j                  }t          || j        |          }	|t          j        u }
t          | j                  dhk    r|	s|
r@| j                            dd          }t          | j        |t          ||          g          S t!          | j        |          S )zDDecides which strategy to use to implement an editable installation.__editable__.r   r#   rN   r{   )r   rS   r/   rA   r3   rG   
_empty_dir	_LinkTreerZ   _find_packages_simple_layoutr^   r7   setr}   
_StaticPth_TopLevelFinder)rU   rl   r   r   
build_namerS   r3   auxiliary_dirpackageshas_simple_layoutis_compat_modesrc_dirs               r@   r   zeditable_wheel._select_strategyk  s#    2T11C11
4+,,$$TY//='''&tD,<gz'R'RSSMT.mYOOO!$"344*8T5E{SS!55t  RD((->(.(&**2s33Gd/['8R8R7STTT t0$777rB   r5   rW   )r5   r4   )rl   rw   r   r   r   r   r   r   )r5   r   )
r   rw   r   r   r   r   r   r   r5   r   )r   rw   )r   rw   )rl   rw   r   rw   r   r   r5   r   )rC   rD   rE   rF   descriptionr	   r/   user_optionsrV   ra   rq   rf   r   r   r   r   r   r   r   r   rj   r   r   rI   rB   r@   rK   rK   g   sm        
 WK 	LK	$!6!<"==>L  V V V V   *	A 	A 	A' ' '& & & &
=# =# =# =#~	# 	# 	#      ' ' ' ',   8  84 4 4 48 8 8 8 8 8rB   rK   c                  &    e Zd Zdd	ZddZddZdS )r   r   r+   r   	list[str]r   Mapping[str, str]r5   objectc                    d S rP   rI   )rU   r   r   r   s       r@   __call__zEditableStrategy.__call__  s    rB   r)   c                    d S rP   rI   rT   s    r@   	__enter__zEditableStrategy.__enter__  s      rB   	_exc_typetype[BaseException] | None
_exc_valueBaseException | None
_tracebackTracebackType | Nonec                    d S rP   rI   rU   r  r  r  s       r@   __exit__zEditableStrategy.__exit__  s	    
 rB   N)r   r+   r   r   r   r   r5   r   r5   r)   )r  r  r  r  r  r  r5   r   )rC   rD   rE   r   r  r  rI   rB   r@   r   r     sJ            %$$$     rB   r   c                  .    e Zd Zdd	ZddZddZddZdS )r   rY   r   rl   rw   path_entries
list[Path]r5   rW   c                0    || _         || _        || _        d S rP   )rY   rl   r  )rU   rY   rl   r  s       r@   __init__z_StaticPth.__init__  s    		(rB   r   r+   r   r   r   r   c                    d                     d | j        D                       }t          | d          }|                    d| j         d|           d S )N
c              3  X   K   | ]%}t          |                                          V  &d S rP   )rw   r~   ).0ps     r@   	<genexpr>z&_StaticPth.__call__.<locals>.<genexpr>  s2      HHC		,,HHHHHHrB   r   .pth)r`   r  _encode_pthwritestrrl   )rU   r   r   r   entriescontentss         r@   r   z_StaticPth.__call__  s`    ))HHd6GHHHHH'~~~..6ty666AAAAArB   r)   c                    dt          t          t          j        | j                            d}t
                              |t          z              | S )Nz_
        Editable install will be performed using .pth file to extend `sys.path` with:
        z	
        )listr   r\   fspathr  r   warning_LENIENT_WARNINGrU   msgs     r@   r  z_StaticPth.__enter__  sQ    	c")T.//	0	0   	..///rB   r  r   r  r  c                    d S rP   rI   r
  s       r@   r  z_StaticPth.__exit__  s	     	rB   N)rY   r   rl   rw   r  r  r5   rW   r   r+   r   r   r   r   r  r  r   r  r   r  r   r5   rW   )rC   rD   rE   r  r   r  r  rI   rB   r@   r   r     sh        ) ) ) )
B B B B
        rB   r   c                  Z     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.
    rY   r   rl   rw   r   r   r   r5   rW   c                   t          |          | _        t          |                                          | _        |                    d          j        | _        t                                          ||| j        g           d S )Nr$   )	r   r   r~   r   r   	copy_file_filesuperr  )rU   rY   rl   r   r   	__class__s        r@   r  z_LinkTree.__init__  sn     "-00i0022))*55?
td&8%9:::::rB   r   r+   r   r   r   r   c                z    |                      ||           t                                          |||           d S rP   )_create_linksr+  r   )rU   r   r   r   r,  s       r@   r   z_LinkTree.__call__  s;    5'***w/////rB   filer4   c                *   t          t                    5  t          |                                                              | j                  }t          |                              t          j	        d          cd d d            S # 1 swxY w Y   d S )N/)
r   
ValueErrorr   r~   relative_tor   rw   replacer\   sep)rU   r/  r_   s      r@   _normalize_outputz_LinkTree._normalize_output  s    j!! 	2 	2::%%''33DNCCDt99$$RVS11	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 ts   A&BBBNrelative_outputsrc_filec                    | j         |z  }|j                                        s|j                            d           |                     |||           d S )NT)parentslink)r   r   is_dirre   r*  )rU   r7  r8  r<  dests        r@   _create_filez_LinkTree._create_file  s\    !O3{!!## 	,Kd+++

8T
-----rB   output_mappingc                     j                             dd           t           j                   rdnd} fd|                                D             }d |D             }|D ]3}                     |          }|r||vr                     ||           4|                                D ]\  }}                     |||           d S )NT)r:  rc   symhardc              3  L   K   | ]\  }}                     |          |fV  d S rP   )r6  )r  kvrU   s      r@   r  z*_LinkTree._create_links.<locals>.<genexpr>  s:      XXAt--a00!4XXXXXXrB   c                    i | ]
\  }}|||S rP   rI   )r  rE  rF  s      r@   
<dictcomp>z+_LinkTree._create_links.<locals>.<dictcomp>  s    AAATQ1=Aq===rB   r;  )r   re   _can_symlink_filesitemsr6  r?  )	rU   outputsr@  	link_type
normalisedmappingsoutputrelativesrcs	   `        r@   r.  z_LinkTree._create_links  s       ===/0BCCOEE	XXXXAUAUAWAWXXX
AAZAAA 	4 	4F--f55H 4HH44!!(F333%^^-- 	= 	=MHch)<<<<	= 	=rB   r)   c                N    d}t                               |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-...rB   r  r   r  r  c                F    d| j          d}t          j        d|           d S )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=   rU   r  r  r  r#  s        r@   r  z_LinkTree.__exit__  s:       	5s;;;;;rB   )
rY   r   rl   rw   r   r   r   r   r5   rW   r%  )r/  rw   r5   r4   rP   )r7  rw   r8  rw   )r@  r   r  r&  )rC   rD   rE   rF   r  r   r6  r?  r.  r  r  __classcell__)r,  s   @r@   r   r     s         
; 
; 
; 
; 
; 
;0 0 0 0 0 0   . . . . .= = = =   
< < < < < < < <rB   r   c                  >    e Zd ZddZdd	ZddZddZddZd dZdS )!r   rY   r   rl   rw   r5   rW   c                "    || _         || _        d S rP   )rY   rl   )rU   rY   rl   s      r@   r  z_TopLevelFinder.__init__  s    				rB   5tuple[str, str, dict[str, str], dict[str, list[str]]]c           	        	  j         j        pt          j        }t	          t           j                   t           j                             } j         j        pi }t          |||          	t          t	          t           j         j        pg 	          d t          	          D                                 }	 fd j         j        pg D             }i 	|}d j         d}t          j        |          }||||fS )Nc              3     K   | ]}|g fV  	d S rP   rI   )r  nss     r@   r  z0_TopLevelFinder.template_vars.<locals>.<genexpr>	  s&      DDb"bDDDDDDrB   c                L    i | ] }|t          |j        j        pd           !S )rN   )r   rY   r[   )r  pkgrootsrU   s     r@   rH  z1_TopLevelFinder.template_vars.<locals>.<dictcomp>  sB     
 
 
 "3ty/A/GRHH
 
 
rB   r   z.finder)rY   r[   r\   r]   r
   r   _find_top_level_modulesr^   _find_package_rootsdict_find_namespacesr   _find_virtual_namespacesr|   rl   r   safe_identifier)
rU   r[   	top_levelr^   namespaces_legacy_namespacesr   rl   finderr`  s
   `        @r@   template_varsz_TopLevelFinder.template_vars   s#   9%2.335LTY5W5WXX	i+1r#I{HEE !3!9r5AADD$<U$C$CDDD 
 

 
 
 
 
y39r
 
 

 1U0/0
 2ty111/55tWk11rB   Iterator[tuple[str, bytes]]c              #     K   |                                  \  }}}}t          t          |||          d          }| d|fV  t          d| d| d          }d| j         d|fV  d S )Nutf-8z.pyzimport z; z
.install()r   r  )rk  bytes_finder_templater  rl   )rU   rj  rl   r   rh  contents         r@   get_implementationz"_TopLevelFinder.get_implementation  s      -1-?-?-A-A*g{(wDDgNN~~~w''''DDD&DDDEE.ty...888888rB   r   r+   r   r   r   r   c                f    |                                  D ]\  }}|                    ||           d S rP   )rr  r  )rU   r   r   r   r/  rq  s         r@   r   z_TopLevelFinder.__call__$  sB    !4466 	* 	*MD'NN4))))	* 	*rB   r)   c                N    d}t                               |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..///rB   r  r   r  r  c                4    d}t          j        d|           d S )Nz

        Please be careful with folders in your working directory with the same
        name as your package as they may take precedence during imports.
        rU  )r    r=   rV  s        r@   r  z_TopLevelFinder.__exit__-  s%     	5s;;;;;rB   N)rY   r   rl   rw   r5   rW   )r5   rZ  )r5   rl  r%  r  r&  )	rC   rD   rE   r  rk  rr  r   r  r  rI   rB   r@   r   r     s           2 2 2 269 9 9 9* * * *   

< 
< 
< 
< 
< 
<rB   r   rq  rw   r5   ro  c                @   t          j                    5 }t          j        |t          j                  }|                    |            |                                 |                    d           |                                cddd           S # 1 swxY w Y   dS )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)rq  bufferwrappers      r@   r  r  :  s     
 "6E4FGGGgA{{}}                 s   A2BBBbase_dirr   boolc                   t          t          |                                                     5 }t          |d          t          |d          }}|                    dd           t          t          t          t                    5  t          j
        ||           |                                r3|                    d          dk    r	 d d d            d d d            dS d d d            n# 1 swxY w Y   	 t          j        ||           n$# t          $ r}d}t          |          |d }~ww xY w	 d d d            d	S # 1 swxY w Y   d S )
N)dirz	file1.txtz	file2.txtfile1rn  rw  TzFile system does not seem to support either symlinks or hard links. Strict editable installs require one of them to be supported.F)r   rw   r~   r   
write_textr   AttributeErrorNotImplementedErrorOSErrorr\   symlink
is_symlink	read_textr<  rk   LinksNotSupported)r  r   path1path2ro   r#  s         r@   rI  rI  O  s   	H$4$4$6$6 7 7	8	8	8 CC--tC/E/Eu7333n&97CC 	 	Jue$$$!! eoowo&G&G7&R&R	 	 	 	 	 	       	 	 	 	 	 	 	 	 	 	 	 	 	 	 	
	1GE5!!!! 	1 	1 	1P  $C((b0	1 !                 sa   AEAC1E%E1C5	5E8C5	9E=DE
D4D//D44EE	E	r   Iterable[str]r^   dict[str, str]rS   r   c                4   fd| D             }|st                    i dhfv S t          j                            t	          t
          |                                                    t          fd|                                D                       S )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
    c                4    i | ]}|t          |          S rI   r   )r  r_  r^   rS   s     r@   rH  z"_simple_layout.<locals>.<dictcomp>  s(    XXXc$S+{CCXXXrB   rN   c           	   3     K   | ]:\  }}t          j        t          g|                    d           R  |          V  ;dS r{   N)r   	same_pathr   split)r  keyvaluer   s      r@   r  z!_simple_layout.<locals>.<genexpr>  sa        C 	V5ciinn555u==     rB   )r   r\   r_   
commonpathr   _parent_pathrJ  all)r   r^   rS   layoutr   s    `` @r@   r   r   c  s    > YXXXXxXXXF .;B:--Wfllnn E EFFF     ,,..     rB   c                    |                     |           r|dt          |                     n|}|                    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'
    Nr1  )rx   lenrstripr\   r5  )r_  pkg_pathr   s      r@   r  r    sJ     '/&7&7&<&<JXkS	k""(F==rv&&&rB   rY   r   Iterator[str]c              #    K   t          | j        pg           E d {V  | j        pg }d |D             }| j        r
| j        V  n| j        pg }|d |D             z  }|D ]}|                    d          \  }}}|V   d S )Nc                    g | ]}d |v |	S r{   rI   r  mods     r@   
<listcomp>z"_find_packages.<locals>.<listcomp>  s    >>>c3#::c:::rB   c                .    g | ]}d |j         v |j         S r  rl   r  xs     r@   r  z"_find_packages.<locals>.<listcomp>  s!    HHHa#--16---rB   r{   )iterr   
py_modulesext_packageext_modules
rpartition)rY   r  nested_modulesr  modulepackage_s          r@   r   r     s      DM'R(((((((((&BJ>>Z>>>N I&,"HH;HHHH   ))#..A rB   c              #     K   | j         pg }d |D             E d {V  | j        s| j        pg }d |D             E d {V  d S d S )Nc              3  "   K   | ]
}d |v|V  dS r  rI   r  s     r@   r  z*_find_top_level_modules.<locals>.<genexpr>  s&      <<S^^^^^^<<rB   c              3  6   K   | ]}d |j         v|j         V  dS r  r  r  s     r@   r  z*_find_top_level_modules.<locals>.<genexpr>  s0      EEq3af3D3DAF3D3D3D3DEErB   )r  r  r  )rY   r  r  s      r@   ra  ra    s      &BJ<<z<<<<<<<<<< F&,"EEKEEEEEEEEEEEEF FrB   r   r[   c                \    fdt          |           D             }t          |          S )Nc           
     N    i | ]!}|t          t          |                    "S rI   )_absolute_rootr   )r  r_  r^   r[   s     r@   rH  z'_find_package_roots.<locals>.<dictcomp>  s@     ! ! ! 	^-c;IIJJ! ! !rB   )sorted_remove_nested)r   r^   r[   	pkg_rootss    `` r@   rb  rb    sI    
! ! ! ! !(##! ! !I
 )$$$rB   r_   c                    t          |           }|j        }|                                r!t          |                                          S t          |                                |j        z            S )z(Works for packages and top-level modules)r   r   ry   rw   r~   rl   )r_   path_r   s      r@   r  r    sY    JJE\F||~~ 25==??###6>>##ej0111rB   r  c           	   #  >  K   | D ]}d|vr|                     d          }t          t          |          dz
  dd          D ]Y}d                    |d|                   }t	          t          || d                    }|                                r|| vr|V  ZdS )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.
    r{   r"   r   NrN   )r  ranger  r`   r   r   ry   )r  r_  partsipartial_namer_   s         r@   re  re    s        	# 	#c>>		#s5zzA~q"-- 	# 	#A88E"1"I..L),	2FFGGD;;== #L	$A$A""""	#		# 	#rB   r   Iterator[tuple[str, list[str]]]c              #     K   | D ]]}t          ||d          }t          |                                          r)t          |d                                          s||gfV  ^d S )NrN   z__init__.py)r   r   ry   )r   r  r_  r_   s       r@   rd  rd    s|            i44:: 	 tD-'@'@'G'G'I'I 	 -   rB   c                :   t          |                                           }t          t          |                                                     D ]H\  t          fd|                                 D                       r|                               I|S )Nc              3  N   K   | ]\  }}|k    ot          ||          V   d S rP   )
_is_nested)r  other
other_pathr_   r_  s      r@   r  z!_remove_nested.<locals>.<genexpr>  sR       
 
!z 5LEZT5*EE
 
 
 
 
 
rB   )rc  copyreversedr  rJ  anypop)r  rO  r_   r_  s     @@r@   r  r    s    )..""##Fd9??#4#45566  	T 
 
 
 
 
%.__%6%6
 
 
 
 
 	 JJsOOOMrB   r_  r  r   parent_pathc                   t          j        |          }|                     |dd                              d                              d          }|                     |          o"|t          j        t          |g|R            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
    rN   r"   r{   )r   normpathr4  stripr  
startswithr   )r_  r  r   r  norm_pkg_pathrests         r@   r  r    s     N8,,M;;vr1%%++C0066s;;D>>&!! mu~[ 4   8 8 ' rB   dir_c                Z    t          j        | d           t          j        |            | S )zFCreate a directory ensured to be empty. Existing files may be removed.T)ignore_errors)r   rmtreer\   makedirs)r  s    r@   r   r     s,    N4t,,,,KKrB   c                  "    e Zd ZddZd Zd ZdS )r   r5   rW   c                Z    || _         || _        || _        || _        g | _        d| _        d S )NF)rZ   r[   r   editable_namerK  dry_run)rU   rZ   r   r  r[   s        r@   r  z_NamespaceInstaller.__init__  s3    (  0*"$rB   c                f    t           j                            | j        | j        | j        z             S )zInstallation target.)r\   r_   r`   r   r  	nspkg_extrT   s    r@   _get_nspkg_filez#_NamespaceInstaller._get_nspkg_file  s%    w||D143E3VWWWrB   c                D    t          t          | j                            S )z1Where the modules/packages should be loaded from.)reprrw   r[   rT   s    r@   	_get_rootz_NamespaceInstaller._get_root#  s    C&&'''rB   Nr   )rC   rD   rE   r  r  r  rI   rB   r@   r   r     sI           X X 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
rl   r   r   dict[str, list[str]]c                    t          t          |                                d                     }t                              | ||          S )z_Create a string containing the code for the``MetaPathFinder`` and
    ``PathEntryFinder``.
    c                    | d         S )Nr   rI   )r  s    r@   <lambda>z"_finder_template.<locals>.<lambda>  s
    1 rB   )r  rl   r   r   )rc  r  rJ  _FINDER_TEMPLATEformatr  s      r@   rp  rp    sC     6'--//~~>>>??G""g*"UUUrB   c                      e Zd ZdZdS )r  zCFile system does not seem to support either symlinks or hard links.N)rC   rD   rE   rF   rI   rB   r@   r  r    s        MMMMrB   r  )rq  rw   r5   ro  )r  r   r5   r  )r   r  r^   r  rS   r   r5   r  )rY   r   r5   r  )r   r  r^   r   r[   r   r5   r  )r_   r   r5   rw   )r  r  r5   r  )r   r   r  r  r5   r  )r  r  r5   r  )
r_  rw   r  rw   r   rw   r  rw   r5   r  )r  r,   r5   r,   )rl   rw   r   r   r   r  r5   rw   )arF   
__future__r   ry  loggingr\   r   r   collections.abcr   r   r   
contextlibr   enumr   inspectr	   	itertoolsr
   r   pathlibr   tempfiler   typesr   typingr   r   r   r   rN   r   r   r   r   r   r   r   r2   r   r   	discoveryr   rY   r   warningsr    r!   r#   r   r$   r   r%   rt   r&   r   r'   r   r(   r   typing_extensionsr)   _vendor.wheel.wheelfiler+   r,   	getLoggerrC   r   r/   rS  r!  rK   r   r   r   r   r  rI  r   r  r   ra  rb  r  re  rd  r  r  r   	Installerr   r  rp  	FileErrorr  rI   rB   r@   <module>r     s  
 
 # " " " " " 				  				      7 7 7 7 7 7 7 7 7 7                   $ $ $ $ $ $ $ $       ' ' ' ' ' '       9 9 9 9 9 9 9 9 9 9 9 9 J J J J J J J J J J J J J J J J       ! ! ! ! ! ! ! ! ) ) ) ) ) )       D D D D D D D D % % % % % % . . . . . . 1 1 1 1 1 1 . . . . . . + + + + + + C C C C C C 4&&&&&&333333WT!!!
'
H
%
%&$ &$ &$ &$ &$D &$ &$ &$R \8 \8 \8 \8 \8W \8 \8 \8~
 
 
 
 
x 
 
 
       8I< I< I< I< I<
 I< I< I<X<< << << << << << << <<~   *   (& & & &R' ' '    F F F F
% 
% 
% 
%2 2 2 2# # # #0       
 
 
 
   ,   ( ( ( ( (*. ( ( ($V rV V V VN N N N N( N N N N NrB   