/ lib / setuptools / command / editable_wheel.pyc
editable_wheel.pyc
  1  o

  2  ���c�y�
  3  @s�dZddlZddlZddlZddlZddlZddlZddlZddlm	Z	ddl
  4  mZddlm
Z
ddlmZddlmZddlmZdd	lmZmZmZmZmZmZmZmZmZmZdd
  5  lm Z m!Z!m"Z"m#Z#ddl$m%Z&ddl'm(Z(dd
l)m*Z*er�ddl+m,Z,ej-dkr�ddlm.Z.ner�ddl/m.Z.nddl0m1Z.ee2efZ3ede3d�Z4e�5e6�Z7Gdd�de�Z8dZ9dZ:Gdd�de �Z;Gdd�de.�Z<Gdd�d�Z=Gdd�de=�Z>Gd d!�d!�Z?d"ed#e@fd$d%�ZAd&ee2d'ee2e2fd(ed#e@fd)d*�ZBd+d,�ZCd-e*d#ee2fd.d/�ZDd-e*d#ee2fd0d1�ZEd&ee2d'ee2e2fd2e3d#ee2e2ffd3d4�ZFd5e3d#e2fd6d7�ZGd8ee2e2fd#ee2fd9d:�ZHd&ee2d8ee2e2fd#eee2ee2ffd;d<�ZId8ee2e2fd#ee2e2ffd=d>�ZJd?e2d@e2dAe2dBe2d#e@f
  6  dCdD�ZKdEe3d#e2fdFdG�ZLdHe4d#e4fdIdJ�ZMdKe2d#e2fdLdM�ZNGdNdO�dOe#jO�ZPdPZQdKe2dQee2e2fdRee2ee2fd#e2fdSdT�ZRGdUdV�dVeS�ZTGdWdX�dXe"jU�ZVdS)Ya�
  7  Create a wheel that, when installed, will make the source package 'editable'
  8  (add it to the interpreter's path, including metadata) per PEP 660. Replaces
  9  'setup.py develop'.
 10  
 11  .. note::
 12     One of the mechanisms briefly mentioned in PEP 660 to implement editable installs is
 13     to create a separated directory inside ``build`` and use a .pth file to point to that
 14     directory. In the context of this file such directory is referred as
 15     *auxiliary build directory* or ``auxiliary_dir``.
 16  �N)�suppress)�Enum)�cleandoc)�chain)�Path)�TemporaryDirectory)
 17  �
TYPE_CHECKING�Dict�Iterable�Iterator�List�Mapping�Optional�Tuple�TypeVar�Union)�Command�SetuptoolsDeprecationWarning�errors�
 18  namespaces)�build_py��find_package_path)�Distribution��	WheelFile)��)�Protocol)�ABC�_P)�boundc@s6eZdZdZdZdZdZedee	ddfdd��Z
 19  d	S)
 20  �
_EditableModea
 21      Possible editable installation modes:
 22      `lenient` (new files automatically added to the package - DEFAULT);
 23      `strict` (requires a new installation when files are added/removed); or
 24      `compat` (attempts to emulate `python setup.py develop` - DEPRECATED).
 25      �strict�lenient�compat�mode�returncCsN|stjS|��}|tjvrt�d|�d���|dkr#d}t�|t�t|S)NzInvalid editable mode: z. Try: 'strict'.�COMPATax
 26              The 'compat' editable mode is transitional and will be removed
 27              in future versions of `setuptools`.
 28              Please adapt your code accordingly to use either the 'strict' or the
 29              'lenient' modes.
 30  
 31              For more information, please check:
 32              https://setuptools.pypa.io/en/latest/userguide/development_mode.html
 33              )	r"�LENIENT�upper�__members__r�OptionError�warnings�warnr)�clsr&�_mode�msg�r2��C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.10_3.10.2800.0_x64__qbz5n2kfra8p0\lib\site-packages\setuptools\command\editable_wheel.py�convertGs
 34  	z_EditableMode.convertN)�__name__�
 35  __module__�__qualname__�__doc__�STRICTr)r(�classmethodr�strr4r2r2r2r3r";sr"zU
 36  New or renamed files may not be automatically picked up without a new installation.
 37  zt
 38  Options like `package-data`, `include/exclude-package-data` or
 39  `packages.find.exclude/include` may have no effect.
 40  c@s$eZdZdZdZddddeejpd�fgZdd	�Zd
 41  d�Z	dd
�Z
 42  dd�Zdd�Zde
efdd�Zdedededefdd�Zdd�Zdeeeeeefffdd�Zdededededeeeeeefff
 43  d d!�Zd"d#�Zd$efd%d&�Zd'd(�Zd)efd*d+�Zded,ededd-fd.d/�ZdS)0�editable_wheelzkBuild 'editable' wheel for development.
 44      (This command is reserved for internal use of setuptools).
 45      z!create a PEP 660 'editable' wheel)z	dist-dir=�dz-directory to put final built distributions in)zdist-info-dir=�Iz(path to a pre-build .dist-info directoryzmode=N�cCsd|_d|_d|_d|_dS�N)�dist_dir�
dist_info_dir�project_dirr&��selfr2r2r3�initialize_optionsvs
 46  z!editable_wheel.initialize_optionscCs@|j}|jptj|_|jpi|_t|jptj�	|jd��|_dS)N�dist)
 47  �distribution�src_root�os�curdirrC�package_dirrrA�path�join)rErGr2r2r3�finalize_options|s zeditable_wheel.finalize_optionsc
 48  Cs|z#|jjdd�|��|�d�|�d�}|�|j�|�|�WdSty=}zt	�
 49  �d}t�t
|��|�d}~ww)NT)�exist_ok�bdist_wheela�
 50              Support for editable installs via PEP 660 was recently introduced
 51              in `setuptools`. If you are seeing this error, please report to:
 52  
 53              https://github.com/pypa/setuptools/issues
 54  
 55              Meanwhile you can try the legacy behavior by setting an
 56              environment variable and trying to install again:
 57  
 58              SETUPTOOLS_ENABLE_FEATURES="legacy-editable"
 59              )rA�mkdir�_ensure_dist_info�reinitialize_command�get_finalized_commandZwrite_wheelfilerB�_create_wheel_file�	Exception�	traceback�	print_excr�
InternalErrorr)rErQ�exr1r2r2r3�run�s
 60  
 61  ��zeditable_wheel.runcCsd|jdur|�d�}|j|_|��|��|j|_dSt|j��d�s&J�t|jd��	�s0J�dS)N�	dist_infoz
 62  .dist-info�METADATA)
 63  rBrTrA�
 64  output_dir�ensure_finalizedr\r;�endswithr�exists)rEr]r2r2r3rS�s
 65  
 66  z editable_wheel._ensure_dist_infocCsD|j}|jsdSt|j|j�dd����}t||||�}|��dS)Nr?�.)	rH�namespace_packagesrrCrL�get�resolve�_NamespaceInstaller�install_namespaces)rE�installation_dirZ
 67  pth_prefixrGrI�	installerr2r2r3�_install_namespaces�sz"editable_wheel._install_namespacesr'cCs2|jr	t|j�jnt�}tt|�d��}t|d�S)Nz
 68  *.egg-info)rBr�parent�mapr;�glob�next)rE�
 69  parent_dir�
 70  candidatesr2r2r3�_find_egg_info_dir�s
 71  z!editable_wheel._find_egg_info_dir�name�unpacked_wheel�	build_lib�tmp_dircCs|j}t|�}t|�}tt||�d�d��}tt||�d�d��}tt||�d�d��}	|jddd�}
 72  t|�|
 73  _d|
 74  _|jddd�}|jd	dd�}||_|_|_||_	|_
 75  |_|	|_|_
||_||_|�d
 76  �}
d|
_t|�|_|�d�}d|_|��|_|��|��|��d
S)a�Configure commands to behave in the following ways:
 77  
 78          - Build commands can write to ``build_lib`` if they really want to...
 79            (but this folder is expected to be ignored and modules are expected to live
 80            in the project directory...)
 81          - Binary extensions should be built in-place (editable_mode = True)
 82          - Data/header/script files are not part of the "editable" specification
 83            so they are written directly to the unpacked_wheel directory.
 84          z.data�data�headers�scripts�egg_infoT)�reinit_subcommands�build�install�install_scriptsrFN)rHr;rrT�egg_base�ignore_egg_info_in_manifest�
build_platlib�
build_purelibru�install_purelib�install_platlib�install_libr~�
build_scripts�install_headers�install_data�get_command_obj�no_ep�
 85  build_temp�compilerr�existing_egg_info_dir�_set_editable_moder`)rErsrtrurvrG�wheelrwrxryrzr|r}r~rr2r2r3�_configure_build�s2
 86  
 87  
 88  
 89  
 90  zeditable_wheel._configure_buildcCsN|j}|�d�}|��D]}|�|�}t|d�rd|_qt|d�r$d|_qdS)z8Set the ``editable_mode`` flag in the build sub-commandsr|�
editable_modeT�inplaceN)rHr��get_sub_commands�hasattrr�r�)rErGr|�cmd_name�cmdr2r2r3r��s
 91  
 92  
 93  
 94  ��z!editable_wheel._set_editable_modecCsjg}i}|�d�}|��D]#}|�|�}t|d�r"|�|��p g�t|d�r0|�|��p.i�q
||fS)Nr|�get_outputs�get_output_mapping)rUr�r��extendr��updater�)rE�files�mappingr|r�r�r2r2r3�_collect_build_outputs�s
 95  
 96  
 97  
 98  �z%editable_wheel._collect_build_outputs�	dist_namecCsJ|�||||�|��|��\}}|�d�|�d�|�d�||fS)Nrxryrw)r��_run_build_subcommandsr��_run_install)rEr�rtrurvr�r�r2r2r3�_run_build_commandss
 99  
100  
101  z"editable_wheel._run_build_commandscCsP|�d�}|��D]}|�|�}|dkr t|�tkr |�|�q	|�|�q	dS)a}
102          Issue #3501 indicates that some plugins/customizations might rely on:
103  
104          1. ``build_py`` not running
105          2. ``build_py`` always copying files to ``build_lib``
106  
107          However both these assumptions may be false in editable_wheel.
108          This method implements a temporary workaround to support the ecosystem
109          while the implementations catch up.
110          r|rN)rUr��type�build_py_cls�_safely_run�run_command)rEr|rsr�r2r2r3r�s
111  
112  �z%editable_wheel._run_build_subcommandsr�c	CsLz|�|�WSty%t���d|�d|�d�}tj|tdd�YdSw)Nz�
113  
114              If you are seeing this warning it is very likely that a setuptools
115              plugin or customization overrides the `z�` command, without
116              taking into consideration how editable installs run build steps
117              starting from v64.0.0.
118  
119              Plugin authors and developers relying on custom build steps are encouraged
120              to update their `aO` implementation considering the information in
121              https://setuptools.pypa.io/en/latest/userguide/extension.html
122              about editable installs.
123  
124              For the time being `setuptools` will silence this error and ignore
125              the faulty command, but this behaviour will change in future versions.
126  
127              �)�
128  stacklevel)r�rWrX�
129  format_excr-r.r)rEr�r1r2r2r3r�"s
130  ���zeditable_wheel._safely_runcCs�ddlm}|�d�}|j}d�|���}d}|�d|�d|�d�}t|j|�}|��r0|�	�t
131  |d�}	t
132  dd�}
133  t
134  d	d�}|	��}|
135  �t}
|�b}t|t|j�j�}t�
|j|�|�||j�|�|||
|�\}}|�|||
�}|�(||d
136  ��}||||�|�|�Wd�n1s�wYWd�n1s�wYWd�n1s�wYWd�n1s�wYWd�|SWd�|S1s�wY|S)Nrrr]�-z
137  0.editablez.whl)�suffixz
138  .build-libz.build-temp�w)�wheel.wheelfilerrUrsrN�get_tagrrArb�unlinkrrB�shutil�copytreerkr��_select_strategyZwrite_files)rErQrr]r��tagZ	build_tag�archive_name�
139  wheel_pathrtruZ	build_tmp�unpacked�lib�tmpZunpacked_dist_infor�r��strategyZ	wheel_objr2r2r3rV6sB
140  
141  
142  
143  �����(
144  �
145  �
146  z!editable_wheel._create_wheel_file�categorycCsLt|jd|��d�}|r"|�r$t�d|�d��|�d|���dSdSdS)NZhas_zInstalling z as non editable�install_)�getattrrH�_logger�infor�)rEr�Zhas_categoryr2r2r3r�Rs
147  
148  �zeditable_wheel._run_installr��EditableStrategycCs�d|�d|��}t|j�}t�|j�}|tjur)tt|jd|��}t|j|||�St	|j�}t
149  ||j|�}	|tju}
150  t
|j�dhkrD|	sF|
151  rX|j�dd�}t|j|t||�g�St|j|�S)zDDecides which strategy to use to implement an editable installation.�
__editable__.r�r|r?rc)rrCr"r4r&r9�
152  _empty_dir�	_LinkTreerH�_find_packages�_simple_layoutrLr(�setre�
153  _StaticPth�_TopLevelFinder)rErsr�ruZ
154  build_namerCr&�
auxiliary_dir�packagesZhas_simple_layoutZis_compat_mode�src_dirr2r2r3r�Xs
155  
156  
157  
158  zeditable_wheel._select_strategy)r5r6r7r8�descriptionrr"�user_optionsrFrOr\rSrkrr;rr�_Pathr�r�rrr	r�r�r�r�rVr�r�r2r2r2r3r<is`�
159  ���
160  �2"����
161  �����r<c@s>eZdZdddeedeeeffdd�Zdd�Zd	d
162  �ZdS)r�r�rr�r�cC�dSr@r2�rEr�r�r�r2r2r3�__call__t�zEditableStrategy.__call__cCr�r@r2rDr2r2r3�	__enter__wr�zEditableStrategy.__enter__cCr�r@r2�rE�	_exc_type�
163  _exc_value�
164  _tracebackr2r2r3�__exit__zr�zEditableStrategy.__exit__N)	r5r6r7rr;r	r�r�r�r2r2r2r3r�ss"r�c@sXeZdZdededeefdd�Zdddeed	eeeffd
165  d�Z	dd
�Z
166  dd�ZdS)r�rGrs�path_entriescCs||_||_||_dSr@)rGrsr�)rErGrsr�r2r2r3�__init__s
167  z_StaticPth.__init__r�rr�r�cCs@d�dd�|jD��}t|�d�d�}|�d|j�d�|�dS)N�
168  css�|]	}t|���VqdSr@)r;rf)�.0�pr2r2r3�	<genexpr>���z&_StaticPth.__call__.<locals>.<genexpr>�utf-8r��.pth)rNr��bytes�writestrrs)rEr�r�r��entries�contentsr2r2r3r��sz_StaticPth.__call__cCs,dtttj|j���d�}t�|t�|S)Nz_
169          Editable install will be performed using .pth file to extend `sys.path` with:
170          z	
171          )�listrmrJ�fspathr�r��warning�_LENIENT_WARNING�rEr1r2r2r3r��s
172  �z_StaticPth.__enter__cCr�r@r2r�r2r2r3r��r�z_StaticPth.__exit__N)r5r6r7rr;rrr�r	r�r�r�r2r2r2r3r�~s
173  "r�cs�eZdZdZdedededef�fdd�Zdd	d
174  eede	eeff�fdd
�Z
175  dedeefdd�Zddedefdd�Z
dd�Zdd�Zdd�Z�ZS)r�a`
176      Creates a ``.pth`` file that points to a link tree in the ``auxiliary_dir``.
177  
178      This strategy will only link files (not dirs), so it can be implemented in
179      any OS, even if that means using hardlinks instead of symlinks.
180  
181      By collocating ``auxiliary_dir`` and the original source code, limitations
182      with hardlinks should be avoided.
183      rGrsr�rucs>t|�|_t|���|_|�d�j|_t��|||jg�dS)Nr)	rr�rfrur��	copy_file�_file�superr�)rErGrsr�ru��	__class__r2r3r��s
184  z_LinkTree.__init__r�rr�r�cs |�||�t��|||�dSr@)�
_create_linksr�r�r�r�r2r3r��sz_LinkTree.__call__�filer'cCsRtt��t|����|j�}t|��tj	d�Wd�S1s"wYdS)N�/)
185  r�
186  ValueErrorrrf�relative_torur;�replacerJ�sep)rEr�rMr2r2r3�_normalize_output�s
187  
188   �z_LinkTree._normalize_outputN�relative_output�src_filecCs6|j|}|j��s|jjdd�|j|||d�dS)NT)�parents��link)r�rl�is_dirrRr�)rEr�r�r��destr2r2r3�_create_file�s
189  
190  z_LinkTree._create_filecs��jjddd�t�j�rdnd}�fdd�|��D�}|�dd�|D]}��|�}|r7||vr7��||�q$|��D]\}}�j|||d�q<dS)NT)r�rP�sym�hardcsi|]
191  \}}��|�|�qSr2)r��r��k�vrDr2r3�
192  <dictcomp>�s
193  ��z+_LinkTree._create_links.<locals>.<dictcomp>r�)r�rR�_can_symlink_files�items�popr�r�)rE�outputsZoutput_mapping�	link_type�mappings�output�relative�srcr2rDr3r��s
194  �
195  ��z_LinkTree._create_linkscC�d}t�|t�|S)Nz=Strict editable install will be performed using a link tree.
196  )r�r��_STRICT_WARNINGr�r2r2r3r���z_LinkTree.__enter__cCsd|j�d�}t�|t�dS)Nz\
197  
198          Strict editable installation performed using the auxiliary directory:
199              z�
200  
201          Please be careful to not remove this directory, otherwise you might not be able
202          to import/use your package.
203          )r�r-r.�InformationOnly�rEr�r�r�r1r2r2r3r��s�z_LinkTree.__exit__r@)r5r6r7r8rr;r�r�rr	r�rr�r�r�r�r��
__classcell__r2r2r�r3r��s"	����&r�c@sPeZdZdedefdd�Zdddeedeeeffd	d
204  �Zdd�Z	d
d�Z
205  dS)r�rGrscCs||_||_dSr@)rGrs)rErGrsr2r2r3r��s
206  z_TopLevelFinder.__init__r�rr�r�cCs�|jjptj}tt|j�t|j��}|jjpi}t|||�}t	tt
207  |jjp&g|�dd�t|�D���}d|j
�d�}	t|	�}
208  tt|	||�d�}|�|
209  �d�|�td|
210  �d|
211  �d	�d�}|�d|j
�d
212  �|�dS)Ncss�|]}|gfVqdSr@r2)r��nsr2r2r3r��s�z+_TopLevelFinder.__call__.<locals>.<genexpr>r�z.finderr�z.pyzimport z; z
213  .install()r�)rGrIrJrKrr��_find_top_level_modulesrL�_find_package_roots�dict�_find_namespacesr��_find_virtual_namespacesrs�_make_identifierr��_finder_templater�)rEr�r�r�rI�	top_levelrL�rootsZnamespaces_rs�finder�contentr2r2r3r��s�z_TopLevelFinder.__call__cCr
)Nz=Editable install will be performed using a meta path finder.
214  )r�r�r�r�r2r2r3r��rz_TopLevelFinder.__enter__cCsd}t�|t�dS)Nz�
215  
216          Please be careful with folders in your working directory with the same
217          name as your package as they may take precedence during imports.
218          )r-r.rrr2r2r3r��sz_TopLevelFinder.__exit__N)r5r6r7rr;r�rr	r�r�r�r2r2r2r3r��s
219  "r��base_dirr'cCstt|���d��o}t|d�t|d�}}|jddd�tttt��)t	�
220  ||�|��rD|jdd�dkrD	Wd�Wd�dSWd�n1sNwYzt	�
||�Wntyn}zd}t|�|�d}~ww	Wd�d	S1s{wYdS)
221  N)�dirz	file1.txtz	file2.txtZfile1r�)�encodingTz�File system does not seem to support either symlinks or hard links. Strict editable installs require one of them to be supported.F)rr;rfr�
222  write_textr�AttributeError�NotImplementedError�OSErrorrJ�symlink�
223  is_symlink�	read_textr�rW�LinksNotSupported)rr�Zpath1�path2r[r1r2r2r3rs*����
224  ��$�rr�rLrCcs^��fdd�|D�}|st��idhfvStj�dd�|��D���t�fdd�|��D��S)a[Return ``True`` if:
225      - all packages are contained by the same parent directory, **and**
226      - all packages become importable if the parent directory is added to ``sys.path``.
227  
228      >>> _simple_layout(['a'], {"": "src"}, "/tmp/myproj")
229      True
230      >>> _simple_layout(['a', 'a.b'], {"": "src"}, "/tmp/myproj")
231      True
232      >>> _simple_layout(['a', 'a.b'], {}, "/tmp/myproj")
233      True
234      >>> _simple_layout(['a', 'a.a1', 'a.a1.a2', 'b'], {"": "src"}, "/tmp/myproj")
235      True
236      >>> _simple_layout(['a', 'a.a1', 'a.a1.a2', 'b'], {"a": "a", "b": "b"}, ".")
237      True
238      >>> _simple_layout(['a', 'a.a1', 'a.a1.a2', 'b'], {"a": "_a", "b": "_b"}, ".")
239      False
240      >>> _simple_layout(['a', 'a.a1', 'a.a1.a2', 'b'], {"a": "_a"}, "/tmp/myproj")
241      False
242      >>> _simple_layout(['a', 'a.a1', 'a.a1.a2', 'b'], {"a.a1.a2": "_a2"}, ".")
243      False
244      >>> _simple_layout(['a', 'a.b'], {"": "src", "a.b": "_ab"}, "/tmp/myproj")
245      False
246      >>> # Special cases, no packages yet:
247      >>> _simple_layout([], {"": "src"}, "/tmp/myproj")
248      True
249      >>> _simple_layout([], {"a": "_a", "": "src"}, "/tmp/myproj")
250      False
251      csi|]	}|t|����qSr2r�r��pkg)rLrCr2r3r4s��z"_simple_layout.<locals>.<dictcomp>r?cSsg|]	\}}t||��qSr2)�_parent_pathrr2r2r3�
252  <listcomp>:sz"_simple_layout.<locals>.<listcomp>c3s6�|]\}}tt�g|�d��R��t|�kVqdS�rcN)�_normalize_pathr�split)r��key�value)rlr2r3r�;s
253  � �
254  �z!_simple_layout.<locals>.<genexpr>)r�rJrM�
255  commonpathr�all)r�rLrC�layoutr2)rLrlrCr3r�s��r�cCs0|�|�r|dt|��n|}|�dtj�S)a7Infer the parent path containing a package, that if added to ``sys.path`` would
256      allow importing that package.
257      When ``pkg`` is directly mapped into a directory with a different name, return its
258      own path.
259      >>> _parent_path("a", "src/a")
260      'src'
261      >>> _parent_path("b", "src/c")
262      'src/c'
263      Nr�)ra�len�rstriprJr�)r,�pkg_pathrlr2r2r3r-As 
264  r-rGccs~�t|jpg�EdH|jpg}dd�|D�}|jr|jVn|jp#g}|dd�|D�7}|D]
}|�d�\}}}|Vq/dS)NcSsg|]}d|vr|�qS�rcr2�r��modr2r2r3r.Ssz"_find_packages.<locals>.<listcomp>cSsg|]
265  }d|jvr|j�qSr:�rs�r��xr2r2r3r.Xsrc)�iterr��
266  py_modules�ext_package�ext_modules�
267  rpartition)rGrAZnested_modulesrC�module�package�_r2r2r3r�Os�
268  
269  
270  �r�ccsL�|jpg}dd�|D�EdH|js$|jpg}dd�|D�EdHdSdS)Ncss�|]	}d|vr|VqdSr/r2r;r2r2r3r�ar�z*_find_top_level_modules.<locals>.<genexpr>css �|]}d|jvr|jVqdSr/r=r>r2r2r3r�es�)rArBrC)rGrArCr2r2r3r_s�
271  
272  �rrIcs ��fdd�t|�D�}t|�S)Ncsi|]}|tt|�����qSr2)�_absolute_rootrr+�rLrIr2r3rms��z'_find_package_roots.<locals>.<dictcomp>)�sorted�_remove_nested)r�rLrI�	pkg_rootsr2rIr3rhs�rrMcCs4t|�}|j}|��rt|���St|��|j�S)z(Works for packages and top-level modules)rrlrbr;rfrs)rMZpath_rlr2r2r3rHus
273  rHrLccsv�|D]5}d|vr
274  q|�d�}tt|�ddd�D]}d�|d|��}tt||d��}|��r4||vr7|VqqdS)a8By carefully designing ``package_dir``, it is possible to implement the logical
275      structure of PEP 420 in a package without the corresponding directories.
276  
277      Moreover a parent package can be purposefully/accidentally skipped in the discovery
278      phase (e.g. ``find_packages(include=["mypkg.*"])``, when ``mypkg.foo`` is included
279      by ``mypkg`` itself is not).
280      We consider this case to also be a virtual namespace (ignoring the original
281      directory) to emulate a non-editable installation.
282  
283      This function will try to find these kinds of namespaces.
284      rc�r�����Nr?)r1�ranger7rNrrrb)rLr,�parts�i�partial_namerMr2r2r3r�s�
285  ���rccsB�|D]}t||d�}t|���rt|d���s||gfVqdS)Nr?z__init__.py)rrrb)r�rLr,rMr2r2r3r�s���rcsPt|���}tt|����D]\��t��fdd�|��D��r%|���q|S)Nc3s*�|]\}}�|kot��||�VqdSr@)�
286  _is_nested)r��other�
287  other_path�rMr,r2r3r��s
288  ��
289  �z!_remove_nested.<locals>.<genexpr>)r�copy�reversedr�r�anyr)rLr
290  r2rVr3rK�s�
291  �rKr,r9rl�parent_pathcCsDt|�}|�|dd��d��d�}|�|�o!|tt|g|�R��kS)a�
292      Return ``True`` if ``pkg`` is nested inside ``parent`` both logically and in the
293      file system.
294      >>> _is_nested("a.b", "path/a/b", "a", "path/a")
295      True
296      >>> _is_nested("a.b", "path/a/b", "a", "otherpath/a")
297      False
298      >>> _is_nested("a.b", "path/a/b", "c", "path/c")
299      False
300      >>> _is_nested("a.a", "path/a/a", "a", "path/a")
301      True
302      >>> _is_nested("b.a", "path/b/a", "a", "path/a")
303      False
304      r?rMrc)r0r��stripr1�
305  startswithr)r,r9rlrZZ
norm_pkg_path�restr2r2r3rS�s
306  
307  �rS�filenamecCs6tjdkrtj�|�n|}tj�tj�tj�|���S)z1Normalize a file/dir name for comparison purposes�cygwin)�sys�platformrJrM�abspath�normcase�realpath�normpath)r^r�r2r2r3r0�sr0�dir_cCstj|dd�t�|�|S)zFCreate a directory ensured to be empty. Existing files may be removed.T)�
ignore_errors)r��rmtreerJ�makedirs)rfr2r2r3r��s
308  r�rscCst�dd|�}|��s
J�|S)z�Make a string safe to be used as Python identifier.
309      >>> _make_identifier("12abc")
310      '_12abc'
311      >>> _make_identifier("__editable__.myns.pkg-78.9.3_local")
312      '__editable___myns_pkg_78_9_3_local'
313      z
314  \W|^(?=\d)rG)�re�sub�isidentifier)rs�safer2r2r3r�src@s$eZdZdd�Zdd�Zdd�ZdS)rgcCs(||_||_||_||_g|_d|_dS)NF)rHrIri�
editable_namer�dry_run)rErHrirnrIr2r2r3r��s
315  z_NamespaceInstaller.__init__cCstj�|j|j�S)zInstallation target.)rJrMrNrirnrDr2r2r3�_get_target�sz_NamespaceInstaller._get_targetcCstt|j��S)z1Where the modules/packages should be loaded from.)�reprr;rIrDr2r2r3�	_get_root�sz_NamespaceInstaller._get_rootN)r5r6r7r�rprrr2r2r2r3rg�srga<	import sys
316  from importlib.machinery import ModuleSpec
317  from importlib.machinery import all_suffixes as module_suffixes
318  from importlib.util import spec_from_file_location
319  from itertools import chain
320  from pathlib import Path
321  
322  MAPPING = {mapping!r}
323  NAMESPACES = {namespaces!r}
324  PATH_PLACEHOLDER = {name!r} + ".__path_hook__"
325  
326  
327  class _EditableFinder:  # MetaPathFinder
328      @classmethod
329      def find_spec(cls, fullname, path=None, target=None):
330          for pkg, pkg_path in reversed(list(MAPPING.items())):
331              if fullname == pkg or fullname.startswith(f"{{pkg}}."):
332                  rest = fullname.replace(pkg, "", 1).strip(".").split(".")
333                  return cls._find_spec(fullname, Path(pkg_path, *rest))
334  
335          return None
336  
337      @classmethod
338      def _find_spec(cls, fullname, candidate_path):
339          init = candidate_path / "__init__.py"
340          candidates = (candidate_path.with_suffix(x) for x in module_suffixes())
341          for candidate in chain([init], candidates):
342              if candidate.exists():
343                  return spec_from_file_location(fullname, candidate)
344  
345  
346  class _EditableNamespaceFinder:  # PathEntryFinder
347      @classmethod
348      def _path_hook(cls, path):
349          if path == PATH_PLACEHOLDER:
350              return cls
351          raise ImportError
352  
353      @classmethod
354      def _paths(cls, fullname):
355          # Ensure __path__ is not empty for the spec to be considered a namespace.
356          return NAMESPACES[fullname] or MAPPING.get(fullname) or [PATH_PLACEHOLDER]
357  
358      @classmethod
359      def find_spec(cls, fullname, target=None):
360          if fullname in NAMESPACES:
361              spec = ModuleSpec(fullname, None, is_package=True)
362              spec.submodule_search_locations = cls._paths(fullname)
363              return spec
364          return None
365  
366      @classmethod
367      def find_module(cls, fullname):
368          return None
369  
370  
371  def install():
372      if not any(finder == _EditableFinder for finder in sys.meta_path):
373          sys.meta_path.append(_EditableFinder)
374  
375      if not NAMESPACES:
376          return
377  
378      if not any(hook == _EditableNamespaceFinder._path_hook for hook in sys.path_hooks):
379          # PathEntryFinder is needed to create NamespaceSpec without private APIS
380          sys.path_hooks.append(_EditableNamespaceFinder._path_hook)
381      if PATH_PLACEHOLDER not in sys.path:
382          sys.path.append(PATH_PLACEHOLDER)  # Used just to trigger the path hook
383  r�rcCs(tt|��dd�d��}tj|||d�S)z_Create a string containing the code for the``MetaPathFinder`` and
384      ``PathEntryFinder``.
385      cSs|dS)Nrr2)r�r2r2r3�<lambda>?sz"_finder_template.<locals>.<lambda>)r2�rsr�r)rrJr�_FINDER_TEMPLATE�formatrtr2r2r3r9src@�eZdZdZdS)rz�Currently there is no clear way of displaying messages to the users
386      that use the setuptools backend directly via ``pip``.
387      The only thing that might work is a warning, although it is not the
388      most appropriate tool for the job...
389      N�r5r6r7r8r2r2r2r3rC�rc@rw)r)zCFile system does not seem to support either symlinks or hard links.Nrxr2r2r2r3r)Kryr))Wr8�loggingrJrjr�r`rXr-�
390  contextlibr�enumr�inspectr�	itertoolsr�pathlibr�tempfiler�typingrr	r
391  rrr
rrrr�
392  setuptoolsrrrrZsetuptools.command.build_pyrr��setuptools.discoveryr�setuptools.distrr�r�version_infor�typing_extensions�abcrr;r�r �	getLoggerr5r�r"rr�r<r�r�r�r��boolrr�r-r�rrrHrrrKrSr0r�r�	Installerrgrur�UserWarningr�	FileErrorr)r2r2r2r3�<module>s�0

393  
394  $G%�
395  ��
396  �,	�
397  ��
398  
399  �
�
400  �
401  �"	
H�
402  ��
403  �
404