U +a&C@szdZddlZddlZddlZddlZddlmZddlTddl m Z m Z ddl m Z GdddeZGd d d ee ZdS) zHdistutils.command.build_py Implements the Distutils 'build_py' command.N)Command)*) convert_path Mixin2to3)logc@seZdZdZdddddgZddgZd diZd d Zd d ZddZ ddZ ddZ ddZ ddZ ddZddZddZddZd d!Zd"d#Zd$d%Zd2d'd(Zd)d*Zd+d,Zd-d.Zd/d0Zd1S)3build_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 r r cCs4d|_d|_d|_d|_d|_d|_d|_d|_dS)Nr) build_lib py_modulespackage package_data package_dirr optimizer selfrN/tmp/pip-install-1bd_1mtk/setuptools/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 krdksnt Wn tt fk rtdYnXdS)Nbuild)rr)r r rzoptimize must be 0, 1, or 2)set_undefined_options distributionpackagesrrritemsrget_data_files data_files isinstancerintAssertionError ValueErrorDistutilsOptionError)rnamepathrrrfinalize_options*s$       zbuild_py.finalize_optionscCs:|jr||jr$||||jdddSNr)include_bytecode)r build_modulesrbuild_packagesbuild_package_data byte_compile get_outputsrrrrrunCs 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 ssz+build_py.get_data_files..) rget_package_dirosr(joinrsplitlenfind_data_filesappend)rdatarsrc_dir build_dir filenamesrr7rr as     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|]}|krtj|r|qSr)r;r(isfile)r5fnfilesrrr9s z,build_py.find_data_files..) rgetglobr;r(r<escaperextend)rrrBZglobspatternfilelistrrHrr?ys  zbuild_py.find_data_filescCs`d}|jD]P\}}}}|D]>}tj||}|tj||jtj|||ddqq dS)z$Copy data files into build directoryNF preserve_mode)r!r;r(r<mkpathdirname copy_file)rZlastdirrrBrCrDfilenametargetrrrr.szbuild_py.build_package_datacCs|d}|js&|r tjj|SdSng}|rz|jd|}Wn*tk rl|d|d|d=Yq*X|d|tjj|Sq*|jd}|dk r|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).r2rErN)r=rr;r(r<KeyErrorinsertrJ)rrr(tailZpdirrrrr:s(       zbuild_py.get_package_dircCsj|dkr8tj|s td|tj|s8td||rftj|d}tj|rZ|Std|dS)NrEz%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)) r;r(existsDistutilsFileErrorisdirr<rFrwarn)rrrinit_pyrrr check_packages&   zbuild_py.check_packagecCs&tj|std||dSdSdS)Nz!file %s (for module %s) not foundFT)r;r(rFrr^)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) r`rKr;r(r<rLabspathr script_namesplitextbasenamer@ debug_print) rrrZ module_filesmodulesZ setup_scriptrZabs_frarrrfind_package_moduless  zbuild_py.find_package_modulesc Csi}g}|jD]}|d}d|dd}|d}z||\}}Wn"tk rh||}d}YnX|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. r2rrWr3__init__.py) rr=r<rXr:r`r@r;r(rc) rrrirar(rZ module_basercheckedr_rbrrr 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.)rrMrnrr:rj)rrirrmrrrfind_all_moduless    zbuild_py.find_all_modulescCsdd|DS)NcSsg|] }|dqS)rWr)r5rarrrr9-sz-build_py.get_source_files..)rprrrrget_source_files,szbuild_py.get_source_filescCs$|gt||dg}tjj|S)Nrl)listr;r(r<)rrCrraZ outfile_pathrrrget_module_outfile/szbuild_py.get_module_outfiler3cCs|}g}|D]p\}}}|d}||j||}|||r|jr^|tjj|dd|j dkr|tjj||j dq|dd|j D7}|S)Nr2rE) optimizationrcSs,g|]$\}}}}|D]}tj||qqSr)r;r(r<)r5rrBrCrDrUrrrr9Bs z(build_py.get_outputs..) rpr=rsrr@r importlibutilcache_from_sourcerr!)rr+rioutputsrrarbrUrrrr03s*      zbuild_py.get_outputscCsbt|tr|d}nt|ttfs,td||j||}tj |}| ||j ||ddS)Nr2z:'package' must be a string (dot-separated), list, or tuplerrP) r"strr=rrtuple TypeErrorrsrr;r(rSrRrT)rrarbroutfiledirrrr build_moduleJs    zbuild_py.build_modulecCs*|}|D]\}}}||||q dSr4)rnr~)rrirrarbrrrr,Yszbuild_py.build_modulescCsP|jD]D}||}|||}|D]$\}}}||ks:t||||q$qdSr4)rr:rjr$r~)rrrriZpackage_rarbrrrr-bs    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/rW)rr prefixdry_run) sysdont_write_bytecoder^distutils.utilr/rr;sepr r rr)rrIr/rrrrr/vs&    zbuild_py.byte_compileN)r3)__name__ __module__ __qualname__ description user_optionsboolean_options negative_optrr)r1r r?r.r:r`rcrjrnrprqrsr0r~r,r-r/rrrrrs8    '4  rc@seZdZddZddZdS) build_py_2to3cCsLg|_|jr||jr*||||j||jdddSr*) updated_filesrr,rr-r.run_2to3r/r0rrrrr1s zbuild_py_2to3.runcCs,t||||}|dr(|j|d|S)Nr3r)rr~rr@)rrarbrresrrrr~szbuild_py_2to3.build_moduleN)rrrr1r~rrrrrsr)__doc__r;importlib.utilrurrKdistutils.corerdistutils.errorsrrr distutilsrrrrrrrs  }