a oe@@sldZddlZddlZddlZddlZddlmZddlm Z m Z ddl m Z ddl mZGdd d eZdS) zHdistutils.command.build_py Implements the Distutils 'build_py' command.N)Command)DistutilsOptionErrorDistutilsFileError) convert_path)logc@seZdZdZgdZddgZddiZddZdd Zd d Z d d Z ddZ ddZ ddZ ddZddZddZddZddZddZd 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)compileczcompile .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])forcefz2forcibly build everything (ignore file timestamps)r rr cCs4d|_d|_d|_d|_d|_d|_d|_d|_dS)Nr) build_lib py_modulespackage package_data package_dirr optimizerselfrGC:\Program Files\Certbot\pkgs\setuptools\_distutils\command\build_py.pyinitialize_options#szbuild_py.initialize_optionsc Cs|ddd|jj|_|jj|_|jj|_i|_|jjr^|jjD]\}}t||j|<qF||_ t |j t sz,t |j |_ d|j krdksnJWnt tfytdYn0dS)Nbuild)rr)rrrrzoptimize must be 0, 1, or 2)Zset_undefined_options distributionpackagesrrritemsrget_data_files data_files isinstancerint ValueErrorAssertionErrorr)rnamepathrrrfinalize_options-s"       zbuild_py.finalize_optionscCs:|jr||jr$||||jdddS)Nr)include_bytecode)r build_modulesrbuild_packagesbuild_package_data byte_compile get_outputsrrrrrunFs z build_py.runcsg}|js|S|jD]h}||}tjj|jg|d}d|rPt|dfdd|||D}| ||||fq|S)z?Generate list of '(package,src_dir,build_dir,filenames)' tuples.rcsg|]}|dqSNr).0fileplenrr vz+build_py.get_data_files..) rget_package_dirosr&joinrsplitlenfind_data_filesappend)rdatarsrc_dir build_dir filenamesrr4rrds   zbuild_py.get_data_filescsd|jdg|j|g}g|D]:}ttjt|t|}fdd|Dq$S)z6Return filenames for package's data files in 'src_dir'cs$g|]}|vrtj|r|qSr)r9r&isfile)r2fnfilesrrr6r7z,build_py.find_data_files..) rgetglobr9r&r:escaperextend)rrr@ZglobspatternZfilelistrrFrr=zszbuild_py.find_data_filescCs\|jD]P\}}}}|D]>}tj||}|tj||jtj|||ddqqdS)z$Copy data files into build directoryFZ preserve_modeN)r r9r&r:mkpathdirname copy_file)rrr@rArBfilenametargetrrrr+szbuild_py.build_package_datacCs|d}|js&|r tjj|SdSng}|rz|jd|}Wn(tyj|d|d|d=Yq*0|d|tjj|Sq*|jd}|dur|d||rtjj|SdSdS)zReturn 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/rCrN)r;rr9r&r:KeyErrorinsertrH)rrr&tailZpdirrrrr8s(        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&existsrisdirr:rD)rrrinit_pyrrr check_packages    zbuild_py.check_packagecCs&tj|std||dSdSdS)Nz!file %s (for module %s) not foundFT)r9r&rDrZwarning)rmodule module_filerrr check_modules zbuild_py.check_modulec Cs|||ttjt|d}g}tj|jj}|D]P}tj|}||krtj tj |d}| |||fq>| d|q>|S)Nz*.pyrz excluding %s) rZrIr9r&r:rJabspathr script_namesplitextbasenamer>Z debug_print) rrrZ module_filesmodulesZ setup_scriptrZabs_fr[rrrfind_package_moduless  zbuild_py.find_package_modulesc Csi}g}|jD]}|d}d|dd}|d}z||\}}Wn tyf||}d}Yn0|s|||} |df||<| r||d| ftj||d} | || sq|||| fq|S)aFinds 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_basercheckedrYr\rrr find_moduless*        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)rrbrrmrrrfind_all_moduless    zbuild_py.find_all_modulescCsdd|DS)NcSsg|] }|dqS)rSr)r2r[rrrr6/r7z-build_py.get_source_files..)rirrrrget_source_files.szbuild_py.get_source_filescCs$|gt||dg}tjj|S)Nre)listr9r&r:)rrArr[Z outfile_pathrrrget_module_outfile1szbuild_py.get_module_outfiler0cCs|}g}|D]p\}}}|d}||j||}|||r|jr^|tjj|dd|j dkr|tjj||j dq|dd|j D7}|S)Nr/rC) optimizationrcSs,g|]$\}}}}|D]}tj||qqSr)r9r&r:)r2rr@rArBrQrrrr6Hs z(build_py.get_outputs..) rir;rlrr>r importlibutilcache_from_sourcerr )rr(rbZoutputsrr[r\rQrrrr-5s*   zbuild_py.get_outputscCsbt|tr|d}nt|ttfs,td||j||}tj |}| ||j ||ddS)Nr/z:'package' must be a string (dot-separated), list, or tuplerrM) r!strr;rktuple TypeErrorrlrr9r&rOrNrP)rr[r\rZoutfiledirrrr 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_packagescCstjr|ddSddlm}|j}|dtjkr>|tj}|jrZ||d|j ||j d|j dkr||||j |j ||j ddS)Nz%byte-compiling is disabled, skipping.r)r,rSr)rrprefixdry_run) sysdont_write_bytecodewarnror,rr9sepr 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__r9importlib.utilrnrxrIZcorererrorsrrrorZdistutils._logrrrrrrs