a „oe™@ã@sldZddlZddlZddlZddlZddlmZddlm Z m Z ddl m Z ddl mZGdd „d eƒZdS) zHdistutils.command.build_py Implements the Distutils 'build_py' command.éNé)ÚCommand)ÚDistutilsOptionErrorÚDistutilsFileError)Ú convert_path)Úlogc@sÂeZdZdZgd¢ZddgZddiZdd„Zdd „Zd d „Z d d „Z dd„Z dd„Z dd„Z dd„Zdd„Zdd„Zdd„Zdd„Zdd„Zd d!„Zd.d#d$„Zd%d&„Zd'd(„Zd)d*„Zd+d,„Zd-S)/Úbuild_pyz5"build" pure Python modules (copy to build directory)))z build-lib=Údzdirectory to "build" (copy) to)ÚcompileÚczcompile .py to .pyc)ú 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)r rr cCs4d|_d|_d|_d|_d|_d|_d|_d|_dS)Nr)Ú build_libÚ py_modulesÚpackageÚ package_dataÚ package_dirr Úoptimizer©Úself©rúGC:\Program Files\Certbot\pkgs\setuptools\_distutils\command\build_py.pyÚinitialize_options#szbuild_py.initialize_optionsc CsÄ| ddd¡|jj|_|jj|_|jj|_i|_|jjr^|jj ¡D]\}}t|ƒ|j|<qF| ¡|_ t |j t ƒsÀz,t |j ƒ|_ d|j kr˜dksžnJ‚Wnt tfy¾tdƒ‚Yn0dS)NÚbuild)rr)rrrrzoptimize must be 0, 1, or 2)Zset_undefined_optionsÚ distributionÚpackagesrrrÚitemsrÚget_data_filesÚ data_filesÚ isinstancerÚintÚ ValueErrorÚAssertionErrorr)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_outputsrrrrÚrunFs z build_py.runcs‚g}|js|S|jD]h}| |¡}tjj|jg| d¡Ž}d‰|rPt|ƒd‰‡fdd„| ||¡Dƒ}|  ||||f¡q|S)z?Generate list of '(package,src_dir,build_dir,filenames)' tuplesÚ.récsg|]}|ˆd…‘qS©Nr)Ú.0Úfile©ÚplenrrÚ vóz+build_py.get_data_files..) rÚget_package_dirÚosr&ÚjoinrÚsplitÚlenÚfind_data_filesÚappend)rÚdatarÚsrc_dirÚ build_dirÚ filenamesrr4rrds   zbuild_py.get_data_filescsd|j dg¡|j |g¡}g‰|D]:}t tj t |¡t|ƒ¡¡}ˆ ‡fdd„|Dƒ¡q$ˆS)z6Return filenames for package's data files in 'src_dir'Úcs$g|]}|ˆvrtj |¡r|‘qSr)r9r&Úisfile)r2Úfn©Úfilesrrr6…r7z,build_py.find_data_files..) rÚgetÚglobr9r&r:ÚescaperÚextend)rrr@ZglobsÚpatternZfilelistrrFrr=zsÿÿzbuild_py.find_data_filescCs\|jD]P\}}}}|D]>}tj ||¡}| tj |¡¡|jtj ||¡|dd�qqdS)z$Copy data files into build directoryF©Z preserve_modeN)r r9r&r:ÚmkpathÚdirnameÚ copy_file)rrr@rArBÚfilenameÚtargetrrrr+‰sÿzbuild_py.build_package_datacCs¾| d¡}|js&|r tjj|ŽSdSn”g}|r†z|jd |¡}Wn(tyj| d|d¡|d=Yq*0| d|¡tjj|ŽSq*|j d¡}|dur¦| 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/rCréÿÿÿÿN)r;rr9r&r:ÚKeyErrorÚinsertrH)rrr&ÚtailZpdirrrrr8“s(        zbuild_py.get_package_dircCs^|dkr8tj |¡s td|ƒ‚tj |¡s8td|ƒ‚|rZtj |d¡}tj |¡rZ|SdS)NrCz%package directory '%s' does not existz>supposed package directory '%s' exists, but is not a directoryz __init__.py)r9r&ÚexistsrÚisdirr:rD)rrrÚinit_pyrrrÚ check_packageºs  ÿ ÿÿ zbuild_py.check_packagecCs&tj |¡st d||¡dSdSdS)Nz!file %s (for module %s) not foundFT)r9r&rDrZwarning)rÚmoduleÚ module_filerrrÚ check_moduleÔs zbuild_py.check_modulec Cs”| ||¡t tj t |¡d¡¡}g}tj |jj¡}|D]P}tj |¡}||kr€tj  tj  |¡¡d}|  |||f¡q>|  d|¡q>|S)Nz*.pyrz excluding %s) rZrIr9r&r:rJÚabspathrÚ script_nameÚsplitextÚbasenamer>Z debug_print) rrrZ module_filesÚmodulesZ setup_scriptrZabs_fr[rrrÚfind_package_modulesÛs  zbuild_py.find_package_modulesc CsÎi}g}|jD]º}| d¡}d |dd…¡}|d}z||\}}Wn tyf| |¡}d}Yn0|s˜| ||¡} |df||<| r˜| |d| f¡tj ||d¡} |  || ¡s¸q| ||| f¡q|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/rrSr0Ú__init__ú.py) rr;r:rTr8rZr>r9r&r]) rrrbr[r&rZ module_baserÚcheckedrYr\rrrÚ find_modulesês*        zbuild_py.find_modulescCsNg}|jr| | ¡¡|jrJ|jD]$}| |¡}| ||¡}| |¡q$|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.)rrKrgrr8rc)rrbrrÚmrrrÚfind_all_moduless    zbuild_py.find_all_modulescCsdd„| ¡DƒS)NcSsg|] }|d‘qS)rSr)r2r[rrrr6/r7z-build_py.get_source_files..)rirrrrÚget_source_files.szbuild_py.get_source_filescCs$|gt|ƒ|dg}tjj|ŽS)Nre)Úlistr9r&r:)rrArr[Z outfile_pathrrrÚget_module_outfile1szbuild_py.get_module_outfiler0cCsš| ¡}g}|D]p\}}}| d¡}| |j||¡}| |¡|r|jr^| tjj|dd�¡|j dkr| tjj||j d�¡q|dd„|j Dƒ7}|S)Nr/rC)Ú optimizationrcSs,g|]$\}}}}|D]}tj ||¡‘qqSr)r9r&r:)r2rr@rArBrQrrrr6Hs þz(build_py.get_outputs..) rir;rlrr>r Ú importlibÚutilÚcache_from_sourcerr )rr(rbZoutputsrr[r\rQrrrr-5s*  ÿ ÿÿþzbuild_py.get_outputscCsbt|tƒr| d¡}nt|ttfƒs,tdƒ‚| |j||¡}tj   |¡}|  |¡|j ||dd�S)Nr/z:'package' must be a string (dot-separated), list, or tuplerrM) r!Ústrr;rkÚtupleÚ TypeErrorrlrr9r&rOrNrP)rr[r\rZoutfileÚdirrrrÚ build_modulePs  ÿ  zbuild_py.build_modulecCs*| ¡}|D]\}}}| |||¡q dSr1)rgru)rrbrr[r\rrrr)`szbuild_py.build_modulescCsP|jD]D}| |¡}| ||¡}|D]$\}}}||ks:J‚| |||¡q$qdSr1)rr8rcru)rrrrbZpackage_r[r\rrrr*is    zbuild_py.build_packagescCs€tjr| d¡dSddlm}|j}|dtjkr>|tj}|jrZ||d|j ||j d�|j dkr||||j |j ||j d�dS)Nz%byte-compiling is disabled, skipping.r)r,rSr)rrÚprefixÚdry_run) ÚsysÚdont_write_bytecodeÚwarnror,rr9Úsepr rrwr)rrGr,rvrrrr,}s&   ÿ ûzbuild_py.byte_compileN)r0)Ú__name__Ú __module__Ú __qualname__Ú descriptionZ user_optionsZboolean_optionsZ negative_optrr'r.rr=r+r8rZr]rcrgrirjrlr-rur)r*r,rrrrrs.   '4  r)Ú__doc__r9Úimportlib.utilrnrxrIZcorerÚerrorsrrrorZdistutils._logrrrrrrÚs