
    dfy              
       2   d Z ddlZddl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	 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 dd	lmZmZmZmZmZmZmZmZmZmZ dd
lm Z m!Z!m"Z"m#Z# ddl$m%Z& ddl'm(Z( ddl)m*Z* erddl+m,Z, ejZ                  dk\  rddlm.Z. nerddl/m.Z. nddl0m1Z. ee2ef   Z3 ede3      Z4 ejj                  e6      Z7 G d de      Z8dZ9dZ: G d de       Z; G d de.      Z< G d d      Z= G d de=      Z> G d  d!      Z?d"ed#e@fd$ZAd%ee2   d&ee2e2f   d'ed#e@fd(ZBd) ZCd*e*d#ee2   fd+ZDd*e*d#ee2   fd,ZEd%ee2   d&ee2e2f   d-e3d#ee2e2f   fd.ZFd/e3d#e2fd0ZGd1ee2e2f   d#ee2   fd2ZHd%ee2   d1ee2e2f   d#eee2ee2   f      fd3ZId1ee2e2f   d#ee2e2f   fd4ZJd5e2d6e2d7e2d8e2d#e@f
d9ZKd:e3d#e2fd;ZLd<e4d#e4fd=ZMd>e2d#e2fd?ZN G d@ dAe#j                        ZPdBZQd>e2dCee2e2f   dDee2ee2   f   d#e2fdEZR G dF dGeS      ZT G dH dIe"j                        ZVy)Ja  
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``.
    N)suppress)Enum)cleandoc)chain)Path)TemporaryDirectory)
TYPE_CHECKINGDictIterableIteratorListMappingOptionalTupleTypeVarUnion)CommandSetuptoolsDeprecationWarningerrors
namespaces)build_py)find_package_path)Distribution	WheelFile)      )Protocol)ABC_P)boundc                   <    e Zd ZdZdZdZdZedee	   dd f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compatmodereturnc                     |st         j                  S |j                         }|t         j                  vrt	        j
                  d|d      |dk(  rd}t        j                  |t               t         |   S )NzInvalid editable mode: z. Try: 'strict'.COMPATax  
            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.

            For more information, please check:
            https://setuptools.pypa.io/en/latest/userguide/development_mode.html
            )	r#   LENIENTupper__members__r   OptionErrorwarningswarnr   )clsr'   _modemsgs       Z/home/api-vastappli/venv/lib/python3.12/site-packages/setuptools/command/editable_wheel.pyconvertz_EditableMode.convertG   sq     (((

111$$'>thFV%WXXHC MM#;<U##    N)__name__
__module____qualname____doc__STRICTr+   r*   classmethodr   strr5    r6   r4   r#   r#   ;   s<     FGF$8C= $_ $ $r6   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                   2   e Zd ZdZdZdddd eej                  xs d      fgZd Zd	 Z	d
 Z
d Zd Zdee   fdZdedededefdZd Zdeee   eeef   f   fdZdededededeee   eeef   f   f
dZd ZdefdZd ZdefdZdedededdfd Zy)!editable_wheelzkBuild 'editable' wheel for development.
    (This command is reserved for internal use of setuptools).
    z!create a 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    r4   initialize_optionsz!editable_wheel.initialize_optionsv   s     !	r6   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curdirrH   package_dirr   rF   pathjoin)rJ   rM   s     r4   finalize_optionszeditable_wheel.finalize_options|   s_      ==5BII++1rT]]Tbggll4;K;KV.TUr6   c                    	 | j                   j                  d       | j                          | j                  d       | j	                  d      }|j                  | j                         | j                  |       y # t        $ r:}t        j                          d}t        j                  t        |            |d }~ww xY w)NT)exist_okbdist_wheela  
            Support for editable installs via PEP 660 was recently introduced
            in `setuptools`. If you are seeing this error, please report to:

            https://github.com/pypa/setuptools/issues

            Meanwhile you can try the legacy behavior by setting an
            environment variable and trying to install again:

            SETUPTOOLS_ENABLE_FEATURES="legacy-editable"
            )rF   mkdir_ensure_dist_inforeinitialize_commandget_finalized_commandwrite_wheelfilerG   _create_wheel_file	Exception	traceback	print_excr   InternalErrorr   )rJ   rX   exr3   s       r4   runzeditable_wheel.run   s    	>MM.""$ %%m444]CK''(:(:;##K0 	>!
C &&x}52=	>s   A:A= =	C 5B;;C c                 \   | j                   T| j                  d      }| j                  |_        |j	                          |j                          |j                   | _         y t        | j                         j                  d      sJ t        | j                   d      j                         sJ y )N	dist_infoz
.dist-infoMETADATA)
rG   r[   rF   
output_dirensure_finalizedrd   r=   endswithr   exists)rJ   rf   s     r4   rZ   z editable_wheel._ensure_dist_info   s    %11+>I#'==I &&(MMO!*!8!8Dt))*33LAA**J7>>@@@r6   c                     | j                   }|j                  sy t        | j                  | j                  j                  dd            j                         }t        ||||      }|j                          y )NrC   .)	rN   namespace_packagesr   rH   rR   getresolve_NamespaceInstallerinstall_namespaces)rJ   installation_dir
pth_prefixrM   rO   	installers         r4   _install_namespacesz"editable_wheel._install_namespaces   sd      &&(($*:*:*>*>r3*GHPPR'.>
HU	$$&r6   r(   c                     | j                   rt        | j                         j                  n	t               }t        t        |j                  d            }t        |d       S )Nz
*.egg-info)rG   r   parentmapr=   globnext)rJ   
parent_dir
candidatess      r4   _find_egg_info_dirz!editable_wheel._find_egg_info_dir   sH    8<8J8JT$,,-44PTPV
jool;<
J%%r6   nameunpacked_wheel	build_libtmp_dirc                    | j                   }t        |      }t        |      }t        t        || dd            }t        t        || dd            }t        t        || dd            }	|j                  dd      }
t        |      |
_        d|
_        |j                  dd      }|j                  d	d      }|x|_        x|_        |_        |x|_	        x|_
        |_        |	x|_        |_        ||_        ||_        |j!                  d
      }d|_        t        |      |_        |j!                  d      }d|_        | j)                         |_        | j-                          |j/                          |j/                          y)a  Configure commands to behave in the following ways:

        - Build commands can write to ``build_lib`` if they really want to...
          (but this folder is expected to be ignored and modules are expected to live
          in the project directory...)
        - Binary extensions should be built in-place (editable_mode = True)
        - Data/header/script files are not part of the "editable" specification
          so they are written directly to the unpacked_wheel directory.
        z.datadataheadersscriptsegg_infoT)reinit_subcommandsbuildinstallinstall_scriptsr   FN)rN   r=   r   r[   egg_baseignore_egg_info_in_manifestbuild_platlibbuild_purelibr   install_purelibinstall_platlibinstall_libr   build_scriptsinstall_headersinstall_dataget_command_objno_ep
build_tempcompiler~   existing_egg_info_dir_set_editable_moderi   )rJ   r   r   r   r   rM   wheelr   r   r   r   r   r   r   r   s                  r4   _configure_buildzeditable_wheel._configure_build   s      N#	N	44&?@d>dV5>9EFd>dV5>9EF ,,ZD,QL/3,))'d)K++I$+OFOOOe1EORWWW'"9G<O8??%"5")#../@A $w<''
3 )-)@)@)B&!   "r6   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)rN   r   get_sub_commandshasattrr   r   )rJ   rM   r   cmd_namecmds        r4   r   z!editable_wheel._set_editable_mode   sh      $$W-..0 	#H&&x0CsO,$(!i("	#r6   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)r\   r   r   extendr   updater   )rJ   filesmappingr   r   r   s         r4   _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~r6   	dist_namec                     | j                  ||||       | j                          | j                         \  }}| j                  d       | j                  d       | j                  d       ||fS )Nr   r   r   )r   _run_build_subcommandsr   _run_install)rJ   r   r   r   r   r   r   s          r4   _run_build_commandsz"editable_wheel._run_build_commands  sj     	iGL##%446w)$)$&!g~r6   c                     | j                  d      }|j                         D ]M  }| j                  |      }|dk(  r$t        |      t        k7  r| j	                  |       =| j                  |       O 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)r\   r   typebuild_py_cls_safely_runrun_command)rJ   r   r   r   s       r4   r   z%editable_wheel._run_build_subcommands  sk     33G<**, 	'D,,T2Cz!d3i<&?  &  &	'r6   r   c                     	 | j                  |      S # t        $ r< t        j                          d| d| d}t	        j
                  |t        d       Y y w xY w)Nz

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

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

            For the time being `setuptools` will silence this error and ignore
            the faulty command, but this behaviour will change in future versions.

               )
stacklevel)r   r_   r`   
format_excr/   r0   r   )rJ   r   r3   s      r4   r   zeditable_wheel._safely_run"  sn    	K##H-- 	K ++-. /44<: >
 'Z (C MM#;J	Ks    A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                  ||||      \  }}| 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   rf   -z
0.editablez.whl)suffixz
.build-libz.build-tempw)wheel.wheelfiler   r\   r   rT   get_tagr   rF   rk   unlinkr   rG   shutilcopytreerv   r   _select_strategywrite_files)rJ   rX   r   rf   r   tag	build_tagarchive_name
wheel_pathr   r   	build_tmpunpackedlibtmpunpacked_dist_infor   r   strategy	wheel_objs                       r4   r^   z!editable_wheel._create_wheel_file6  s   -..{;	NN	hh{**,- 	#Ai[#d;$--6
+<@&l;	&m<	 	0x 	0c9 	0!%hT5G5G0H0M0M!NOOD..0BC$$Xy~~>!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   ,G/F82BF,
F 	F*F 	2F,:F8GFF 	 F)%F,,F51F88G	=GGcategoryc                     t        | j                  d| d       }|r6 |       r.t        j                  d| d       | j	                  d|        y y y )Nhas_zInstalling z as non editableinstall_)getattrrN   _loggerinfor   )rJ   r   has_categorys      r4   r   zeditable_wheel._run_installR  sV    t00D
2CTJLNLL;xj0@ABxz23 +<r6   r   EditableStrategyc                 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   rC   rm   )r   rH   r#   r5   r'   r;   
_empty_dir	_LinkTreerN   _find_packages_simple_layoutrR   r*   setro   
_StaticPth_TopLevelFinder)rJ   r   r   r   
build_namerH   r'   auxiliary_dirpackageshas_simple_layoutis_compat_modesrc_dirs               r4   r   zeditable_wheel._select_strategyX  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7r6   )r7   r8   r9   r:   descriptionr   r#   user_optionsrK   rU   rd   rZ   rv   r   r=   r~   _Pathr   r   r   r   r
   r   r   r   r   r^   r   r   r>   r6   r4   r@   r@   i   sB    6K 	LK	$!6!6!<"=>LV>4	A'&HSM &
0#0#).0#;@0#KP0#d	#d3ic3h.G(H 		.3	@E	PU		tCy$sCx.(	)	',KC K(84S 488 8 	8
 
8r6   r@   c                   <    e Zd Zdddee   deeef   fdZd Zd Zy)	r   r   r   r   r   c                      y rE   r>   )rJ   r   r   r   s       r4   __call__zEditableStrategy.__call__t      r6   c                      y rE   r>   rI   s    r4   	__enter__zEditableStrategy.__enter__w  r   r6   c                      y rE   r>   rJ   	_exc_type
_exc_value
_tracebacks       r4   __exit__zEditableStrategy.__exit__z  r   r6   N)	r7   r8   r9   r   r=   r
   r   r   r   r>   r6   r4   r   r   s  s3    k $s) d3PS8n r6   r   c                   V    e Zd Zdededee   fdZdddee   deeef   fd	Z	d
 Z
d Zy)r   rM   r   path_entriesc                 .    || _         || _        || _        y rE   )rM   r   r   )rJ   rM   r   r   s       r4   __init__z_StaticPth.__init__  s    		(r6   r   r   r   r   c                     dj                  d | j                  D              }t        | dd      }|j                  d| j                   d|       y )N
c              3   N   K   | ]  }t        |j                                 y wrE   )r=   rp   ).0ps     r4   	<genexpr>z&_StaticPth.__call__.<locals>.<genexpr>  s     I!S-Is   #%utf-8r   .pth)rT   r   byteswritestrr   )rJ   r   r   r   entriescontentss         r4   r   z_StaticPth.__call__  sI    ))It7H7HIJG9B1tyyk6Ar6   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	
        )listry   rP   fspathr   r   warning_LENIENT_WARNINGrJ   r3   s     r4   r   z_StaticPth.__enter__  sH    		c"))T../	03 4	 	../r6   c                      y rE   r>   r   s       r4   r   z_StaticPth.__exit__  r   r6   N)r7   r8   r9   r   r=   r   r   r   r
   r   r   r   r>   r6   r4   r   r   ~  sU    )\ ) )DJ )
Bk B$s) Bd3PS8n B
r6   r   c                        e Zd ZdZdedededef fdZddd	ee   d
e	eef   f fdZ
dedee   fdZddedefdZd Zd Z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.
    rM   r   r   r   c                     t        |      | _        t        |      j                         | _        |j	                  d      j
                  | _        t        | !  ||| j                  g       y )Nr   )	r   r   rp   r   r   	copy_file_filesuperr   )rJ   rM   r   r   r   	__class__s        r4   r   z_LinkTree.__init__  sX     "-0i002))*5??
td&8&8%9:r6   r   r   r   r   c                 L    | j                  ||       t        | 	  |||       y rE   )_create_linksr  r   )rJ   r   r   r   r  s       r4   r   z_LinkTree.__call__  s$    5'*w/r6   filer(   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   rp   relative_tor   r=   replacerP   sep)rJ   r  rS   s      r4   _normalize_outputz_LinkTree._normalize_output  s]    j! 	2:%%'33DNNCDt9$$RVVS1	2 	2 	2 s   AA55A>relative_outputsrc_filec                     | j                   |z  }|j                  j                         s|j                  j                  d       | j	                  |||       y )NT)parentslink)r   rx   is_dirrY   r  )rJ   r  r   r$  dests        r4   _create_filez_LinkTree._create_file  sI    !!O3{{!!#KKd+

8T
-r6   c                    | j                   j                  dd       t        | j                         rdnd}|j                         D ci c]  \  }}| j	                  |      | }}}|j                  d d        |D ]-  }| j	                  |      }|s||vs| j                  ||       / |j                         D ]  \  }}	| j                  ||	|        y c c}}w )NT)r"  rW   symhardr#  )r   rY   _can_symlink_filesitemsr  popr'  )
rJ   outputsoutput_mapping	link_typekvmappingsoutputrelativesrcs
             r4   r  z_LinkTree._create_links  s       =/0B0BCE	 ',,.
1 ""1%q(
 
 	T4  	4F--f5HHH4!!(F3	4
 &^^- 	=MHch)<	=
s   
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     r4   r   z_LinkTree.__enter__  s    No-.r6   c                 X    d| j                    d}t        j                  |t               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.
        )r   r/   r0   InformationOnlyrJ   r   r   r   r3   s        r4   r   z_LinkTree.__exit__  s/      !	 	c?+r6   rE   )r7   r8   r9   r:   r   r=   r   r   r   r
   r   r   r  r'  r  r   r   __classcell__)r  s   @r4   r   r     s    	; 	;	; 	; 		;0k 0$s) 0d3PS8n 0c hsm .C .3 .="
,r6   r   c                   L    e Zd ZdedefdZdddee   deeef   fdZd	 Z	d
 Z
y)r   rM   r   c                      || _         || _        y rE   )rM   r   )rJ   rM   r   s      r4   r   z_TopLevelFinder.__init__  s    		r6   r   r   r   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                    }d| j                   d}	t        |	      }
t        t!        |	||      d      }|j#                  |
 d|       t        d|
 d|
 dd      }|j#                  d| j                   d	|       y )
Nc              3   $   K   | ]  }|g f 
 y wrE   r>   )r   nss     r4   r  z+_TopLevelFinder.__call__.<locals>.<genexpr>  s     @"b"X@s   r   z.finderr  z.pyzimport z; z
.install()r  )rM   rO   rP   rQ   r   r   _find_top_level_modulesrR   _find_package_rootsdict_find_namespacesr   _find_virtual_namespacesr   _make_identifierr  _finder_templater  )rJ   r   r   r   rO   	top_levelrR   rootsnamespaces_r   findercontents               r4   r   z_TopLevelFinder.__call__  s   99%%2.35LTYY5WX	ii++1r#I{HE,0TYY//52u=@ 8 ?@2
 -
 tyyk1!$'(ukBGL&~w/'&F8:>Htyyk6@r6   c                 B    d}t         j                  |t        z          | S )Nz=Editable install will be performed using a meta path finder.
)r   r  r  r  s     r4   r   z_TopLevelFinder.__enter__  s    N../r6   c                 <    d}t        j                  |t               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.
        )r/   r0   r:  r;  s        r4   r   z_TopLevelFinder.__exit__  s     	c?+r6   N)r7   r8   r9   r   r=   r   r   r
   r   r   r   r>   r6   r4   r   r     sJ    \  Ak A$s) Ad3PS8n A&
,r6   r   base_dirr(   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file1r  )encodingTzFile system does not seem to support either symlinks or hard links. Strict editable installs require one of them to be supported.F)r   r=   rp   r   
write_textr   AttributeErrorNotImplementedErrorOSErrorrP   symlink
is_symlink	read_textr$  r_   LinksNotSupported)rP  r   path1path2rc   r3   s         r4   r+  r+    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r   rR   rH   c           
      L   | D ci c]  }|t        |||       }}|st        |      i dhfv S t        j                  j	                  |j                         D cg c]  \  }}t        ||       c}}      t        fd|j                         D              S c c}w 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
    rC   c           	   3      K   | ]7  \  }}t        t        g|j                  d              t        |      k(   9 ywrm   N)_normalize_pathr   split)r   keyvaluerx   s      r4   r  z!_simple_layout.<locals>.<genexpr>;  s>      C 	V5ciin56/%:PPs   =A )r   r   rP   rS   
commonpathr,  _parent_pathall)r   rR   rH   pkglayoutr1  r2  rx   s          @r4   r   r     s    B  	sK==F  ;B:--WW O1a!3 OPF  ,,.   !Ps   B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  )rj   lenrstriprP   r  )ri  pkg_pathrx   s      r4   rg  rg  A  s<     &.%6%6s%;XjCy!F==rvv&&r6   rM   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)Nrm   )iterr   
py_modulesext_packageext_modulesr   
rpartition)	rM   rq  modnested_modulesrs  xmodulepackage_s	            r4   r   r   O  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ra  r>   )r   ru  s     r4   r  z*_find_top_level_modules.<locals>.<genexpr>a  s     <S^<s   	c              3   R   K   | ]  }d |j                   vs|j                    ! ywra  )r   )r   rw  s     r4   r  z*_find_top_level_modules.<locals>.<genexpr>e  s     Eq3aff3DAFFEs   '')rq  rr  rs  )rM   rq  rs  s      r4   rB  rB  _  sZ     &BJ<z<<<&&,"EKEEE  = 	Fs!   AA,AAAArO   c                 |    t        |       D ci c]  }|t        t        |||             }}t        |      S c c}w rE   )sorted_absolute_rootr   _remove_nested)r   rR   rO   ri  	pkg_rootss        r4   rC  rC  h  sL     (#! 	^-c;IJJ!I !
 )$$!s   9rS   c                     t        |       }|j                  }|j                         rt        |j	                               S t        |j	                         |j
                  z        S )z(Works for packages and top-level modules)r   rx   rk   r=   rp   r   )rS   path_rx   s      r4   r  r  u  sI    JE\\F||~5==?##6>>#ejj011r6   r  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.
    rm      r   NrC   )rc  rangerl  rT   r   r   rk   )r  ri  partsipartial_namerS   s         r4   rF  rF    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)NrC   z__init__.py)r   r   rk   )r   r  ri  rS   s       r4   rE  rE    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rE   )
_is_nested)r   other
other_pathrS   ri  s      r4   r  z!_remove_nested.<locals>.<genexpr>  s4      
!z 5LEZT5*EE
s   "%)rD  copyreversedr	  r,  anyr-  )r  r4  rS   ri  s     @@r4   r  r    sh    ).."#Fd9??#456 	T 
%.__%6
 
 JJsO Mr6   ri  rn  rx   parent_pathc                     t        |      }| j                  |dd      j                  d      j                  d      }| j	                  |      xr |t        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
    rC   r  rm   )rb  r  striprc  
startswithr   )ri  rn  rx   r  norm_pkg_pathrests         r4   r  r    sd     $H-M;;vr1%++C066s;Dv 	G_T+-E-EFFr6   filenamec                    t         j                  dk(  rt        j                  j	                  |       n| }t        j                  j                  t        j                  j                  t        j                  j                  |                  S )z1Normalize a file/dir name for comparison purposescygwin)sysplatformrP   rS   abspathnormcaserealpathnormpath)r  r  s     r4   rb  rb    sV     ),(@277??8$hD77BGG,,RWW-=-=d-CDEEr6   dir_c                 ^    t        j                  | d       t        j                  |        | S )zFCreate a directory ensured to be empty. Existing files may be removed.T)ignore_errors)r   rmtreerP   makedirs)r  s    r4   r   r     s!    
MM$d+KKKr6   r   c                 X    t        j                  dd|       }|j                         sJ |S )zMake a string safe to be used as Python identifier.
    >>> _make_identifier("12abc")
    '_12abc'
    >>> _make_identifier("__editable__.myns.pkg-78.9.3_local")
    '__editable___myns_pkg_78_9_3_local'
    z
\W|^(?=\d)rz  )resubisidentifier)r   safes     r4   rG  rG    s*     66-d+DKr6   c                       e Zd Zd Zd Zd Zy)rq   c                 X    || _         || _        || _        || _        g | _        d| _        y )NF)rN   rO   rs   editable_namer.  dry_run)rJ   rN   rs   r  rO   s        r4   r   z_NamespaceInstaller.__init__  s/    (  0*r6   c                 j    t         j                  j                  | j                  | j                        S )zInstallation target.)rP   rS   rT   rs   r  rI   s    r4   _get_targetz_NamespaceInstaller._get_target  s#    ww||D1143E3EFFr6   c                 >    t        t        | j                              S )z1Where the modules/packages should be loaded from.)reprr=   rO   rI   s    r4   	_get_rootz_NamespaceInstaller._get_root  s    C&''r6   N)r7   r8   r9   r   r  r  r>   r6   r4   rq   rq     s    G(r6   rq   a<	  import sys
from importlib.machinery import ModuleSpec
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 = {mapping!r}
NAMESPACES = {namespaces!r}
PATH_PLACEHOLDER = {name!r} + ".__path_hook__"


class _EditableFinder:  # MetaPathFinder
    @classmethod
    def find_spec(cls, fullname, path=None, target=None):
        for pkg, pkg_path in reversed(list(MAPPING.items())):
            if fullname == pkg or fullname.startswith(f"{{pkg}}."):
                rest = fullname.replace(pkg, "", 1).strip(".").split(".")
                return cls._find_spec(fullname, Path(pkg_path, *rest))

        return None

    @classmethod
    def _find_spec(cls, fullname, candidate_path):
        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)


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

    @classmethod
    def _paths(cls, fullname):
        # Ensure __path__ is not empty for the spec to be considered a namespace.
        return NAMESPACES[fullname] or MAPPING.get(fullname) or [PATH_PLACEHOLDER]

    @classmethod
    def find_spec(cls, fullname, target=None):
        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):
        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
r   r   c                 |    t        t        |j                         d             }t        j	                  | ||      S )z_Create a string containing the code for the``MetaPathFinder`` and
    ``PathEntryFinder``.
    c                     | d   S )Nr   r>   )r   s    r4   <lambda>z"_finder_template.<locals>.<lambda>?  s
    1 r6   )rd  r   r   r   )rD  r  r,  _FINDER_TEMPLATEformatr  s      r4   rH  rH  9  s3     6'--/~>?G""g*"UUr6   c                       e Zd ZdZy)r:  zCurrently there is no clear way of displaying messages to the users
    that use the setuptools backend directly via ``pip``.
    The only thing that might work is a warning, although it is not the
    most appropriate tool for the job...
    Nr7   r8   r9   r:   r>   r6   r4   r:  r:  C  s    r6   r:  c                       e Zd ZdZy)r\  zCFile system does not seem to support either symlinks or hard links.Nr  r>   r6   r4   r\  r\  K  s    Mr6   r\  )Wr:   loggingrP   r  r   r  r`   r/   
contextlibr   enumr   inspectr   	itertoolsr   pathlibr   tempfiler   typingr	   r
   r   r   r   r   r   r   r   r   
setuptoolsr   r   r   r   setuptools.command.build_pyr   r   setuptools.discoveryr   setuptools.distr   r   r   version_infor   typing_extensionsabcr   r=   r   r    	getLoggerr7   r   r#   r8  r  r@   r   r   r   r   boolr+  r   rg  r   rB  rC  r  rF  rE  r  r  rb  r   rG  	Installerrq   r  rH  UserWarningr:  	FileErrorr\  r>   r6   r4   <module>r     s$  
  	 	  
        '   Q P @ 2 ()v*#c4iT
'

H
%!$D !$H G8W G8Tx  .D,
 D,N", ",J $ ()sm)*.sCx.)GK)	)X' (3-  F, F8C= F
%sm
%c"
% 
% 
#s(^	
%2 23 2#S#X #8C= #0 3i $(cN eCcN#$ 
d38n 
c3h 
C 3  # $ .Fe F FR B 	3 	3 	(*.. ($E PV
VS)V7;CcN7KVVk N(( Nr6   