B ‘–Reo@ã@sddZddlZddlZddlZddlZddlmZddlTddl m Z ddl m Z Gdd„deƒZ dS) zHdistutils.command.build_py Implements the Distutils 'build_py' command.éN)ÚCommand)Ú*)Ú convert_path)Úlogc@sÈeZdZdZdddddgZddgZd diZd d „Zd d „Zdd„Z dd„Z dd„Z dd„Z dd„Z dd„Zdd„Zdd„Zdd„Zd d!„Zd"d#„Zd$d%„Zd2d'd(„Zd)d*„Zd+d,„Zd-d.„Zd/d0„Zd1S)3Úbuild_pyz5"build" pure Python modules (copy to build directory))z build-lib=Údzdirectory to "build" (copy) to)ÚcompileÚczcompile .py to .pyc)z no-compileNz!don't compile .py files [default])z optimize=ÚOzlalso compile with optimization: -O1 for "python -O", -O2 for "python -OO", and -O0 to disable [default: -O0])ÚforceÚfz2forcibly build everything (ignore file timestamps)rr z no-compilecCs4d|_d|_d|_d|_d|_d|_d|_d|_dS)Nr)Ú build_libÚ py_modulesÚpackageÚ package_dataÚ package_dirrÚoptimizer )Úself©rúœ/builddir/build/BUILDROOT/alt-python37-setuptools-58.3.0-4.el8.x86_64/opt/alt/python37/lib/python3.7/site-packages/setuptools/_distutils/command/build_py.pyÚinitialize_options szbuild_py.initialize_optionsc CsÊ| ddd¡|jj|_|jj|_|jj|_i|_|jjrbx&|jj ¡D]\}}t|ƒ|j|<qHW| ¡|_ t |j t ƒsÆy,t |j ƒ|_ d|j krœdks¢nt ‚Wn tt fk rÄtdƒ‚YnXdS)NÚbuild)r r )r r rézoptimize must be 0, 1, or 2)Úset_undefined_optionsÚ distributionÚpackagesrrrÚitemsrÚget_data_filesÚ data_filesÚ isinstancerÚintÚAssertionErrorÚ ValueErrorÚDistutilsOptionError)rÚnameÚpathrrrÚfinalize_options*s"       zbuild_py.finalize_optionscCs:|jr| ¡|jr$| ¡| ¡| |jdd¡dS)Nr)Úinclude_bytecode)rÚ build_modulesrÚbuild_packagesÚbuild_package_dataÚ byte_compileÚ get_outputs)rrrrÚrunCs z build_py.runcs†g}|js|Sxr|jD]h}| |¡}tjj|jg| d¡Ž}d‰|rRt|ƒd‰‡fdd„| ||¡Dƒ}|  ||||f¡qW|S)z?Generate list of '(package,src_dir,build_dir,filenames)' tuplesÚ.récsg|]}|ˆd…‘qS)Nr)Ú.0Úfile)Úplenrrú tsz+build_py.get_data_files..) rÚget_package_dirÚosr%Újoinr ÚsplitÚlenÚfind_data_filesÚappend)rÚdatarÚsrc_dirÚ build_dirÚ filenamesr)r2rras   zbuild_py.get_data_filescsh|j dg¡|j |g¡}g‰xB|D]:}t tj t |¡t|ƒ¡¡}ˆ ‡fdd„|Dƒ¡q&WˆS)z6Return filenames for package's data files in 'src_dir'Úcs$g|]}|ˆkrtj |¡r|‘qSr)r5r%Úisfile)r0Úfn)Úfilesrrr3‚s z,build_py.find_data_files..) rÚgetÚglobr5r%r6ÚescaperÚextend)rrr<ZglobsÚpatternÚfilelistr)rBrr9ys  zbuild_py.find_data_filescCshd}x^|jD]T\}}}}xF|D]>}tj ||¡}| tj |¡¡|jtj ||¡|ddqWq WdS)z$Copy data files into build directoryNF)Ú preserve_mode)rr5r%r6ÚmkpathÚdirnameÚ copy_file)rZlastdirrr<r=r>ÚfilenameÚtargetrrrr*†s zbuild_py.build_package_datacCsÄ| d¡}|js&|r tjj|ŽSdSnšg}x”|rŠy|jd |¡}Wn*tk rn| d|d¡|d=Yq,X| d|¡tjj|ŽSq,W|j d¡}|dk r¬| d|¡|r¼tjj|ŽSdSdS)z½Return the directory, relative to the top of the source distribution, where package 'package' should be found (at least according to the 'package_dir' option, if any).r.r?réÿÿÿÿN)r7rr5r%r6ÚKeyErrorÚinsertrC)rrr%ÚtailZpdirrrrr4s(       zbuild_py.get_package_dircCsj|dkr8tj |¡s td|ƒ‚tj |¡s8td|ƒ‚|rftj |d¡}tj |¡rZ|St d|¡dS)Nr?z%package directory '%s' does not existz>supposed package directory '%s' exists, but is not a directoryz __init__.pyz8package init file '%s' not found (or not a regular file)) r5r%ÚexistsÚDistutilsFileErrorÚisdirr6r@rÚwarn)rrrÚinit_pyrrrÚ check_package·s    zbuild_py.check_packagecCs&tj |¡st d||¡dSdSdS)Nz!file %s (for module %s) not foundFT)r5r%r@rrV)rÚmoduleÚ module_filerrrÚ check_moduleÒs zbuild_py.check_modulec Cs˜| ||¡t tj t |¡d¡¡}g}tj |jj¡}xX|D]P}tj |¡}||kr‚tj  tj  |¡¡d}|  |||f¡q@|  d|¡q@W|S)Nz*.pyrz excluding %s) rXrDr5r%r6rEÚabspathrÚ script_nameÚsplitextÚbasenamer:Ú debug_print) rrrZ module_filesÚmodulesZ setup_scriptr Zabs_frYrrrÚfind_package_modulesÙs   zbuild_py.find_package_modulesc CsÔi}g}xÆ|jD]¼}| d¡}d |dd…¡}|d}y||\}}Wn"tk rj| |¡}d}YnX|sœ| ||¡} |df||<| rœ| |d| f¡tj ||d¡} |  || ¡s¼q| ||| f¡qW|S)aÈFinds individually-specified Python modules, ie. those listed by module name in 'self.py_modules'. Returns a list of tuples (package, module_base, filename): 'package' is a tuple of the path through package-space to the module; 'module_base' is the bare (no packages, no dots) module name, and 'filename' is the path to the ".py" file (relative to the distribution root) that implements the module. r.rrOr/Ú__init__z.py) rr7r6rPr4rXr:r5r%r[) rrrarYr%rZ module_baserÚcheckedrWrZrrrÚ find_modulesès*       zbuild_py.find_modulescCsRg}|jr| | ¡¡|jrNx.|jD]$}| |¡}| ||¡}| |¡q&W|S)a4Compute the list of all modules that will be built, whether they are specified one-module-at-a-time ('self.py_modules') or by whole packages ('self.packages'). Return a list of tuples (package, module, module_file), just like 'find_modules()' and 'find_package_modules()' do.)rrFrerr4rb)rrarrÚmrrrÚfind_all_moduless   zbuild_py.find_all_modulescCsdd„| ¡DƒS)NcSsg|] }|d‘qS)rOr)r0rYrrrr3-sz-build_py.get_source_files..)rg)rrrrÚget_source_files,szbuild_py.get_source_filescCs$|gt|ƒ|dg}tjj|ŽS)Nz.py)Úlistr5r%r6)rr=rrYZ outfile_pathrrrÚget_module_outfile/szbuild_py.get_module_outfiler/cCsž| ¡}g}xx|D]p\}}}| d¡}| |j||¡}| |¡|r|jr`| tjj|dd¡|j dkr| tjj||j d¡qW|dd„|j Dƒ7}|S)Nr.r?)Ú optimizationrcSs,g|]$\}}}}|D]}tj ||¡‘qqSr)r5r%r6)r0rr<r=r>rMrrrr3Cs z(build_py.get_outputs..) rgr7rjr r:rÚ importlibÚutilÚcache_from_sourcerr)rr'raÚoutputsrrYrZrMrrrr,3s"       zbuild_py.get_outputscCsbt|tƒr| d¡}nt|ttfƒs,tdƒ‚| |j||¡}tj   |¡}|  |¡|j ||ddS)Nr.z:'package' must be a string (dot-separated), list, or tupler)rI) rÚstrr7riÚtupleÚ TypeErrorrjr r5r%rKrJrL)rrYrZrÚoutfileÚdirrrrÚ build_moduleJs    zbuild_py.build_modulecCs.| ¡}x |D]\}}}| |||¡qWdS)N)reru)rrarrYrZrrrr(Yszbuild_py.build_modulescCsXxR|jD]H}| |¡}| ||¡}x,|D]$\}}}||ks>t‚| |||¡q(WqWdS)N)rr4rbr!ru)rrrraZpackage_rYrZrrrr)bs    zbuild_py.build_packagescCs€tjr| d¡dSddlm}|j}|dtjkr>|tj}|jrZ||d|j ||j d|j dkr||||j |j ||j ddS)Nz%byte-compiling is disabled, skipping.r)r+rO)rr ÚprefixÚdry_run) ÚsysÚdont_write_bytecoderVÚdistutils.utilr+r r5Úseprr rwr)rrBr+rvrrrr+vs    zbuild_py.byte_compileN)r/)Ú__name__Ú __module__Ú __qualname__Ú descriptionÚ user_optionsÚboolean_optionsÚ negative_optrr&r-rr9r*r4rXr[rbrergrhrjr,rur(r)r+rrrrrs6   '4  r)Ú__doc__r5Úimportlib.utilrlrxrDÚdistutils.corerÚdistutils.errorsrzrÚ distutilsrrrrrrÚs