a „oe;ã@sâddlmZddlmZddlmZddlmmZddl Z ddl Z ddl Z ddl Z ddlZddlZddlmZddlmZmZmZmZmZmZddlmZdd lmZd Zd d „ZGd d„dejƒZdd„ZGdd„dƒZ dS)é)Úpartial)Úglob)Ú convert_pathN)ÚPath)ÚDictÚIterableÚIteratorÚListÚOptionalÚTupleé)Úunique_everseen)ÚSetuptoolsDeprecationWarning)z*.pyizpy.typedcCst |t |¡jtjB¡dS©N)ÚosÚchmodÚstatÚst_modeÚS_IWRITE)Útarget©rúr?r@r1r$rrrÚget_data_files_without_manifest[sz(build_py.get_data_files_without_manifestcsJ| |¡‰tjj|jg| d¡Ž}‡fdd„| |ˆ¡Dƒ}|ˆ||fS)NÚ.csg|]}tj |ˆ¡‘qSr)rÚpathÚrelpath)Ú.0Úfile©Úsrc_dirrrÚ msÿz0build_py._get_pkg_data_files..)Úget_package_dirrrEÚjoinÚ build_libÚsplitÚfind_data_files)r%r<Ú build_dirÚ filenamesrrIrr@es    þzbuild_py._get_pkg_data_filescCsd|j|j||td�}tttdd�|ƒ}tj |¡}t t j j |ƒ}t |j  |g¡|¡}| |||¡S)z6Return filenames for package's data files in 'src_dir')Úextra_patternsT)Ú recursive)Ú_get_platform_patternsr Ú_IMPLICIT_DATA_FILESr?rrÚ itertoolsÚchainÚ from_iterableÚfilterrrEÚisfilerAÚgetÚexclude_data_files)r%r<rJÚpatternsZglobs_expandedZ globs_matchesZ glob_filesÚfilesrrrrPssü  þzbuild_py.find_data_files)Úreturncs"|jrt| ¡ ¡ƒStƒ |¡S)ú1See :class:`setuptools.commands.build.SubCommand`)rr>Úget_output_mappingÚkeysr)r3)r%r0r.rrr3…szbuild_py.get_outputscCs(t | ¡| ¡¡}tt|dd„d�ƒS)racSs|dS)Nrr)ÚxrrrÚ‘óz-build_py.get_output_mapping..)Úkey)rWrXÚ _get_package_data_output_mappingÚ_get_module_mappingÚdictÚsorted)r%Úmappingrrrrb‹s þzbuild_py.get_output_mappingccs<| ¡D].\}}}| d¡}| |j||¡}||fVqdS)z5Iterate over all modules producing (dest, src) pairs.rDN)Zfind_all_modulesrOZget_module_outfilerN)r%r<r:r;Úfilenamerrrri“s zbuild_py._get_module_mappingccsH|jD]<\}}}}|D]*}tj ||¡}tj ||¡}||fVqqdS)z6Iterate over package data producing (dest, src) pairs.N)rrrErM)r%r<rJrQrRrmrÚsrcfilerrrrhšs z)build_py._get_package_data_output_mappingcCs@| ¡D]2\}}| tj |¡¡| ||¡\}}t|ƒqdS)z$Copy data files into build directoryN)rhZmkpathrrEÚdirnamer*r)r%rrnZ_outfZ_copiedrrrr2¢szbuild_py.build_package_datacCsji|_}|jjsdSi}|jp"dD]}||t| |¡ƒ<q$t|ddƒrzt|jdƒ  ¡rz|j}t|dƒ}|j dd�  ¡}n"|  d¡|  d¡}|j}|jj}tƒ}| ||¡D]¶} tj t| ƒ¡\} } d} | } | �r | | k�r | |v�r | } tj | ¡\} }tj || ¡} qÎ| |vr®| | k�r.| | ¡�rNq®n | || | ¡}|�rN| |¡| || g¡ | ¡q®dS)Nrrz SOURCES.txtzutf-8)ÚencodingÚegg_info)rArZinclude_package_datar1Úassert_relativerLÚgetattrrrÚexistsÚ read_textÚ splitlinesZ run_commandÚget_finalized_commandrqZfilelistr_Ú_IncludePackageDataAbuseÚ_filter_build_filesrrErOrMÚ is_moduleÚimportable_subpackageÚwarnrBr9)r%ZmfZsrc_dirsr<Z egg_info_dirZmanifestr_Zei_cmdÚcheckrEÚdÚfÚprevZoldfZdfÚ importablerrrr=©sD  ÿþ      zbuild_py.analyze_manifest)r_rqr`c#sl| d¡}||j|j|jf}dd„|Dƒ}|D]8}tj |¡‰tj |¡r`t‡fdd„|Dƒƒr.|Vq.dS)a} ``build_meta`` may try to create egg_info outside of the project directory, and this can be problematic for certain plugins (reported in issue #3500). Extensions might also include between their sources files created on the ``build_lib`` and ``build_temp`` directories. This function should filter this case of invalid files out. ÚbuildcSsg|]}|rtj |¡‘qSr)rrEÚnormpath)rGÚprrrrKÞrfz0build_py._filter_build_files..c3s|]}|ˆvVqdSrr)rGr~©Z norm_pathrrÚ ârfz/build_py._filter_build_files..N) rwrNZ build_tempZ build_baserrErƒÚisabsÚall)r%r_rqr‚Z build_dirsZ norm_dirsrHrr…rryÒs  "zbuild_py._filter_build_filescCsdSrrr$rrrÚget_data_filesåszbuild_py.get_data_filescCsÆz |j|WStyYn0tj |||¡}||j|<|rF|jjsJ|S|jjD]}||ksl| |d¡rRqvqR|St|dƒ�}|  ¡}Wdƒn1sž0Yd|vrÂt j   d|f¡‚|S)z8Check namespace packages' __init__ for declare_namespacerDÚrbNsdeclare_namespacezÁNamespace package problem: %s is a namespace package, but its __init__.py does not call declare_namespace()! Please fix it. (See the setuptools manual under "Namespace Packages" for details.) ") Úpackages_checkedÚKeyErrorrrÚ check_packagerZnamespace_packagesÚ startswithÚopenÚreadÚ distutilsÚerrorsZDistutilsError)r%r<Z package_dirZinit_pyÚpkgrÚcontentsrrrr�ès*      &ýÿzbuild_py.check_packagecCs"i|_tj |¡d|_d|_dS)NF)r‹rrÚinitialize_optionsrrr$rrrr•s zbuild_py.initialize_optionscCs0tj ||¡}|jjdur,tj |jj|¡S|Sr)rrrLrZsrc_rootrrErM)r%r<ÚresrrrrL s zbuild_py.get_package_dircs\tˆƒ‰| |j||¡}‡fdd„|Dƒ}tj |¡}t|ƒ‰‡fdd„ˆDƒ}tt|ƒƒS)z6Filter filenames for package's data files in 'src_dir'c3s|]}t ˆ|¡VqdSr)ÚfnmatchrZ©rGÚpattern)r_rrr†rfz.build_py.exclude_data_files..c3s|]}|ˆvr|VqdSrr)rGÚfn)Úbadrrr†rf)r>rUr!rWrXrYÚsetr )r%r<rJr_r^Z match_groupsÚmatchesZkeepersr)r›r_rr]sý zbuild_py.exclude_data_filescs0t || dg¡| |g¡¡}‡fdd„|DƒS)zÜ yield platform-specific path patterns (suitable for glob or fn_match) from a glob-based spec (such as self.package_data or self.exclude_package_data) matching package in src_dir. Úc3s |]}tj ˆt|ƒ¡VqdSr)rrErMrr˜rIrrr†/sÿz2build_py._get_platform_patterns..)rWrXr\)Úspecr<rJrSZ raw_patternsrrIrrU"s  ý ýzbuild_py._get_platform_patterns)r&r&Nr&)r&)'Ú__name__Ú __module__Ú __qualname__Ú__doc__rÚboolÚ__annotations__rr r'rr*r4r6r8r5rCr@rPr r3rrbrr rirhr2r=rryr‰r�r•rLr]Ú staticmethodrUÚ __classcell__rrr.rrs6   ÿ  )rcCs:tj |¡s|Sddlm}t d¡ ¡|}||ƒ‚dS)Nr)ÚDistutilsSetupErrorzÓ Error: setup script specifies an absolute path: %s setup() arguments must *always* be /-separated paths relative to the setup.py directory, *never* absolute paths. )rrEr‡Údistutils.errorsr¨ÚtextwrapÚdedentÚlstrip)rEr¨Úmsgrrrrr6s  ÿ öÿ rrc@s@eZdZdZGdd„deƒZdd„Zdd„Zdd „Zd d „Z d S) rxz>Inform users that package or module is included as 'data file'c@seZdZdZdZdS)z!_IncludePackageDataAbuse._WarningzU Package {importable!r} is absent from the `packages` configuration. a| ############################ # Package would be ignored # ############################ Python recognizes {importable!r} as an importable package[^1], but it is absent from setuptools' `packages` configuration. This leads to an ambiguous overall configuration. If you want to distribute this package, please make sure that {importable!r} is explicitly added to the `packages` configuration field. Alternatively, you can also rely on setuptools' discovery methods (for example by using `find_namespace_packages(...)`/`find_namespace:` instead of `find_packages(...)`/`find:`). You can read more about "package discovery" on setuptools documentation page: - https://setuptools.pypa.io/en/latest/userguide/package_discovery.html If you don't want {importable!r} to be distributed and are already explicitly excluding {importable!r} via `find_namespace_packages(...)/find_namespace` or `find_packages(...)/find`, you can try to use `exclude_package_data`, or `include-package-data=False` in combination with a more fine grained `package-data` configuration. You can read more about "package data files" on setuptools documentation page: - https://setuptools.pypa.io/en/latest/userguide/datafiles.html [^1]: For Python, any directory (with suitable naming) can be imported, even if it does not contain any `.py` files. On the other hand, currently there is no concept of package data directory, all directories are treated like packages. N)r r¡r¢Z_SUMMARYZ_DETAILSrrrrÚ_WarningNsr®cCs tƒ|_dSr)rœÚ_already_warnedr$rrrÚ__init__ysz!_IncludePackageDataAbuse.__init__cCs | d¡o|dtdƒ … ¡S)Nz.py)ÚendswithÚlenÚ isidentifier)r%rHrrrrz|sz"_IncludePackageDataAbuse.is_modulecCs6t|ƒj}tt tj|j¡ƒ}|r2d |g|¢¡SdS)NrD) rÚparentr>rWÚ takewhiler'r³ÚpartsrM)r%r´rHr“r¶rrrr{s  z._IncludePackageDataAbuse.importable_subpackagecCs(||jvr$|jj|d�|j |¡dS)N)r�)r¯r®ÚemitÚadd)r%r�rrrr|†s z_IncludePackageDataAbuse.warnN) r r¡r¢r£rr®r°rzr{r|rrrrrxKs +rx)!Ú functoolsrrZdistutils.utilrZdistutils.command.build_pyZcommandrrrr—rªr©r‘rWrÚpathlibrÚtypingrrrr r r Zextern.more_itertoolsr ÚwarningsrrVrrrrxrrrrÚs(