
    wg@                    `   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) ddl*m+Z+ ddl,m-Z- ddl.m/Z/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,      ZMdBd-ZNdCd.ZO	 	 	 	 	 	 	 	 dDd/ZPd0 ZQdEd1ZRdEd2ZS	 	 	 	 	 	 	 	 dFd3ZTdGd4ZUdHd5ZV	 	 	 	 	 	 dId6ZWdJd7ZXdKd8ZYdLd9ZZ G d: d;e&j                        Z\d<Z]	 	 	 	 	 	 	 	 dMd=Z^ G d> d?e%j                        Z` G d@ dAe1      Zay)Na  
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)py312)find_package_path)Distribution)InformationOnlySetuptoolsDeprecationWarningSetuptoolsWarning   )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.
                userguide/development_mode.html)see_docs)r.   LENIENTupper__members__r   OptionErrorr   emit)clsmode_modes      f/home/mcse/projects/flask/flask-venv/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__STRICTr6   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curdirrS   package_dirr   rQ   pathjoin)rU   rX   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        $ r^ t        j                          | j                  j                  xs | j                  j                         }t        j                  |        w xY w)NT)exist_okbdist_wheel)project)rQ   mkdir_ensure_dist_inforeinitialize_commandget_finalized_commandwrite_wheelfilerR   _create_wheel_file	Exception	traceback	print_excrY   nameget_name_DebuggingTipsr:   )rU   rc   rd   s      r>   runzeditable_wheel.run   s    	MM.""$ %%m444]CK''(:(:;##K0 	!'',,L0A0A0J0J0LG0		s   A:A= =A'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)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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 )NrN   .)	rY   namespace_packagesr   rS   r]   getresolve_NamespaceInstallerinstall_namespaces)rU   installation_dir
pth_prefixrX   rZ   	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)rR   r   parentmaprw   globnext)rU   
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|_        |_        ||_        ||_        t        t(        |j+                  d
            }d|_        t        |      |_        t        t0        |j+                  d            }d|_        | j5                         |_        | j9                          |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&   r'   r#   FN)rY   rw   r   r   egg_info_clsrg   egg_baseignore_egg_info_in_manifest	build_clsinstall_clsbuild_platlibbuild_purelib	build_libinstall_purelibinstall_platlibinstall_libr'   build_scriptsinstall_headersinstall_datainstall_scripts_clsget_command_objno_ep
build_tempbuild_py_clscompiler   existing_egg_info_dir_set_editable_moderv   )rU   rn   unpacked_wheelr   tmp_dirrX   wheelr   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)rY   r   get_sub_commandshasattrr   r   )rU   rX   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)rh   r   r   extendr   updater   )rU   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)rU   	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)rh   r   typer   _safely_runrun_command)rU   r"   rn   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 `ab  ` 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 behaviour will change in future versions.
                )r   rk   r   r:   rl   
format_exc)rU   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*   rh   rn   r_   get_tagr   rQ   ry   unlinkr   rR   shutilcopytreer   r   _select_strategywrite_files)rU   rc   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_file@  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_)getattrrY   _loggerinfor   )rU   categoryhas_categorys      r>   r   zeditable_wheel._run_install\  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"   rN   r{   )r   rS   r.   r?   r<   rG   
_empty_dir	_LinkTreerY   _find_packages_simple_layoutr]   r3   setr}   
_StaticPth_TopLevelFinder)rU   rn   r   r   
build_namerS   r<   auxiliary_dirpackageshas_simple_layoutis_compat_modesrc_dirs               r>   r   zeditable_wheel._select_strategyb  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@   rB   None)rB   rA   )rn   rw   r   r   r   r   r   r   )rB    tuple[list[str], dict[str, str]])
r   rw   r   r   r   r   r   r   rB   r   )r   rw   )r   rw   )rn   rw   r   rw   r   r   rB   EditableStrategy)rC   rD   rE   rF   descriptionr	   r.   user_optionsrV   r`   rq   rf   r   r   r   r   r   r   r   r   rj   r   r   rI   r@   r>   rK   rK   g   s    
 WK 	LK	$!6!6!<"=>LV"	A'&
8#8#)08#=D8#OV8#t	#   	
  
*',88488 8 	8
 
8r@   rK   c                  D    e Zd Z	 	 	 	 	 	 	 	 ddZddZ	 	 	 	 	 	 	 	 ddZy)r   c                     y rP   rI   )rU   r   r   r   s       r>   __call__zEditableStrategy.__call__~  s    r@   c                     y rP   rI   rT   s    r>   	__enter__zEditableStrategy.__enter__  s    r@   c                     y rP   rI   rU   	_exc_type
_exc_value
_tracebacks       r>   __exit__zEditableStrategy.__exit__  s    
 r@   N)r   r*   r   	list[str]r   Mapping[str, str]rB   objectrB   r(   )r   ztype[BaseException] | Noner  zBaseException | Noner  zTracebackType | NonerB   r  )rC   rD   rE   r   r   r  rI   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 rP   )rX   rn   path_entries)rU   rX   rn   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rP   )rw   r~   ).0ps     r>   	<genexpr>z&_StaticPth.__call__.<locals>.<genexpr>  s     HC		,Hs   #%r   .pth)r_   r
  _encode_pthwritestrrn   )rU   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   r[   fspathr
  r   warning_LENIENT_WARNINGrU   msgs     r>   r   z_StaticPth.__enter__  sH    		c"))T../	03 4	 	../r@   c                     y rP   rI   r   s       r>   r  z_StaticPth.__exit__  s     	r@   N)rX   r   rn   rw   r
  z
list[Path]rB   r   r   r*   r   r  r   r  r  r   r  r  r  r  r  rB   r   )rC   rD   rE   r  r   r   r  rI   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  )rU   rX   rn   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 rP   )_create_linksr%  r   )rU   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   rw   replacer[   sep)rU   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_dirre   r$  )rU   relative_outputsrc_filer4  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)r2  rb   symhardc              3  J   K   | ]  \  }}j                  |      |f  y wrP   )r0  )r  kvrU   s      r>   r  z*_LinkTree._create_links.<locals>.<genexpr>  s%     XAt--a0!4Xs    #r3  )r   re   _can_symlink_filesitemsr0  r9  )rU   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   r:   rU   r   r  r  r  s        r>   r  z_LinkTree.__exit__  s2      !	 	5s;r@   )
rX   r   rn   rw   r   r   r   r   rB   r   r  )r/  rw   rB   rA   rP   )r6  rw   r7  rw   )rC  r  r  r   )rC   rD   rE   rF   r  r   r0  r9  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 rP   )rX   rn   )rU   rX   rn   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rP   rI   )r  nss     r>   r  z0_TopLevelFinder.template_vars.<locals>.<genexpr>   s     Db"bDs   rN   r   z.finder)rX   rZ   r[   r\   r
   r   _find_top_level_modulesr]   _find_package_rootsdict_find_namespacesr   _find_virtual_namespacesr|   r   rn   r   safe_identifier)rU   rZ   	top_levelr]   rootsnamespaces_pkglegacy_namespacesr   rn   finders              r>   template_varsz_TopLevelFinder.template_vars  s+   99%%2.35LTYY5WX	ii++1r#I{HE,0 !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  )ra  bytes_finder_templater  rn   )rU   r`  rn   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 rP   )rg  r  )rU   r   r   r   r/  rf  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.
        rM  )r   r:   rN  s        r>   r  z_TopLevelFinder.__exit__$  s     	5s;r@   N)rX   r   rn   rw   rB   r   )rB   z5tuple[str, str, dict[str, str], dict[str, list[str]]])rB   zIterator[tuple[str, bytes]]r  r  r   )	rC   rD   rE   r  ra  rg  r   r   r  rI   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 behaviour 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)rf  bufferwrappers      r>   r  r  1  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file1rc  rl  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_textr4  rk   LinksNotSupported)base_dirr   path1path2exr  s         r>   r@  r@  F  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
    rN   c           	   3     K   | ]6  \  }}t        j                  t        g|j                  d        |       8 ywr{   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   r[   r^   
commonpathr   _parent_pathrA  all)r   r]   rS   r^  layoutr   s        @r>   r   r   Z  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*  )rx   lenrstripr[   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)Nr{   )iterr   
py_modulesext_packageext_modulesrn   
rpartition)	rX   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  rI   )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  )rn   )r  r  s     r>   r  z*_find_top_level_modules.<locals>.<genexpr>  s     Eq3aff3DAFFEs   '')r  r  r  )rX   r  r  s      r>   rU  rU    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 rP   )sorted_absolute_rootr   _remove_nested)r   r]   rZ   r^  	pkg_rootss        r>   rV  rV    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   ry   rw   r~   rn   )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.
    r{   r!   r   NrN   )r  ranger  r_   r   r   ry   )r  r^  partsipartial_namer^   s         r>   rY  rY    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)NrN   z__init__.py)r   r   ry   )r   r  r^  r^   s       r>   rX  rX    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rP   )
_is_nested)r  other
other_pathr^   r^  s      r>   r  z!_remove_nested.<locals>.<genexpr>  s4      
!z 5LEZT5*EE
s   "%)rW  copyreversedr  rA  anypop)r  rG  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
    rN   r!   r{   )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   rmtreer[   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)rY   rZ   r   editable_namerB  dry_run)rU   rY   r   r  rZ   s        r>   r  z_NamespaceInstaller.__init__  s/    (  0*"$r@   c                    t         j                  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,    ww||D1143E3E3VWWr@   c                >    t        t        | j                              S )z1Where the modules/packages should be loaded from.)reprrw   rZ   rT   s    r>   	_get_rootz_NamespaceInstaller._get_root  s    C&''r@   Nr   )rC   rD   rE   r  r  r  rI   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   rI   )r  s    r>   <lambda>z"_finder_template.<locals>.<lambda>~  s
    1 r@   )r  rn   r   r   )rW  r  rA  _FINDER_TEMPLATEformatr  s      r>   re  re  x  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)rC   rD   rE   rF   rI   r@   r>   r  r    s    Mr@   r  c                      e Zd ZdZdZdZy)rp   z!Problem in editable installation.a  
    An error happened while installing `{project}` in editable mode.

    The following steps are recommended to help debug this problem:

    - Try to install the project normally, without using the editable mode.
      Does the error still persist?
      (If it does, try fixing the problem before attempting the editable mode).
    - If you are using binary extensions, make sure you have all OS-level
      dependencies installed (e.g. compilers, toolchains, binary libraries, ...).
    - Try the latest version of setuptools (maybe the error was already fixed).
    - If you (or your project dependencies) are using any setuptools extension
      or customization, make sure they support the editable mode.

    After following the steps above, if the problem still persists and
    you think this is related to how setuptools handles editable installations,
    please submit a reproducible example
    (see https://stackoverflow.com/help/minimal-reproducible-example) to:

        https://github.com/pypa/setuptools/issues
    r4   N)rC   rD   rE   _SUMMARY_DETAILS	_SEE_DOCSrI   r@   r>   rp   rp     s    2HH* 2Ir@   rp   )rf  rw   rB   rd  )r  r   rB   bool)r   Iterable[str]r]   dict[str, str]rS   r   rB   r  )rX   r   rB   Iterator[str])r   r  r]   r  rZ   r   rB   r  )r^   r   rB   rw   )r  r  rB   r  )r   r  r  r  rB   zIterator[tuple[str, list[str]]])r  r  rB   r  )
r^  rw   r  rw   r   rw   r  rw   rB   r  )r  r+   rB   r+   )rn   rw   r   r  r   zdict[str, list[str]]rB   rw   )brF   
__future__r   rn  loggingr[   r   rl   collections.abcr   r   r   
contextlibr   enumr   inspectr	   	itertoolsr
   r   pathlibr   tempfiler   typesr   typingr   r   r   r   rN   r   r   r   r   r   r   r   r1   r   	discoveryr   rX   r   warningsr   r   r    r"   r   r#   r   r$   rt   r%   r   r&   r   r'   r   typing_extensionsr(   _vendor.wheel.wheelfiler*   r+   	getLoggerrC   r   r.   rK  r  rK   r   r   r   r   r  r@  r   r  r   rU  rV  r  rY  rX  r  r  r   	Installerr   r  re  	FileErrorr  rp   rI   r@   r>   <module>r     s  
 # 	  	   7 7    $  '  9 9 J J   )  W W % . 1 . + C&3T!
'

H
%&$D &$R S8W S8l
x 
 8I<
 I<X<< <<~*(&&*8&GN&	&R' F
%
%"
% 
% 	
%2#0  $2 $ 
,(*.. ($V rV
V)V7KVVN(( N2& 2r@   