�`^c@s�dZdZddlZddlZddlmZddlmZddlmZm Z ddl
mZddlm
Z
d efd
��YZdS(sHdistutils.command.build_py
Implements the Distutils 'build_py' command.s$Id$i�N(tglob(tCommand(tDistutilsOptionErrortDistutilsFileError(tconvert_path(tlogtbuild_pycBs�eZdZd#d$d&d'd(gZddgZidd6Zd�Zd�Zd�Z d�Z
d�Zd�Zd�Z
d�Zd�Zd�Zd�Zd�Zd�Zd�Zdd�Zd�Zd �Zd!�Zd"�ZRS()s5"build" pure Python modules (copy to build directory)s
build-lib=tdsdirectory to "build" (copy) totcompiletcscompile .py to .pycs
no-compiles!don't compile .py files [default]s optimize=tOslalso compile with optimization: -O1 for "python -O", -O2 for "python -OO", and -O0 to disable [default: -O0]tforcetfs2forcibly build everything (ignore file timestamps)cCsLd|_d|_d|_d|_d|_d|_d|_d|_dS(Ni( tNonet build_libt
py_modulestpackagetpackage_datatpackage_dirRtoptimizeR(tself((s0/sys/lib/python2.7/distutils/command/build_py.pytinitialize_options!s cCs|jddd�|jj|_|jj|_|jj|_i|_|jjr�x6|jjj�D]\}}t|�|j|<qhWn|j�|_ t
|jt�sy;t|j�|_d|jko�dkns�
�Wqtt
fk
rtd��qXndS( NtbuildRRiisoptimize must be 0, 1, or 2(s build_libs build_lib(sforcesforce(tset_undefined_optionstdistributiontpackagesRRRtitemsRtget_data_filest
data_filest
isinstanceRtinttAssertionErrort
ValueErrorR(Rtnametpath((s0/sys/lib/python2.7/distutils/command/build_py.pytfinalize_options+s" )cCsS|jr|j�n|jr6|j�|j�n|j|jdd��dS(Ntinclude_bytecodei(Rt
build_modulesRtbuild_packagestbuild_package_datatbyte_compiletget_outputs(R((s0/sys/lib/python2.7/distutils/command/build_py.pytrunDs
cCs�g}|js|Sx�|jD]�}|j|�}tjj|jg|jd��}d}|rvt|�d}ng|j||�D]}||^q�}|j ||||f�qW|S(s?Generate list of '(package,src_dir,build_dir,filenames)' tuplest.ii(
Rtget_package_dirtosR"tjoinRtsplittlentfind_data_filestappend(RtdataRtsrc_dirt build_dirtplentfilet filenames((s0/sys/lib/python2.7/distutils/command/build_py.pyRbs %)cCs�|jjdg�|jj|g�}g}xm|D]e}ttjj|t|���}|jg|D]*}||kritjj|�ri|^qi�q5W|S(s6Return filenames for package's data files in 'src_dir't( RtgetRR-R"R.Rtextendtisfile(RRR4tglobstfilestpatterntfilelisttfn((s0/sys/lib/python2.7/distutils/command/build_py.pyR1zs
!#cCs�x�|jD]v\}}}}xa|D]Y}tjj||�}|jtjj|��|jtjj||�|dt�q#Wq
WdS(s$Copy data files into build directoryt
preserve_modeN(RR-R"R.tmkpathtdirnamet copy_filetFalse(RRR4R5R8tfilenamettarget((s0/sys/lib/python2.7/distutils/command/build_py.pyR'�s
cCs|jd�}|js5|r.tjj|�SdSn�g}x�|r�y|jdj|�}Wn,tk
r�|jd|d�|d=q>X|jd|�tjj|�Sq>W|jjd�}|dk r�jd|�n|r�jj|�SdSdS(s�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+R9ii�N( R/RR-R"R.tKeyErrortinsertR:R
(RRR"ttailtpdir((s0/sys/lib/python2.7/distutils/command/build_py.pyR,�s(
cCs�|dkrYtjj|�s1td|��ntjj|�sYtd|��qYn|r�tjj|d�}tjj|�r�|Stjdd|�ndS(NR9s%package directory '%s' does not exists>supposed package directory '%s' exists, but is not a directorys__init__.pys!package init file '%s' not found s(or not a regular file)(
R-R"texistsRtisdirR.R<RtwarnR
(RRRtinit_py((s0/sys/lib/python2.7/distutils/command/build_py.pyt
check_package�s cCs1tjj|�s)tjd||�tStSdS(Ns!file %s (for module %s) not found(R-R"R<RRORFtTrue(Rtmoduletmodule_file((s0/sys/lib/python2.7/distutils/command/build_py.pytcheck_module�sc Cs�|j||�ttjj|d��}g}tjj|jj�}xx|D]p}tjj|�}||kr�tjjtjj |��d}|j
|||f�qP|jd|�qPW|S(Ns*.pyisexcluding %s(RQRR-R"R.tabspathRtscript_nametsplitexttbasenameR2tdebug_print( RRRtmodule_filestmodulestsetup_scriptRtabs_fRS((s0/sys/lib/python2.7/distutils/command/build_py.pytfind_package_modules�s
"cCs!i}g}x|jD]}|jd�}dj|dd!�}|d}y||\}}Wn&tk
r�|j|�}d}nX|s�|j||�} |df||<| r�|j|d| f�q�ntjj||d�}
|j ||
�sqn|j|||
f�qW|S(s�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+ii�it__init__s.py(
RR/R.RIR,RQR2R-R"RU(RRR\RSR"Rtmodule_baseRtcheckedRPRT((s0/sys/lib/python2.7/distutils/command/build_py.pytfind_modules�s*
cCswg}|jr%|j|j��n|jrsxB|jD]4}|j|�}|j||�}|j|�q8Wn|S(s4Compute 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.(RR;RcRR,R_(RR\RRtm((s0/sys/lib/python2.7/distutils/command/build_py.pytfind_all_moduless cCs!g|j�D]}|d^q
S(Ni�(Re(RRS((s0/sys/lib/python2.7/distutils/command/build_py.pytget_source_files-scCs.|gt|�|dg}tjj|�S(Ns.py(tlistR-R"R.(RR5RRStoutfile_path((s0/sys/lib/python2.7/distutils/command/build_py.pytget_module_outfile0sicCs�|j�}g}x�|D]�\}}}|jd�}|j|j||�}|j|�|r|jr|j|d�n|jdkr�|j|d�q�qqW|g|jD]4\}}} }
|
D]}tj j
| |�^q�q�7}|S(NR+R ito(ReR/RiRR2RRRR-R"R.(RR$R\toutputsRRSRTRGR4R5R8((s0/sys/lib/python2.7/distutils/command/build_py.pyR)4s
)cCs�t|t�r!|jd�}n$t|ttf�sEtd��n|j|j||�}tj j
|�}|j|�|j||dd�S(NR+s:'package' must be a string (dot-separated), list, or tupleRBi(
RtstrR/Rgttuplet TypeErrorRiRR-R"RDRCRE(RRSRTRtoutfiletdir((s0/sys/lib/python2.7/distutils/command/build_py.pytbuild_moduleIs
cCs=|j�}x*|D]"\}}}|j|||�qWdS(N(RcRq(RR\RRSRT((s0/sys/lib/python2.7/distutils/command/build_py.pyR%XscCsxxq|jD]f}|j|�}|j||�}x<|D]4\}}}||ksYt�|j|||�q8Wq
WdS(N(RR,R_RRq(RRRR\tpackage_RSRT((s0/sys/lib/python2.7/distutils/command/build_py.pyR&bsc
Cs�tjr|jd�dSddlm}|j}|dtjkrV|tj}n|jr�||ddd|j d|d|j
�n|jdkr�||d|jd|j d|d|j
�ndS( Ns%byte-compiling is disabled, skipping.i�(R(RiRtprefixtdry_run(tsystdont_write_bytecodeROtdistutils.utilR(RR-tsepRRRtR(RR>R(Rs((s0/sys/lib/python2.7/distutils/command/build_py.pyR(ws
(s
build-lib=Rsdirectory to "build" (copy) to(scompileR scompile .py to .pycN(s
no-compileNs!don't compile .py files [default](s optimize=R
slalso compile with optimization: -O1 for "python -O", -O2 for "python -OO", and -O0 to disable [default: -O0](sforceRs2forcibly build everything (ignore file timestamps)(t__name__t
__module__tdescriptionR
tuser_optionstboolean_optionstnegative_optRR#R*RR1R'R,RQRUR_RcReRfRiR)RqR%R&R((((s0/sys/lib/python2.7/distutils/command/build_py.pyRs8
( 4
(t__doc__t__revision__R-RuRtdistutils.coreRtdistutils.errorsRRRwRt distutilsRR(((s0/sys/lib/python2.7/distutils/command/build_py.pyt<module>s
|