
    Ixhy              
          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j-        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j5        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#jO                  ZPdBZQd>e2dCee2e2f         dDee2ee2         f         d#e2fdEZR G dF dGeS          ZT G dH dIe"jU                  ZVdS )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                   J    e Zd ZdZdZdZdZedee	         dd f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returnc                     |st           j        S |                                }|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       T/var/www/html/what/lib/python3.11/site-packages/setuptools/command/editable_wheel.pyconvertz_EditableMode.convertG   s}     	) ((

111$%Wt%W%W%WXXXHC M#;<<<U##    N)__name__
__module____qualname____doc__STRICTr,   r+   classmethodr   strr6    r7   r5   r$   r$   ;   s_          FGF$8C= $_ $ $ $ [$ $ $r7   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                   V   e Zd ZdZdZdddd eej        p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dS )!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 | _        d S N)dist_dirdist_info_dirproject_dirr(   selfs    r5   initialize_optionsz!editable_wheel.initialize_optionsv   s$    !			r7   c                     | j         }|j        pt          j        | _        |j        pi | _        t          | j        p$t          j        	                    | j        d                    | _        d S )Ndist)
distributionsrc_rootoscurdirrI   package_dirr   rG   pathjoin)rK   rN   s     r5   finalize_optionszeditable_wheel.finalize_options|   sX     =5BI+1rT]Tbgll4;KV.T.TUUr7   c                    	 | j                             d           |                                  |                     d           |                     d          }|                    | j                   |                     |           d S # 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"
            )rG   mkdir_ensure_dist_inforeinitialize_commandget_finalized_commandwrite_wheelfilerH   _create_wheel_file	Exception	traceback	print_excr   InternalErrorr   )rK   rY   exr4   s       r5   runzeditable_wheel.run   s    	>M...""$$$ %%m44444]CCK''(:;;;##K00000 	> 	> 	>!!!
C &x}}552=	>s   BB 
C7CCc                 f   | j         W|                     d          }| j        |_        |                                 |                                 |j         | _         d S t          | j                                       d          sJ t          | j         d          	                                sJ d S )N	dist_infoz
.dist-infoMETADATA)
rH   r\   rG   
output_dirensure_finalizedre   r>   endswithr   exists)rK   rg   s     r5   r[   z editable_wheel._ensure_dist_info   s    %11+>>I#'=I &&(((MMOOO!*!8Dt)**33LAAAAA*J77>>@@@@@@@r7   c                     | j         }|j        sd S t          | j        | j                            dd                                                    }t          ||||          }|                                 d S )NrD   .)	rO   namespace_packagesr   rI   rS   getresolve_NamespaceInstallerinstall_namespaces)rK   installation_dir
pth_prefixrN   rP   	installers         r5   _install_namespacesz"editable_wheel._install_namespaces   sw     & 	F($*:*>*>r3*G*GHHPPRR'.>
HUU	$$&&&&&r7   r)   c                     | j         rt          | j                   j        nt                      }t          t          |                    d                    }t          |d           S )Nz
*.egg-info)rH   r   parentmapr>   globnext)rK   
parent_dir
candidatess      r5   _find_egg_info_dirz!editable_wheel._find_egg_info_dir   sT    8<8JVT$,--44PTPVPV
jool;;<<
J%%%r7   nameunpacked_wheel	build_libtmp_dirc                    | j         }t          |          }t          |          }t          t          || dd                    }t          t          || dd                    }t          t          || dd                    }	|                    dd          }
t          |          |
_        d|
_        |                    dd          }|                    d	d          }|x|_        x|_        |_        |x|_	        x|_
        |_        |	x|_        |_        ||_        ||_        |                    d
          }d|_        t          |          |_        |                    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scriptsegg_infoT)reinit_subcommandsbuildinstallinstall_scriptsr   FN)rO   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_moderj   )rK   r   r   r   r   rN   wheelr   r   r   r   r   r   r   r   s                  r5   _configure_buildzeditable_wheel._configure_build   s     N##	NN	44??@@d>d>>>9EEFFd>d>>>9EEFF ,,ZD,QQLL/3,))'d)KK++I$+OOFOOOe1EORWWW'"9G<O8??%"5")#../@AA $w<<''
33 )-)@)@)B)B&!!!     """""r7   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)rO   r   get_sub_commandshasattrr   r   )rK   rN   r   cmd_namecmds        r5   r   z!editable_wheel._set_editable_mode   s     $$W--..00 	# 	#H&&x00CsO,, #$(!!i(( #"	# 	#r7   c                 x   g }i }|                      d          }|                                D ]}|                      |          }t          |d          r)|                    |                                pg            t          |d          r)|                    |                                pi            ||fS )Nr   get_outputsget_output_mapping)r]   r   r   extendr   updater   )rK   filesmappingr   r   r   s         r5   _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~r7   	dist_namec                    |                      ||||           |                                  |                                 \  }}|                     d           |                     d           |                     d           ||fS )Nr   r   r   )r   _run_build_subcommandsr   _run_install)rK   r   r   r   r   r   r   s          r5   _run_build_commandsz"editable_wheel._run_build_commands  s     	iGLLL##%%%4466w)$$$)$$$&!!!g~r7   c                    |                      d          }|                                D ]`}|                      |          }|dk    r.t          |          t          k    r|                     |           K|                     |           ad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)r]   r   typebuild_py_cls_safely_runrun_command)rK   r   r   r   s       r5   r   z%editable_wheel._run_build_subcommands  s     33G<<**,, 	' 	'D,,T22Cz!!d3ii<&?&?  &&&&  &&&&	' 	'r7   r   c                     	 |                      |          S # t          $ r< t          j                     d| d| d}t	          j        |t          d           Y d S 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`   ra   
format_excr0   r1   r   )rK   r   r4   s      r5   r   zeditable_wheel._safely_run"  s    	K##H--- 	K 	K 	K +--  4<  '  C M#;JJJJJJJ	Ks    A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        |           |                     ||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   rg   -z
0.editablez.whl)suffixz
.build-libz.build-tempw)wheel.wheelfiler   r]   r   rU   get_tagr   rG   rl   unlinkr   rH   shutilcopytreerw   r   _select_strategywrite_files)rK   rY   r   rg   r   tag	build_tagarchive_name
wheel_pathr   r   	build_tmpunpackedlibtmpunpacked_dist_infor   r   strategy	wheel_objs                       r5   r_   z!editable_wheel._create_wheel_file6  sJ   ------..{;;	N	hh{**,,-- 	#;;i;;#;;;$-66
 	 +<@@@&l;;;	&m<<<	 	0x 	0c9 	0!%hT5G0H0H0M!N!NOD.0BCCC$$Xy~>>>!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   G5	GBGF0	*#FF0	FF0	 F!F0	$G0F44G7F48G;GGGGGG5G"	"G5%G"	&G55G9<G9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_)getattrrO   _loggerinfor   )rK   r   has_categorys      r5   r   zeditable_wheel._run_installR  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 	4r7   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   rD   rn   )r   rI   r$   r6   r(   r<   
_empty_dir	_LinkTreerO   _find_packages_simple_layoutrS   r+   setrp   
_StaticPth_TopLevelFinder)rK   r   r   r   
build_namerI   r(   auxiliary_dirpackageshas_simple_layoutis_compat_modesrc_dirs               r5   r   zeditable_wheel._select_strategyX  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7r7   )r8   r9   r:   r;   descriptionr   r$   user_optionsrL   rV   re   r[   rw   r   r>   r   _Pathr   r   r   r   r
   r   r   r   r   r_   r   r   r?   r7   r5   rA   rA   i   s         6K 	LK	$!6!<"==>L  V V V> > >4	A 	A 	A' ' '&HSM & & & &
0#0#).0#;@0#KP0# 0# 0# 0#d	# 	# 	#d3ic3h.G(H    		.3	@E	PU		tCy$sCx.(	)	 	 	 	' ' ',KC K K K K(  84S 4 4 4 488 8 	8
 
8 8 8 8 8 8r7   rA   c                   J    e Zd Zdddee         deeef         fdZd Zd ZdS )	r   r   r   r   r   c                     d S rF   r?   )rK   r   r   r   s       r5   __call__zEditableStrategy.__call__t      r7   c                     d S rF   r?   rJ   s    r5   	__enter__zEditableStrategy.__enter__w  r   r7   c                     d S rF   r?   rK   	_exc_type
_exc_value
_tracebacks       r5   __exit__zEditableStrategy.__exit__z  r   r7   N)	r8   r9   r:   r   r>   r
   r   r   r   r?   r7   r5   r   r   s  sh        k $s) d3PS8n          r7   r   c                   j    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dS )r   rN   r   path_entriesc                 0    || _         || _        || _        d S rF   )rN   r   r   )rK   rN   r   r   s       r5   __init__z_StaticPth.__init__  s    		(r7   r   r   r   r   c                     d                     d | j        D                       }t          | dd          }|                    d| j         d|           d S )N
c              3   X   K   | ]%}t          |                                          V  &d S rF   )r>   rq   ).0ps     r5   	<genexpr>z&_StaticPth.__call__.<locals>.<genexpr>  s2      II!S--IIIIIIr7   utf-8r   .pth)rU   r   byteswritestrr   )rK   r   r   r   entriescontentss         r5   r   z_StaticPth.__call__  sb    ))IIt7HIIIJJG116ty666AAAAAr7   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	
        )listrz   rQ   fspathr   r   warning_LENIENT_WARNINGrK   r4   s     r5   r   z_StaticPth.__enter__  sQ    	c")T.//	0	0   	..///r7   c                     d S rF   r?   r   s       r5   r   z_StaticPth.__exit__  r   r7   N)r8   r9   r:   r   r>   r   r   r   r
   r   r   r   r?   r7   r5   r   r   ~  s        )\ ) )DJ ) ) ) )
Bk B$s) Bd3PS8n B B B B
      r7   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.
    rN   r   r   r   c                    t          |          | _        t          |                                          | _        |                    d          j        | _        t                                          ||| j        g           d S )Nr   )	r   r   rq   r   r   	copy_file_filesuperr   )rK   rN   r   r   r   	__class__s        r5   r   z_LinkTree.__init__  sn     "-00i0022))*55?
td&8%9:::::r7   r   r   r   r   c                 z    |                      ||           t                                          |||           d S rF   )_create_linksr  r   )rK   r   r   r   r  s       r5   r   z_LinkTree.__call__  s;    5'***w/////r7   filer)   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   rq   relative_tor   r>   replacerQ   sep)rK   r  rT   s      r5   _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   ry   is_dirrZ   r  )rK   r   r!  r%  dests        r5   _create_filez_LinkTree._create_file  s\    !O3{!!## 	,Kd+++

8T
-----r7   c                      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#  rX   symhardc                 B    i | ]\  }}                     |          |S r?   )r  )r   kvrK   s      r5   
<dictcomp>z+_LinkTree._create_links.<locals>.<dictcomp>  s=     
 
 
1 ""1%%q
 
 
r7   r$  )r   rZ   _can_symlink_filesitemspopr  r(  )rK   outputsoutput_mapping	link_typemappingsoutputrelativesrcs   `       r5   r  z_LinkTree._create_links  s      ===/0BCCOEE	
 
 
 
&,,..
 
 
 	T4    	4 	4F--f55H 4HH44!!(F333%^^-- 	= 	=MHch)<<<<	= 	=r7   c                 N    d}t                               |t          z              | S )Nz=Strict editable install will be performed using a link tree.
)r   r  _STRICT_WARNINGr  s     r5   r   z_LinkTree.__enter__  s#    No-...r7   c                 P    d| j          d}t          j        |t                     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.
        )r   r0   r1   InformationOnlyrK   r   r   r   r4   s        r5   r   z_LinkTree.__exit__  s8       	c?+++++r7   rF   )r8   r9   r:   r;   r   r>   r   r   r   r
   r   r   r  r(  r  r   r   __classcell__)r  s   @r5   r   r     s%        	; 	;	; 	; 		; 	; 	; 	; 	; 	;0k 0$s) 0d3PS8n 0 0 0 0 0 0c hsm    . .C .3 . . . .= = ="  
, , , , , , ,r7   r   c                   Z    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
dS )r   rN   r   c                 "    || _         || _        d S rF   )rN   r   )rK   rN   r   s      r5   r   z_TopLevelFinder.__init__  s    				r7   r   r   r   r   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                                 }d| j         d}	t          |	          }
t          t!          |	||          d          }|                    |
 d|           t          d|
 d|
 dd          }|                    d| j         d	|           d S )
Nc              3      K   | ]}|g fV  	d S rF   r?   )r   nss     r5   r  z+_TopLevelFinder.__call__.<locals>.<genexpr>  s&      @@"b"X@@@@@@r7   r   z.finderr  z.pyzimport z; z
.install()r  )rN   rP   rQ   rR   r   r   _find_top_level_modulesrS   _find_package_rootsdict_find_namespacesr   _find_virtual_namespacesr   _make_identifierr  _finder_templater  )rK   r   r   r   rP   	top_levelrS   rootsnamespaces_r   findercontents               r5   r   z_TopLevelFinder.__call__  sE   9%2.335LTY5W5WXX	i+1r#I{HEE,0TY/52u==@@ 8 ? ?@@@2
 2
 - -
 2ty111!$''(ukBBGLL&~~~w///>&>>F>>>HH6ty666@@@@@r7   c                 N    d}t                               |t          z              | S )Nz=Editable install will be performed using a meta path finder.
)r   r  r  r  s     r5   r   z_TopLevelFinder.__enter__  s$    N..///r7   c                 >    d}t          j        |t                     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.
        )r0   r1   r=  r>  s        r5   r   z_TopLevelFinder.__exit__  s#     	c?+++++r7   N)r8   r9   r:   r   r>   r   r   r
   r   r   r   r?   r7   r5   r   r     s        \     Ak A$s) Ad3PS8n A A A A&  
, , , , ,r7   r   base_dirr)   c                    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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>   rq   r   
write_textr   AttributeErrorNotImplementedErrorOSErrorrQ   symlink
is_symlink	read_textr%  r`   LinksNotSupported)rS  r   path1path2rd   r4   s         r5   r0  r0    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   rS   rI   c                 "   fd| D             }|st                    i dhfv S t          j                            d |                                D                       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 r?   r   )r   pkgrS   rI   s     r5   r/  z"_simple_layout.<locals>.<dictcomp>4  s8        	sK==  r7   rD   c                 4    g | ]\  }}t          ||          S r?   )_parent_path)r   r-  r.  s      r5   
<listcomp>z"_simple_layout.<locals>.<listcomp>:  s&     O O O1a!3!3 O O Or7   c           	   3      K   | ]E\  }}t          t          g|                    d           R            t          |          k    V  FdS rn   N)_normalize_pathr   split)r   keyvaluery   s      r5   r  z!_simple_layout.<locals>.<genexpr>;  sj        C 	V5ciinn55566/%:P:PP     r7   )r   rQ   rT   
commonpathr1  all)r   rS   rI   layoutry   s    `` @r5   r   r     s    >      F  .;B:--W O O O O OPPF     ,,..     r7   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'
    Nr  )rk   lenrstriprQ   r  )rd  pkg_pathry   s      r5   rf  rf  A  sJ     &.%6%6s%;%;IXjCyj!!F==rv&&&r7   rN   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 rn   r?   r   mods     r5   rg  z"_find_packages.<locals>.<listcomp>S  s    >>>c3#::c:::r7   c                 .    g | ]}d |j         v |j         S rw  r   r   xs     r5   rg  z"_find_packages.<locals>.<listcomp>X  s!    HHHa#--16---r7   rn   )iterr   
py_modulesext_packageext_modules
rpartition)rN   r  nested_modulesr  modulepackage_s          r5   r   r   O  s      DM'R(((((((((&BJ>>Z>>>N I&,"HH;HHHH   ))#..A r7   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 ri  r?   rx  s     r5   r  z*_find_top_level_modules.<locals>.<genexpr>a  s&      <<S^^^^^^<<r7   c              3   6   K   | ]}d |j         v|j         V  dS ri  r{  r|  s     r5   r  z*_find_top_level_modules.<locals>.<genexpr>e  s0      EEq3af3D3DAF3D3D3D3DEEr7   )r  r  r  )rN   r  r  s      r5   rE  rE  _  s      &BJ<<z<<<<<<<<<< F&,"EEKEEEEEEEEEEEEF Fr7   rP   c                 \    fdt          |           D             }t          |          S )Nc           
      N    i | ]!}|t          t          |                    "S r?   )_absolute_rootr   )r   rd  rS   rP   s     r5   r/  z'_find_package_roots.<locals>.<dictcomp>m  s@     ! ! ! 	^-c;IIJJ! ! !r7   )sorted_remove_nested)r   rS   rP   	pkg_rootss    `` r5   rF  rF  h  sI    
! ! ! ! !(##! ! !I
 )$$$r7   rT   c                     t          |           }|j        }|                                r!t          |                                          S t          |                                |j        z            S )z(Works for packages and top-level modules)r   ry   rl   r>   rq   r   )rT   path_ry   s      r5   r  r  u  sY    JJE\F||~~ 25==??###6>>##ej0111r7   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.
    rn      r   NrD   )rk  rangerr  rU   r   r   rl   )r  rd  partsipartial_namerT   s         r5   rI  rI    s        	# 	#c>>		#s5zzA~q"-- 	# 	#A88E"1"I..L),	2FFGGD;;== #L	$A$A""""	#		# 	#r7   c              #      K   | D ]]}t          ||d          }t          |                                          r)t          |d                                          s||gfV  ^d S )NrD   z__init__.py)r   r   rl   )r   r  rd  rT   s       r5   rH  rH    s|            i44:: 	 tD-'@'@'G'G'I'I 	 -   r7   c                 :   t          |                                           }t          t          |                                                     D ]H\  t          fd|                                 D                       r|                               I|S )Nc              3   N   K   | ]\  }}|k    ot          ||          V   d S rF   )
_is_nested)r   other
other_pathrT   rd  s      r5   r  z!_remove_nested.<locals>.<genexpr>  sR       
 
!z 5LEZT5*EE
 
 
 
 
 
r7   )rG  copyreversedr
  r1  anyr2  )r  r7  rT   rd  s     @@r5   r  r    s    )..""##Fd9??#4#45566  	T 
 
 
 
 
%.__%6%6
 
 
 
 
 	 JJsOOOMr7   rd  rt  ry   parent_pathc                     t          |          }|                     |dd                              d                              d          }|                     |          o|t          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
    rD   r  rn   )rj  r  striprk  
startswithr   )rd  rt  ry   r  norm_pkg_pathrests         r5   r  r    s|     $H--M;;vr1%%++C0066s;;Dv 	G_T+-E-E-E-EFFFr7   filenamec                    t           j        dk    rt          j                            |           n| }t          j                            t          j                            t          j                            |                              S )z1Normalize a file/dir name for comparison purposescygwin)sysplatformrQ   rT   abspathnormcaserealpathnormpath)r  r  s     r5   rj  rj    s^     ),(@(@27??8$$$hD7BG,,RW-=-=d-C-CDDEEEr7   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   rmtreerQ   makedirs)r  s    r5   r   r     s,    
M$d++++KKr7   r   c                 ^    t          j        dd|           }|                                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)r  )resubisidentifier)r   safes     r5   rJ  rJ    s4     6-d++DKr7   c                        e Zd Zd Zd Zd ZdS )rr   c                 Z    || _         || _        || _        || _        g | _        d| _        d S )NF)rO   rP   rt   editable_namer3  dry_run)rK   rO   rt   r  rP   s        r5   r   z_NamespaceInstaller.__init__  s3    (  0*r7   c                 V    t           j                            | j        | j                  S )zInstallation target.)rQ   rT   rU   rt   r  rJ   s    r5   _get_targetz_NamespaceInstaller._get_target  s    w||D143EFFFr7   c                 D    t          t          | j                            S )z1Where the modules/packages should be loaded from.)reprr>   rP   rJ   s    r5   	_get_rootz_NamespaceInstaller._get_root  s    C&&'''r7   N)r8   r9   r:   r   r  r  r?   r7   r5   rr   rr     sD          G G G( ( ( ( (r7   rr   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          |                                d                     }t                              | ||          S )z_Create a string containing the code for the``MetaPathFinder`` and
    ``PathEntryFinder``.
    c                     | d         S )Nr   r?   )r  s    r5   <lambda>z"_finder_template.<locals>.<lambda>?  s
    1 r7   )rl  r   r   r   )rG  r  r1  _FINDER_TEMPLATEformatr  s      r5   rK  rK  9  sC     6'--//~~>>>??G""g*"UUUr7   c                       e Zd ZdZdS )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r8   r9   r:   r;   r?   r7   r5   r=  r=  C  s           r7   r=  c                       e Zd ZdZdS )r_  zCFile system does not seem to support either symlinks or hard links.Nr  r?   r7   r5   r_  r_  K  s        MMMMr7   r_  )Wr;   loggingrQ   r  r   r  ra   r0   
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!   	getLoggerr8   r   r$   r;  r  rA   r   r   r   r   boolr0  r   rf  r   rE  rF  r  rI  rH  r  r  rj  r   rJ  	Installerrr   r  rK  UserWarningr=  	FileErrorr_  r?   r7   r5   <module>r     s  
 
  				 				  



                                    ' ' ' ' ' '                        Q P P P P P P P P P P P @ @ @ @ @ @ 2 2 2 2 2 2 ( ( ( ( ( ( *))))))v $*******######c4iWT
'
H
%
%!$ !$ !$ !$ !$D !$ !$ !$H G8 G8 G8 G8 G8W G8 G8 G8T    x          .D, D, D, D, D,
 D, D, D,N", ", ", ", ", ", ", ",J $    ()sm)*.sCx.)GK)	) ) ) )X' ' ' (3-     F, F8C= F F F F
%sm
%c"
% 
% 
#s(^	
% 
% 
% 
%2 23 2 2 2 2#S#X #8C= # # # #0 3i $(cN eCcN#$       
d38n 
c3h 
 
 
 
C 3  # $    .Fe F F F F FR B    	3 	3 	 	 	 	( ( ( ( (*. ( ( ($E PV
VS)V7;CcN7KVV V V V    k   N N N N N( N N N N Nr7   