[ C@sdZddlZddlZddlZddlmZddlmZddlTddl m Z m Z ddl m Z Gdd d eZGd d d ee ZdS) zHdistutils.command.build_py Implements the Distutils 'build_py' command.N)glob)Command)*) convert_path Mixin2to3)logc@s+eZdZdZd8d9d:d;d<gZddgZidd6ZddZddZddZ ddZ ddZ ddZ ddZ dd Zd!d"Zd#d$Zd%d&Zd'd(Zd)d*Zd+d,Zd-d.d/Zd0d1Zd2d3Zd4d5Zd6d7Zd S)=build_pyz5"build" pure Python modules (copy to build directory) build-lib=ddirectory to "build" (copy) tocompileccompile .py to .pyc no-compileN!don't compile .py files [default] optimize=Olalso compile with optimization: -O1 for "python -O", -O2 for "python -OO", and -O0 to disable [default: -O0]forcef2forcibly build everything (ignore file timestamps)cCsLd|_d|_d|_d|_d|_d|_d|_d|_dS)Nr) build_lib py_modulespackage package_data package_dirr optimizer)selfr0/usr/lib/python3.4/distutils/command/build_py.pyinitialize_options s       zbuild_py.initialize_optionsc Cs|jddd|jj|_|jj|_|jj|_i|_|jjrx6|jjjD]\}}t||j|ts z+build_py.get_data_files..) r%get_package_dirosr.joinrsplitlenfind_data_filesappend)rdatarsrc_dir build_dir filenamesr)r;rr'as %%zbuild_py.get_data_filescs|jjdg|jj|g}gxO|D]G}ttjj|t|}jfdd|Dq5WS)z6Return filenames for package's data files in 'src_dir'cs4g|]*}|krtjj|r|qSr)r>r.isfile)r9fn)filesrrr<s z,build_py.find_data_files..)rgetrr>r.r?rextend)rrrEZglobspatternZfilelistr)rKrrBys !$zbuild_py.find_data_filescCsd}x|jD]v\}}}}xa|D]Y}tjj||}|jtjj||jtjj|||ddq)WqWdS)z$Copy data files into build directoryN preserve_modeF)r(r>r.r?mkpathdirname copy_file)rZlastdirrrErFrGfilenametargetrrrr3s zbuild_py.build_package_datac Cs|jd}|js5|r.tjj|SdSng}x|ry|jdj|}Wn-tk r|jd|d|d=Yq>X|jd|tjj|Sq>W|jjd}|dk r|jd|n|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).r7rHrr8NrU)r@rr>r.r?KeyErrorinsertrL)rrr.tailZpdirrrrr=s(      zbuild_py.get_package_dircCs|dkrYtjj|s1td|ntjj|sYtd|qYn|rtjj|d}tjj|r|Stjdd|ndS)NrHz%package directory '%s' does not existz>supposed package directory '%s' exists, but is not a directoryz __init__.pyz!package init file '%s' not found z(or not a regular file)) r>r.existsZDistutilsFileErrorisdirr?rIrwarn)rrrinit_pyrrr check_packages  zbuild_py.check_packagecCs1tjj|s)tjd||dSdSdS)Nz!file %s (for module %s) not foundFT)r>r.rIrr[)rmodule module_filerrr check_moduleszbuild_py.check_modulec Cs|j||ttjj|d}g}tjj|jj}xx|D]p}tjj|}||krtjjtjj |d}|j |||fqP|j d|qPW|S)Nz*.pyrz excluding %s) r]rr>r.r?abspathr$Z script_namesplitextbasenamerCZ debug_print) rrrZ module_filesmodulesZ setup_scriptrZabs_fr^rrrfind_package_moduless  "zbuild_py.find_package_modulesc Cs%i}g}x|jD]}|jd}dj|dd}|d}y||\}}Wn'tk r|j|}d}YnX|s|j||} |df||<| r|j|d| fqntjj||d} |j || sqn|j||| fqW|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. r7rr8__init__z.pyrUrU) rr@r?rVr=r]rCr>r.r`) rr%rdr^r.rZ module_baserZcheckedr\r_rrr find_moduless*   zbuild_py.find_modulescCswg}|jr%|j|jn|jrsxB|jD]4}|j|}|j||}|j|q8Wn|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.)rrMrgr%r=re)rrdrrmrrrfind_all_moduless  zbuild_py.find_all_modulescCsdd|jDS)NcSsg|]}|dqS)r8rUr)r9r^rrrr<-s z-build_py.get_source_files..)ri)rrrrget_source_files,szbuild_py.get_source_filescCs.|gt||dg}tjj|S)Nz.py)listr>r.r?)rrFrr^Z outfile_pathrrrget_module_outfile/szbuild_py.get_module_outfiler8cCs|j}g}x|D]\}}}|jd}|j|j||}|j||r|jr|jtjj|ddn|j dkr|jtjj|ddqqqW|dd|j D7}|S)Nr7debug_overrideTrFcSs>g|]4\}}}}|D]}tjj||qqSr)r>r.r?)r9rrErFrGrSrrrr<Cs z(build_py.get_outputs..) rir@rlrrCr importlibutilcache_from_sourcerr()rr0rdZoutputsrr^r_rSrrrr53s"    zbuild_py.get_outputscCst|tr!|jd}n$t|ttfsEtdn|j|j||}tj j |}|j ||j ||ddS)Nr7z:'package' must be a string (dot-separated), list, or tuplerOr) r)strr@rktuple TypeErrorrlrr>r.rQrPrR)rr^r_rZoutfiledirrrr build_moduleJs  zbuild_py.build_modulecCs=|j}x*|D]"\}}}|j|||qWdS)N)rgru)rrdrr^r_rrrr1Ys zbuild_py.build_modulescCsxxq|jD]f}|j|}|j||}x<|D]4\}}}||ksYt|j|||q8Wq WdS)N)r%r=rer+ru)rrrrdZpackage_r^r_rrrr2bs  zbuild_py.build_packagesc Cstjr|jddSddlm}|j}|d tjkrV|tj}n|jr||ddd|j d|d|j n|j dkr||d|j d|j d|d|j ndS) Nz%byte-compiling is disabled, skipping.r)r4r8rrprefixdry_runrU) sysdont_write_bytecoder[distutils.utilr4rr>sepr rrwr)rrKr4rvrrrr4vs    zbuild_py.byte_compile)r r r )zcompiler r)rNr)rrr)zforcerr)__name__ __module__ __qualname__Z descriptionZ user_optionsZboolean_optionsZ negative_optr r/r6r'rBr3r=r]r`rergrirjrlr5rur1r2r4rrrrrs8        '    4     rc@s(eZdZddZddZdS) build_py_2to3cCslg|_|jr|jn|jr?|j|jn|j|j|j|jdddS)Nr0r) updated_filesrr1r%r2r3Zrun_2to3r4r5)rrrrr6s      zbuild_py_2to3.runcCs=tj||||}|dr9|jj|dn|S)Nr8r)rrurrC)rr^r_rZresrrrrus zbuild_py_2to3.build_moduleN)r|r}r~r6rurrrrrs  r)__doc__r>importlib.utilrnrxrZdistutils.corerZdistutils.errorsrzrrZ distutilsrrrrrrrs    |