a „oeÞƒã@sndZddlZddlZddlZddlZddlZddlZddlmZddl m Z ddl m Z ddl mZddlmZddlmZdd lmZmZmZmZmZmZmZmZmZmZd d lmZm Z m!Z!m"Z"m#Z#d d l$m%Z%d d l&m'Z'd dl(m)Z)m*Z*m+Z+ddl,m,Z-e�rddl.m/Z/ej0dk�r,ddlm1Z1n e�r@ddl2m1Z1n ddl3m4Z1ee5efZ6ede6d�Z7e 8e9¡Z:Gdd„de ƒZ;dZGdd„de1ƒZ?Gdd „d ƒZ@Gd!d"„d"e@ƒZAGd#d$„d$ƒZBe5eCd%œd&d'„ZDeeEd(œd)d*„ZFee5ee5e5feeEd+œd,d-„ZGd.d/„ZHe'ee5d0œd1d2„ZIe'ee5d0œd3d4„ZJee5ee5e5fe6ee5e5fd5œd6d7„ZKe6e5d8œd9d:„ZLee5e5fee5d;œdœd?d@„ZNee5e5fee5e5fd;œdAdB„ZOe5e5e5e5eEdCœdDdE„ZPe7e7dFœdGdH„ZQGdIdJ„dJe#jRƒZSdKZTe5ee5e5fee5ee5fe5dLœdMdN„ZUGdOdP„dPe"jVƒZWGdQdR„dRe+ƒZXdS)Saè 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Ú_normalizationÚ_pathÚerrorsÚ namespaces©Úfind_package_path)Ú Distribution)ÚInformationOnlyÚSetuptoolsDeprecationWarningÚSetuptoolsWarningé)Úbuild_py©Ú WheelFile)éé)ÚProtocol)ÚABCÚ_P)Úboundc@s4eZdZdZdZdZdZeee ddœdd„ƒZ dS) Ú _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). ÚstrictZlenientÚcompat)ÚmodeÚreturncCsN|s tjS| ¡}|tjvr.t d|›d�¡‚|dkrFtjdddd�t|S)NzInvalid editable mode: z. Try: 'strict'.ÚCOMPATzCompat editable installsa  The 'compat' editable mode is transitional and will be removed in future versions of `setuptools`. Please adapt your code accordingly to use either the 'strict' or the 'lenient' modes. úuserguide/development_mode.html)Zsee_docs)r(ÚLENIENTÚupperÚ __members__rZ OptionErrorrÚemit)Úclsr+Ú_mode©r5úBC:\Program Files\Certbot\pkgs\setuptools\command\editable_wheel.pyÚconvertQs øz_EditableMode.convertN) Ú__name__Ú __module__Ú __qualname__Ú__doc__ÚSTRICTr/r-Ú classmethodrÚstrr7r5r5r5r6r(Es 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 @seZdZdZdZddddeejp"dƒfgZdd „Zd d „Z d d „Z dd„Z dd„Z e edœdd„Zeeeedœdd„Zdd„Zeeeeeeffdœdd„Zeeeeeeeeeeffdœdd„Zdd „Zed!œd"d#„Zd$d%„Zed&œd'd(„Zeeed)d*œd+d,„ZdS)-Úeditable_wheelz®Build 'editable' wheel for development. This command is private and reserved for internal use of setuptools, users should rely on ``setuptools.build_meta`` APIs. zBDO NOT CALL DIRECTLY, INTERNAL ONLY: create PEP 660 editable wheel)z dist-dir=Údz-directory to put final built distributions in)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+©Úselfr5r5r6Úinitialize_options†sz!editable_wheel.initialize_optionscCs@|j}|jptj|_|jpi|_t|jp6tj  |jd¡ƒ|_dS)NÚdist) Ú distributionÚsrc_rootÚosÚcurdirrFÚ package_dirrrDÚpathÚjoin)rHrJr5r5r6Úfinalize_optionsŒs zeditable_wheel.finalize_optionscCs„zD|jjdd�| ¡| d¡| d¡}| |j¡| |¡Wn:ty~t   ¡|j j pj|j   ¡}tj|d�‚Yn0dS)NT)Úexist_okÚ bdist_wheel)Úproject)rDÚmkdirÚ_ensure_dist_infoÚreinitialize_commandÚget_finalized_commandZwrite_wheelfilerEÚ_create_wheel_fileÚ ExceptionÚ tracebackÚ print_excrKÚnameZget_nameÚ_DebuggingTipsr2)rHrTrUr5r5r6Úrun’s     zeditable_wheel.runcCsb|jdur6| d¡}|j|_| ¡| ¡|j|_n(t|jƒ d¡sJJ‚t|jdƒ  ¡s^J‚dS)NÚ dist_infoz .dist-infoZMETADATA) rErXrDZ output_dirÚensure_finalizedr`r>ÚendswithrÚexists)rHrar5r5r6rW£s   z editable_wheel._ensure_dist_infocCsD|j}|jsdSt|j|j dd¡ƒ ¡}t||||ƒ}| ¡dS)NrBÚ.) rKÚnamespace_packagesrrFrOÚgetÚresolveÚ_NamespaceInstallerZinstall_namespaces)rHÚinstallation_dirZ pth_prefixrJrLZ installerr5r5r6Ú_install_namespaces®s z"editable_wheel._install_namespaces)r,cCs2|jrt|jƒjntƒ}tt| d¡ƒ}t|dƒS)Nz *.egg-info)rErÚparentÚmapr>ÚglobÚnext)rHZ parent_dirZ candidatesr5r5r6Ú_find_egg_info_dir¸sz!editable_wheel._find_egg_info_dir)r^Úunpacked_wheelÚ build_libÚtmp_dircCs|j}t|ƒ}t|ƒ}tt||›d�dƒƒ}tt||›d�dƒƒ}tt||›d�dƒƒ} |jddd�} t|ƒ| _d| _|jddd�} |jd dd�} || _| _| _|| _ | _ | _ | | _ | _ || _|| _| 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)Zreinit_subcommandsÚbuildÚinstallÚinstall_scriptsrFN)rKr>rrXZegg_baseZignore_egg_info_in_manifestZ build_platlibZ build_purelibrrZinstall_purelibZinstall_platlibZ install_librzZ build_scriptsZinstall_headersZ install_dataÚget_command_objZno_epZ build_tempÚcompilerpZexisting_egg_info_dirÚ_set_editable_moderb)rHr^rqrrrsrJÚwheelrtrurvrwrxryrzrr5r5r6Ú_configure_build½s2      zeditable_wheel._configure_buildcCsN|j}| d¡}| ¡D]0}| |¡}t|dƒr8d|_qt|dƒrd|_qdS)z8Set the ``editable_mode`` flag in the build sub-commandsrxÚ editable_modeTÚinplaceN)rKr{Úget_sub_commandsÚhasattrr€r�)rHrJrxÚcmd_nameÚcmdr5r5r6r}ïs     z!editable_wheel._set_editable_modecCsjg}i}| d¡}| ¡D]F}| |¡}t|dƒrD| | ¡p@g¡t|dƒr| | ¡p\i¡q||fS)NrxÚ get_outputsÚget_output_mapping)rYr‚rƒÚextendr†Úupdater‡)rHÚfilesÚmappingrxr„r…r5r5r6Ú_collect_build_outputsús     z%editable_wheel._collect_build_outputs)Ú dist_namerqrrrsr,cCsJ| ||||¡| ¡| ¡\}}| d¡| d¡| d¡||fS)Nrurvrt)rÚ_run_build_subcommandsrŒÚ _run_install)rHr�rqrrrsrŠr‹r5r5r6Ú_run_build_commandss    z"editable_wheel._run_build_commandscCsP| d¡}| ¡D]8}| |¡}|dkr@t|ƒtkr@| |¡q| |¡qdS)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. rxrN)rYr‚ÚtypeÚ build_py_clsÚ _safely_runÚ run_command)rHrxr^r…r5r5r6rŽs     z%editable_wheel._run_build_subcommands)r„c CsHz | |¡WStyBt ddt ¡›d|›d|›d�¡Yn0dS)Nz0Customization incompatible with editable installz zŒ If you are seeing this warning it is very likely that a setuptools plugin or customization overrides the `a` command, without taking into consideration how editable installs run build steps starting from setuptools v64.0.0. Plugin authors and developers relying on custom build steps are encouraged to update their `ab` implementation considering the information about editable installs in https://setuptools.pypa.io/en/latest/userguide/extension.html. For the time being `setuptools` will silence this error and ignore the faulty command, but this behaviour will change in future versions. )r”r[rr2r\Ú format_exc)rHr„r5r5r6r“)s  ÿü ÷þzeditable_wheel._safely_runc Cs¬ddlm}| d¡}|j}d | ¡¡}d}|›d|›d|›d�}t|j|ƒ}| ¡r`|  ¡t |d�} t dd�} t d d�} | ��} | �ì} | �Æ}t| t|j ƒjƒ}t   |j |¡| | |¡| || | |¡\}}| ||| ¡}|�R||d ƒ�&}||||ƒ| | ¡Wdƒn1�s0YWdƒn1�s>0YWdƒn1�s^0YWdƒn1�s~0YWdƒn1�sž0Y|S) Nrr raú-z 0.editablez.whl)Úsuffixz .build-libz .build-tempÚw)Úwheel.wheelfiler!rYr^rQZget_tagrrDrdÚunlinkrrEÚshutilÚcopytreerkr�Ú_select_strategyZ write_files)rHrTr!rar�ÚtagZ build_tagÚ archive_nameZ wheel_pathrqrrZ build_tmpZunpackedÚlibÚtmpZunpacked_dist_inforŠr‹ZstrategyZ wheel_objr5r5r6rZEs,        ªz!editable_wheel._create_wheel_file)ÚcategorycCsDt|jd|›�dƒ}|r@|ƒr@t d|›d�¡| d|›�¡dS)NZhas_z Installing z as non editableZinstall_)ÚgetattrrKÚ_loggerÚinfor”)rHr¢Z has_categoryr5r5r6r�as zeditable_wheel._run_installÚEditableStrategy)r^ržrrr,c Cs¼d|›d|›�}t|jƒ}t |j¡}|tjurRtt|jd|ƒƒ}t|j|||ƒSt |jƒ}t ||j |ƒ} |tj u} t |j ƒdhkrˆ| sŒ| r°|j  dd¡} t|j|t|| ƒgƒSt|j|ƒS)zDDecides which strategy to use to implement an editable installation.ú __editable__.r–rxrBre)rrFr(r7r+r<Ú _empty_dirÚ _LinkTreerKÚ_find_packagesÚ_simple_layoutrOr-ÚsetrgÚ _StaticPthÚ_TopLevelFinder) rHr^ržrrZ build_namerFr+Ú auxiliary_dirÚpackagesZhas_simple_layoutZis_compat_modeZsrc_dirr5r5r6r�gs     zeditable_wheel._select_strategy)r8r9r:r;Ú descriptionrr(Z user_optionsrIrRr`rWrkrr>rpÚ_Pathrr}rr r rŒr�rŽr“rZr�r�r5r5r5r6r?xs8ý  ÿ 2 "þ ûr?c@s:eZdZdeeeeefdœdd„Zdd„Zdd„Zd S) r¦r!©r~rŠr‹cCsdSrCr5©rHr~rŠr‹r5r5r6Ú__call__ƒszEditableStrategy.__call__cCsdSrCr5rGr5r5r6Ú __enter__†szEditableStrategy.__enter__cCsdSrCr5©rHÚ _exc_typeÚ _exc_valueÚ _tracebackr5r5r6Ú__exit__‰szEditableStrategy.__exit__N) r8r9r:r r>r rµr¶r»r5r5r5r6r¦‚sr¦c@sPeZdZeeeedœdd„Zdeeeeefdœdd„Z dd „Z d d „Z d S) r­©rJr^Ú path_entriescCs||_||_||_dSrCr¼)rHrJr^r½r5r5r6Ú__init__Žsz_StaticPth.__init__r!r³cCs>d dd„|jDƒ¡}t|›d�ƒ}| d|j›d�|¡dS)NÚ css|]}t| ¡ƒVqdSrC)r>rh)Ú.0Úpr5r5r6Ú ”óz&_StaticPth.__call__..r§ú.pth)rQr½Ú _encode_pthÚwritestrr^)rHr~rŠr‹ÚentriesÚcontentsr5r5r6rµ“sz_StaticPth.__call__cCs,dtttj|jƒƒ›d�}t |t¡|S)Nz_ Editable install will be performed using .pth file to extend `sys.path` with: z )ÚlistrmrMÚfspathr½r¤ÚwarningÚ_LENIENT_WARNING©rHÚmsgr5r5r6r¶˜s þz_StaticPth.__enter__cCsdSrCr5r·r5r5r6r» sz_StaticPth.__exit__N) r8r9r:rr>r rr¾r rµr¶r»r5r5r5r6r­�sr­csŒeZdZdZeeeedœ‡fdd„ Zdeee eefdœ‡fdd„ Z ee ed œd d „Z deed œdd„Z dd„Zdd„Zdd„Z‡ZS)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. )rJr^r¯rrcs>t|ƒ|_t|ƒ ¡|_| d¡j|_tƒ |||jg¡dS)Nr) rr¯rhrrr{Z copy_fileÚ_fileÚsuperr¾)rHrJr^r¯rr©Ú __class__r5r6r¾¯s z_LinkTree.__init__r!r³cs | ||¡tƒ |||¡dSrC)Ú _create_linksrÐrµr´rÑr5r6rµ»s z_LinkTree.__call__)Úfiler,cCsRttƒ�6t|ƒ ¡ |j¡}t|ƒ tj d¡WdƒS1sD0YdS)Nú/) rÚ ValueErrorrrhÚ relative_torrr>ÚreplacerMÚsep)rHrÔrPr5r5r6Ú_normalize_output¿s 0z_LinkTree._normalize_outputN)Úrelative_outputÚsrc_filecCs6|j|}|j ¡s"|jjdd�|j|||d�dS)NT)Úparents©Úlink)r¯rlÚis_dirrVrÏ)rHrÛrÜrßÚdestr5r5r6Ú _create_fileÆs  z_LinkTree._create_filecs–ˆjjddd�tˆjƒrdnd}‡fdd„| ¡Dƒ}| dd¡|D]&}ˆ |¡}|rH||vrHˆ ||¡qH| ¡D]\}}ˆj|||d�qxdS)NT)rÝrSZsymZhardcsi|]\}}ˆ |¡|“qSr5)rÚ©rÀÚkÚvrGr5r6Ú ÏrÃz+_LinkTree._create_links..rÞ)r¯rVÚ_can_symlink_filesÚitemsÚpoprÚrâ)rHÚoutputsZoutput_mappingZ link_typeZmappingsÚoutputÚrelativeÚsrcr5rGr6rÓÌs   z_LinkTree._create_linkscCsd}t |t¡|S)Nz=Strict editable install will be performed using a link tree. )r¤rËÚ_STRICT_WARNINGrÍr5r5r6r¶Úsz_LinkTree.__enter__cCsd|j›d�}t d|¡dS)Nz\ Strict editable installation performed using the auxiliary directory: z† Please be careful to not remove this directory, otherwise you might not be able to import/use your package. úEditable installation.)r¯rr2©rHr¸r¹rºrÎr5r5r6r»ßsþz_LinkTree.__exit__)N)r8r9r:r;rr>r²r¾r r rµrrÚrârÓr¶r»Ú __classcell__r5r5rÑr6r©¤s û "r©c@sJeZdZeedœdd„Zdeeeeefdœdd„Zdd „Z d d „Z d S) r®©rJr^cCs||_||_dSrCrò)rHrJr^r5r5r6r¾ësz_TopLevelFinder.__init__r!r³c súˆjjp tj}ttˆjƒtˆjƒƒ}ˆjjp.i}t|||ƒ‰t tt ˆjj pLgˆƒdd„t ˆƒDƒƒƒ}‡‡fdd„ˆjj p|gDƒ}iˆ¥|¥}dˆj›d�} t | ¡} tt| ||ƒdƒ} | | ›d�| ¡td | ›d | ›d �ƒ} | dˆj›d �| ¡dS) Ncss|]}|gfVqdSrCr5)rÀÚnsr5r5r6rÂørÃz+_TopLevelFinder.__call__..cs"i|]}|t|ˆˆjjpdƒ“qS)rB)rrJrL©rÀÚpkg©ÚrootsrHr5r6ræüsÿz,_TopLevelFinder.__call__..r§z.finderúutf-8z.pyzimport z; z .install()rÄ)rJrLrMrNrrªÚ_find_top_level_modulesrOÚ_find_package_rootsÚdictÚ_find_namespacesr°Ú_find_virtual_namespacesrfr^rZsafe_identifierÚbytesÚ_finder_templaterÆrÅ) rHr~rŠr‹rLZ top_levelrOZ namespaces_Zlegacy_namespacesr^ÚfinderÚcontentr5rör6rµïs(  þÿ  þ  z_TopLevelFinder.__call__cCsd}t |t¡|S)Nz=Editable install will be performed using a meta path finder. )r¤rËrÌrÍr5r5r6r¶sz_TopLevelFinder.__enter__cCsd}t d|¡dS)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ï)rr2rðr5r5r6r»sz_TopLevelFinder.__exit__N) r8r9r:rr>r¾r r rµr¶r»r5r5r5r6r®êsr®)rr,cCsntjdkrdnd}t ¡�@}t ||¡}| |¡| ¡| d¡| ¡WdƒS1s`0YdS)a!.pth files are always read with 'locale' encoding, the recommendation from the cpython core developers is to write them as ``open(path, "w")`` and ignore warnings (see python/cpython#77102, pypa/setuptools#3937). This function tries to simulate this behaviour without having to create an actual file, in a way that supports a range of active Python versions. (There seems to be some variety in the way different version of Python handle ``encoding=None``, not all of them use ``locale.getpreferredencoding(False)``). )r"é ÚlocaleNr) ÚsysÚ version_infoÚioÚBytesIOÚ TextIOWrapperÚwriteÚflushÚseekÚread)rÚencodingÚbufferÚwrapperr5r5r6rÅs     rÅ)Úbase_dirr,c Cstt| ¡ƒd��æ}t|dƒt|dƒ}}|jddd�ttttƒ�Pt   ||¡|  ¡r†|j dd�dkr†WdƒWdƒdSWdƒn1sš0Yzt   ||¡Wn2tyæ}zd}t|ƒ|‚WYd}~n d}~00Wdƒd S1�s0YdS) N)Údirz file1.txtz file2.txtZfile1rø)r Tz�File system does not seem to support either symlinks or hard links. Strict editable installs require one of them to be supported.F)rr>rhrÚ write_textrÚAttributeErrorÚNotImplementedErrorÚOSErrorrMÚsymlinkÚ is_symlinkÚ read_textrßr[ÚLinksNotSupported)rr¡Zpath1Zpath2ÚexrÎr5r5r6rç-s :ÿ rç)r°rOrFr,cs^‡‡fdd„|Dƒ}|s*tˆƒidhfvStj dd„| ¡Dƒ¡‰t‡fdd„| ¡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 csi|]}|t|ˆˆƒ“qSr5rrô)rOrFr5r6ræ`rÃz"_simple_layout..rBcSsg|]\}}t||ƒ‘qSr5)Ú _parent_pathrãr5r5r6Ú crÃz"_simple_layout..c3s0|](\}}t tˆg| d¡¢RŽ|¡VqdS©reN)rZ same_pathrÚsplit)rÀÚkeyÚvalue)rlr5r6rÂdsÿz!_simple_layout..)r¬rMrPÚ commonpathrèÚall)r°rOrFZlayoutr5)rOrlrFr6r«As þr«cCs0| |¡r|dt|ƒ …n|}| dtj¡S)a7Infer 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Õ)rcÚlenÚrstriprMrÙ)rõÚpkg_pathrlr5r5r6rjs r)rJr,ccs|t|jp gƒEdH|jpg}dd„|Dƒ}|jr<|jVn|jpDg}|dd„|Dƒ7}|D]}| d¡\}}}|Vq\dS)NcSsg|]}d|vr|‘qS©rer5©rÀÚmodr5r5r6r|rÃz"_find_packages..cSsg|]}d|jvr|j‘qSr&©r^©rÀÚxr5r5r6r�rÃre)Úiterr°Ú py_modulesÚ ext_packageÚ ext_modulesÚ rpartition)rJr-Znested_modulesr/ÚmoduleÚpackageÚ_r5r5r6rªxs   rªccsF|jpg}dd„|DƒEdH|jsB|jp,g}dd„|DƒEdHdS)Ncss|]}d|vr|VqdSrr5r'r5r5r6rŠrÃz*_find_top_level_modules..css|]}d|jvr|jVqdSrr)r*r5r5r6rÂŽrÃ)r-r.r/)rJr-r/r5r5r6rùˆs   rù)r°rOrLr,cs ‡‡fdd„t|ƒDƒ}t|ƒS)Ncsi|]}|tt|ˆˆƒƒ“qSr5)Ú_absolute_rootrrô©rOrLr5r6ræ–sÿz'_find_package_roots..)ÚsortedÚ_remove_nested)r°rOrLÚ pkg_rootsr5r5r6rú‘s þrú)rPr,cCs8t|ƒ}|j}| ¡r"t| ¡ƒSt| ¡|jƒSdS)z(Works for packages and top-level modulesN)rrlrdr>rhr^)rPZpath_rlr5r5r6r4žs  r4)r8r,ccst|D]j}d|vrq| d¡}tt|ƒdddƒD]<}d |d|…¡}tt||dƒƒ}| ¡rf||vr0|Vq0qdS)a8By 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. rerréÿÿÿÿNrB)rÚranger#rQrrrd)r8rõÚpartsÚiZ partial_namerPr5r5r6rý©s  rý)r°r8r,ccs@|D]6}t||dƒ}t|ƒ ¡rt|dƒ ¡s||gfVqdS)NrBz __init__.py)rrrd)r°r8rõrPr5r5r6rüÁs rücsPt| ¡ƒ}tt| ¡ƒƒD].\‰‰t‡‡fdd„| ¡Dƒƒr| ˆ¡q|S)Nc3s(|] \}}ˆ|kotˆˆ||ƒVqdSrC)Ú _is_nested)rÀÚotherÚ other_path©rPrõr5r6rÂÎsÿz!_remove_nested..)rûÚcopyÚreversedrÉrèÚanyré)r8rër5r@r6r7Ês þ r7)rõr%rlÚ parent_pathr,cCsHt |¡}| |dd¡ d¡ d¡}| |¡oF|t t|g|¢RŽ¡kS)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 rBrre)rÚnormpathrØÚstriprÚ startswithr)rõr%rlrDZ norm_pkg_pathÚrestr5r5r6r=×s  ÿr=)Údir_r,cCstj|dd�t |¡|S)zFCreate a directory ensured to be empty. Existing files may be removed.T)Ú ignore_errors)r›ÚrmtreerMÚmakedirs)rIr5r5r6r¨ís r¨c@s$eZdZdd„Zdd„Zdd„ZdS)ricCs(||_||_||_||_g|_d|_dS)NF)rKrLrjÚ editable_namerêÚdry_run)rHrKrjrMrLr5r5r6r¾õs z_NamespaceInstaller.__init__cCstj |j|j|j¡S)zInstallation target.)rMrPrQrjrMZ nspkg_extrGr5r5r6Ú_get_nspkg_fileýsz#_NamespaceInstaller._get_nspkg_filecCstt|jƒƒS)z1Where the modules/packages should be loaded from.)Úreprr>rLrGr5r5r6Ú _get_rootsz_NamespaceInstaller._get_rootN)r8r9r:r¾rOrQr5r5r5r6riôsria import sys from importlib.machinery import ModuleSpec, PathFinder from importlib.machinery import all_suffixes as module_suffixes from importlib.util import spec_from_file_location from itertools import chain from pathlib import Path MAPPING = {mapping!r} NAMESPACES = {namespaces!r} PATH_PLACEHOLDER = {name!r} + ".__path_hook__" class _EditableFinder: # MetaPathFinder @classmethod def find_spec(cls, fullname, path=None, target=None): extra_path = [] # Top-level packages and modules (we know these exist in the FS) if fullname in MAPPING: pkg_path = MAPPING[fullname] return cls._find_spec(fullname, Path(pkg_path)) # Handle immediate children modules (required for namespaces to work) # To avoid problems with case sensitivity in the file system we delegate # to the importlib.machinery implementation. parent, _, child = fullname.rpartition(".") if parent and parent in MAPPING: return PathFinder.find_spec(fullname, path=[MAPPING[parent], *extra_path]) # Other levels of nesting should be handled automatically by importlib # using the parent path. 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‹rr,cCs(tt| ¡dd„d�ƒ}tj|||d�S)z_Create a string containing the code for the``MetaPathFinder`` and ``PathEntryFinder``. cSs|dS)Nrr5)rÁr5r5r6Ú_rÃz"_finder_template..)r©r^r‹r)rûr6rèÚ_FINDER_TEMPLATEÚformatrSr5r5r6rÿYsrÿc@seZdZdZdS)rzCFile system does not seem to support either symlinks or hard links.N)r8r9r:r;r5r5r5r6rcsrc@seZdZdZdZdZdS)r_z!Problem in editable installation.a  An error happened while installing `{project}` in editable mode. The following steps are recommended to help debug this problem: - Try to install the project normally, without using the editable mode. Does the error still persist? (If it does, try fixing the problem before attempting the editable mode). - If you are using binary extensions, make sure you have all OS-level dependencies installed (e.g. compilers, toolchains, binary libraries, ...). - Try the latest version of setuptools (maybe the error was already fixed). - If you (or your project dependencies) are using any setuptools extension or customization, make sure they support the editable mode. After following the steps above, if the problem still persists and you think this is related to how setuptools handles editable installations, please submit a reproducible example (see https://stackoverflow.com/help/minimal-reproducible-example) to: https://github.com/pypa/setuptools/issues r.N)r8r9r:Z_SUMMARYZ_DETAILSZ _SEE_DOCSr5r5r5r6r_gsr_)Yr;ZloggingrrMr›rr\Ú contextlibrÚenumrÚinspectrÚ itertoolsrÚpathlibrZtempfilerÚtypingrr r r r r rrrrrBrrrrrZ discoveryrrJrÚwarningsrrrrr’r™r!rr$Ztyping_extensionsÚabcr%r>r²r&Z getLoggerr8r¤r(rîrÌr?r¦r­r©r®rþrÅÚboolrçr«rrªrùrúr4rýrür7r=r¨Z InstallerrirTrÿZ FileErrorrr_r5r5r5r6Ús„       0          )  F1þ )   ü  þ Tþ