o )ao@@sddZddlZddlZddlZddlZddlmZddlTddl m Z ddl m Z GdddeZ dS) zHdistutils.command.build_py Implements the Distutils 'build_py' command.N)Command)*) 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)rr r cCs4d|_d|_d|_d|_d|_d|_d|_d|_dS)Nr) build_lib py_modulespackage package_data package_dirroptimizer selfrY/opt/alt/python310/lib/python3.10/site-packages/setuptools/_distutils/command/build_py.pyinitialize_options s zbuild_py.initialize_optionsc Cs|ddd|jj|_|jj|_|jj|_i|_|jjr/|jjD] \}}t||j|<q#||_ t |j t s`zt |j |_ d|j krMdksPJJWdSt tfy_tdwdS)NZbuild)rr)r r rzoptimize must be 0, 1, or 2)Zset_undefined_options distributionpackagesrrritemsrget_data_files data_files isinstancerint ValueErrorAssertionErrorZDistutilsOptionError)rnamepathrrrfinalize_options*s(      $zbuild_py.finalize_optionscCs:|jr||jr||||jdddS)Nr)include_bytecode)r build_modulesrbuild_packagesbuild_package_data byte_compile get_outputsrrrrrunCs z build_py.runcsg}|js|S|jD]4}||}tjj|jg|d}d|r(t|dfdd|||D}| ||||fq |S)z?Generate list of '(package,src_dir,build_dir,filenames)' tuples.rcsg|]}|dqSNr).0fileZplenrr ss z+build_py.get_data_files..) rget_package_dirosr$joinrsplitlenfind_data_filesappend)rdatarsrc_dir build_dir filenamesrr2rras     zbuild_py.get_data_filescsd|jdg|j|g}g|D]}ttjt|t|}fdd|DqS)z6Return filenames for package's data files in 'src_dir'cs$g|]}|vrtj|r|qSr)r5r$isfile)r0fnfilesrrr3s  z,build_py.find_data_files..) rgetglobr5r$r6escaperextend)rrr<ZglobspatternZfilelistrrBrr9ys  zbuild_py.find_data_filescCs`d}|jD](\}}}}|D]}tj||}|tj||jtj|||ddq qdS)z$Copy data files into build directoryNFZ preserve_mode)rr5r$r6mkpathdirname copy_file)rZlastdirrr<r=r>filenametargetrrrr)szbuild_py.build_package_datacCs|d}|js|rtjj|SdSg}|rCz |jd|}Wnty4|d|d|d=Yn w|d|tjj|S|s|jd}|durS|d||r[tjj|SdS)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-r?rN)r7rr5r$r6KeyErrorinsertrD)rrr$tailZpdirrrrr4s,         zbuild_py.get_package_dircCsj|dkrtj|std|tj|std||r3tj|d}tj|r-|Std|dS)Nr?z%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)) r5r$existsZDistutilsFileErrorisdirr6r@rwarn)rrrinit_pyrrr check_packages&   zbuild_py.check_packagecCs"tj|std||dSdS)Nz!file %s (for module %s) not foundFT)r5r$r@rrU)rmodule module_filerrr check_modules zbuild_py.check_modulec Cs|||ttjt|d}g}tj|jj}|D](}tj|}||kr@tj tj |d}| |||fq| d|q|S)Nz*.pyrz excluding %s) rWrEr5r$r6rFabspathrZ script_namesplitextbasenamer:Z debug_print) rrrZ module_filesmodulesZ setup_scriptr Zabs_frXrrrfind_package_moduless  zbuild_py.find_package_modulesc Csi}g}|jD]]}|d}d|dd}|d}z||\}}Wnty3||}d}Ynw|sL|||} |df||<| rL||d| ftj||d} | || s\q|||| 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-rrOr.__init__.py) rr7r6rPr4rWr:r5r$rZ) rrr^rXr$rZ module_basercheckedrVrYrrr find_moduless,       zbuild_py.find_modulescCsNg}|jr |||jr%|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.)rrGrcrr4r_)rr^rrmrrrfind_all_moduless    zbuild_py.find_all_modulescCsdd|DS)NcSsg|]}|dqS)rOr)r0rXrrrr3-sz-build_py.get_source_files..)rerrrrget_source_files,szbuild_py.get_source_filescCs$|gt||dg}tjj|S)Nra)listr5r$r6)rr=rrXZ outfile_pathrrrget_module_outfile/s zbuild_py.get_module_outfiler.cCs|}g}|D]8\}}}|d}||j||}|||r@|jr/|tjj|dd|j dkr@|tjj||j dq|dd|j D7}|S)Nr-r?) optimizationrcSs,g|]\}}}}|D] }tj||q qSr)r5r$r6)r0rr<r=r>rMrrrr3Bs  z(build_py.get_outputs..) rer7rhrr:r importlibutilcache_from_sourcerr)rr&r^ZoutputsrrXrYrMrrrr+3s(     zbuild_py.get_outputscCsbt|tr |d}n t|ttfstd||j||}tj |}| ||j ||ddS)Nr-z:'package' must be a string (dot-separated), list, or tuplerrI) rstrr7rgtuple TypeErrorrhrr5r$rKrJrL)rrXrYrZoutfiledirrrr build_moduleJs    zbuild_py.build_modulecCs*|}|D] \}}}||||qdSr/)rcrq)rr^rrXrYrrrr'Yszbuild_py.build_modulescCsP|jD]"}||}|||}|D]\}}}||ksJ||||qqdSr/)rr4r_rq)rrrr^Zpackage_rXrYrrrr(bs   zbuild_py.build_packagescCstjr |ddSddlm}|j}|dtjkr|tj}|jr-||d|j ||j d|j dkr@|||j |j ||j ddSdS)Nz%byte-compiling is disabled, skipping.r)r*rO)rr prefixdry_run) sysdont_write_bytecoderUdistutils.utilr*rr5seprr rsr)rrCr*rrrrrr*vs        zbuild_py.byte_compileN)r.)__name__ __module__ __qualname__ descriptionZ user_optionsZboolean_optionsZ negative_optrr%r,rr9r)r4rWrZr_rcrerfrhr+rqr'r(r*rrrrrs0    '4  r)__doc__r5importlib.utilrjrtrEZdistutils.corerZdistutils.errorsrvrZ distutilsrrrrrrs