
    ZQd&C                         d Z ddlZddlZddlZddlZddlmZ ddlT ddl	m
Z
mZ ddlmZ  G d de          Z G d	 d
ee          ZdS )zHdistutils.command.build_py

Implements the Distutils 'build_py' command.    N)Command)*)convert_path	Mixin2to3)logc                       e Zd ZdZg dZddgZddiZd Zd Zd Z	d	 Z
d
 Zd Zd Zd Zd Zd Zd Zd Zd Zd ZddZd Zd Zd Zd ZdS )build_pyz5"build" pure Python modules (copy to build directory)))z
build-lib=dzdirectory to "build" (copy) to)compileczcompile .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])forcefz2forcibly build everything (ignore file timestamps)r   r   r   c                 v    d | _         d | _        d | _        d | _        d | _        d| _        d| _        d | _        d S )Nr   )	build_lib
py_modulespackagepackage_datapackage_dirr   optimizer   selfs    1/usr/lib/python3.11/distutils/command/build_py.pyinitialize_optionszbuild_py.initialize_options    s@     


    c                 H   |                      ddd           | j        j        | _        | j        j        | _        | j        j        | _        i | _        | j        j        r;| j        j                                        D ]\  }}t          |          | j        |<   |                                 | _	        t          | j        t                    sV	 t          | j                  | _        d| j        cxk    rdk    sn J d S # t          t          f$ r t          d          w xY wd S )Nbuild)r   r   )r   r   r      zoptimize must be 0, 1, or 2)set_undefined_optionsdistributionpackagesr   r   r   itemsr   get_data_files
data_files
isinstancer   int
ValueErrorAssertionErrorDistutilsOptionError)r   namepaths      r   finalize_optionszbuild_py.finalize_options*   sL   ""7#=#5	7 	7 	7 )2+6 -:( 	<"/;AACC < <
d)5d);); &&--// $--- 	JJ #DM 2 2DM....Q......../ J J J*+HIIIJ		J 	Js   /C> >!Dc                     | j         r|                                  | j        r(|                                  |                                  |                     |                     d                     d S Nr   )include_bytecode)r   build_modulesr"   build_packagesbuild_package_databyte_compileget_outputsr   s    r   runzbuild_py.runC   sy    , ? 	!   = 	&!!!##%%%$**A*>>?????r   c                 \   g }| j         s|S | j         D ]}|                     |          }t          j        j        | j        g|                    d          z    }d|rt          |          dz   fd|                     ||          D             }|	                    ||||f           |S )z?Generate list of '(package,src_dir,build_dir,filenames)' tuples.r      c                 $    g | ]}|d          S N ).0fileplens     r   
<listcomp>z+build_py.get_data_files.<locals>.<listcomp>s   s.        $TUU  r   )
r"   get_package_dirosr,   joinr   splitlenfind_data_filesappend)r   datar   src_dir	build_dir	filenamesr?   s         @r   r$   zbuild_py.get_data_filesa   s    } 	K} 	B 	BG**733G '7'--:L:L'LNI D &7||A~   (,(<(<Wg(N(N  I KK'9i@AAAAr   c           	      h   | j                             dg           | j                             |g           z   }g |D ]t}t          j        t          j                            t          j        |          t          |                              }                    fd|D                        uS )z6Return filenames for package's data files in 'src_dir' c                 Z    g | ]'}|vt           j                            |          %|(S r<   )rB   r,   isfile)r=   fnfiless     r   r@   z,build_py.find_data_files.<locals>.<listcomp>   s;     ( ( (2U??GNN2&& 4C"???r   )	r   getglobrB   r,   rC   escaper   extend)r   r   rI   globspatternfilelistrQ   s         @r   rF   zbuild_py.find_data_filesy   s    "&&r2..$(("556 	) 	)Gydk'.B.BLQXDYDY!Z!Z[[HLL ( ( ( (x ( ( ( ) ) ) )r   c                 B   d}| j         D ]\  }}}}|D ]}t          j                            ||          }|                     t          j                            |                     |                     t          j                            ||          |d           dS )z$Copy data files into build directoryNFpreserve_mode)r%   rB   r,   rC   mkpathdirname	copy_file)r   lastdirr   rI   rJ   rK   filenametargets           r   r3   zbuild_py.build_package_data   s    6:o 	4 	42GWi% 4 4i::BGOOF33444rw||GX>>-2  4 4 4 44	4 	4r   c                    |                     d          }| j        s|rt          j        j        | S dS g }|r{	 | j        d                    |                   }|                    d|           t          j        j        | S # t          $ r" |                    d|d                    |d= Y nw xY w|{| j                            d          }||                    d|           |rt          j        j        | S dS )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).r8   rM   r   )rD   r   rB   r,   rC   insertKeyErrorrR   )r   r   r,   tailpdirs        r   rA   zbuild_py.get_package_dir   s"    }}S!! 	 w|T**rD /+CHHTNN;D
 KK4(((7<..   ! ! !KK48,,,R!  " '++B//#KK4((( 7<..2s    B )B.-B.c                    |dk    rbt           j                            |          st          d|z            t           j                            |          st          d|z            |rVt           j                            |d          }t           j                            |          r|S t          j        d|           d S )NrM   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))	rB   r,   existsDistutilsFileErrorisdirrC   rO   r   warn)r   r   r   init_pys       r   check_packagezbuild_py.check_package   s    
 "7>>+.. M(=KM M M7==-- ?(02=>? ? ?
  	?gll;>>Gw~~g&& ? 46=? ? ?
 tr   c                 t    t           j                            |          st          j        d||           dS dS )Nz!file %s (for module %s) not foundFT)rB   r,   rO   r   rl   )r   modulemodule_files      r   check_modulezbuild_py.check_module   s7    w~~k** 	H8+vNNN54r   c                 J   |                      ||           t          j        t          j                            t          j        |          d                    }g }t          j                            | j        j                  }|D ]}t          j                            |          }||k    r[t          j        	                    t          j        
                    |                    d         }|                    |||f           |                     d|z             |S )Nz*.pyr   zexcluding %s)rn   rS   rB   r,   rC   rT   abspathr!   script_namesplitextbasenamerG   debug_print)	r   r   r   module_filesmodulessetup_scriptr   abs_frp   s	            r   find_package_moduleszbuild_py.find_package_modules   s    7K000ydk+.F.F!O!OPPwt'8'DEE 	@ 	@AGOOA&&E$$))"'*:*:1*=*=>>qA34444  ,!>????r   c                    i }g }| j         D ]}|                    d          }d                    |dd                   }|d         }	 ||         \  }}n'# t          $ r |                     |          }d}Y nw xY w|s7|                     ||          }	|df||<   |	r|                    |d|	f           t          j                            ||dz             }
| 	                    ||
          s|                    |||
f           |S )a  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.
        r8   r   rc   r9   __init__.py)
r   rD   rC   re   rA   rn   rG   rB   r,   rr   )r   r"   rz   rp   r,   r   module_baser   checkedrm   rq   s              r   find_moduleszbuild_py.find_modules   sN      o 	@ 	@F<<$$DhhtAbDz**Gr(K)1'):&gg   "227;;  C,,WkBB%0!$4! CNNGZ#ABBB
 ',,{K%4GHHK$$V[99 NNG[+>????s   	A!A98A9c                    g }| j         r'|                    |                                            | j        rJ| j        D ]B}|                     |          }|                     ||          }|                    |           C|S )a4  Compute 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.)r   rU   r   r"   rA   r}   )r   rz   r   r   ms        r   find_all_moduleszbuild_py.find_all_modules  s     ? 	0NN4,,..///= 	"= " ""227;;--g{CCq!!!!r   c                 >    d |                                  D             S )Nc                     g | ]
}|d          S )rc   r<   )r=   rp   s     r   r@   z-build_py.get_source_files.<locals>.<listcomp>-  s    AAAvr
AAAr   )r   r   s    r   get_source_fileszbuild_py.get_source_files,  s"    AA)>)>)@)@AAAAr   c                 \    |gt          |          z   |dz   gz   }t          j        j        | S )Nr   )listrB   r,   rC   )r   rJ   r   rp   outfile_paths        r   get_module_outfilezbuild_py.get_module_outfile/  s/    !{T']]2fun5EEw|\**r   r9   c                    |                                  }g }|D ]\  }}}|                    d          }|                     | j        ||          }|                    |           |r| j        r4|                    t          j                            |d                     | j	        dk    r9|                    t          j                            || j	                             |d | j
        D             z  }|S )Nr8   rM   )optimizationr   c                 b    g | ],\  }}}}|D ]"}t           j                            ||          #-S r<   )rB   r,   rC   )r=   r   rI   rJ   rK   r`   s         r   r@   z(build_py.get_outputs.<locals>.<listcomp>B  sW       6)Y%   GLLH--   r   )r   rD   r   r   rG   r   	importlibutilcache_from_sourcer   r%   )r   r0   rz   outputsr   rp   rq   r`   s           r   r5   zbuild_py.get_outputs3  s'   '')).5 
	? 
	?*WfkmmC((G..t~wOOHNN8$$$ ?< 4NN9>#C#C r $D $3 $3 4 4 4=1$$NN9>#C#C t} $D $> $> ? ? ? 	  :>/   	 r   c                 ~   t          |t                    r|                    d          }n+t          |t          t          f          st          d          |                     | j        ||          }t          j	        
                    |          }|                     |           |                     ||d          S )Nr8   z:'package' must be a string (dot-separated), list, or tupler   rZ   )r&   strrD   r   tuple	TypeErrorr   r   rB   r,   r]   r\   r^   )r   rp   rq   r   outfiledirs         r   build_modulezbuild_py.build_moduleJ  s    gs## 	PmmC((GGGdE]33 	PNP P P ))$.'6JJgoog&&C~~k7!~DDDr   c                 n    |                                  }|D ]\  }}}|                     |||           d S r;   )r   r   )r   rz   r   rp   rq   s        r   r1   zbuild_py.build_modulesY  sP    ##%%.5 	< 	<*Wfk
 fk7;;;;	< 	<r   c                     | j         D ]U}|                     |          }|                     ||          }|D ]%\  }}}||k    sJ |                     |||           &Vd S r;   )r"   rA   r}   r   )r   r   r   rz   package_rp   rq   s          r   r2   zbuild_py.build_packagesb  s    } 	@ 	@G ..w77K//EEG 4; @ @/6;(****!!&+w????@	@ 	@r   c                 J   t           j        r|                     d           d S ddlm} | j        }|d         t          j        k    r|t          j        z   }| j        r ||d| j	        || j
                   | j        dk    r! ||| j        | j	        || j
                   d S d S )Nz%byte-compiling is disabled, skipping.r   )r4   rc   )r   r   prefixdry_run)sysdont_write_bytecoderl   distutils.utilr4   r   rB   sepr   r   r   r   )r   rQ   r4   r   s       r   r4   zbuild_py.byte_compilev  s    " 	II=>>>F//////":bf_F
 < 	PL#z&$,P P P P=1L#z&$,P P P P P P r   N)r9   )__name__
__module____qualname__descriptionuser_optionsboolean_optionsnegative_optr   r-   r6   r$   rF   r3   rA   rn   rr   r}   r   r   r   r   r5   r   r1   r2   r4   r<   r   r   r	   r	      sx       KK
 
 
L !'*O 9-L  J J J2@ @ @<  0  4 4 4% % %N  6    2 2 2h   B B B+ + +   .E E E< < <@ @ @(P P P P Pr   r	   c                       e Zd Zd Zd ZdS )build_py_2to3c                 .   g | _         | j        r|                                  | j        r(|                                  |                                  |                     | j                    |                     |                     d                     d S r/   )	updated_filesr   r1   r"   r2   r3   run_2to3r4   r5   r   s    r   r6   zbuild_py_2to3.run  s     ? 	!   = 	&!!!##%%% 	d())) 	$**A*>>?????r   c                     t                               | |||          }|d         r | j                            |d                    |S )Nr9   r   )r	   r   r   rG   )r   rp   rq   r   ress        r   r   zbuild_py_2to3.build_module  sG    ##D&+wGGq6 	.%%c!f---
r   N)r   r   r   r6   r   r<   r   r   r   r     s5        @ @ @     r   r   )__doc__rB   importlib.utilr   r   rS   distutils.corer   distutils.errorsr   r   r   	distutilsr   r	   r   r<   r   r   <module>r      s   0 0 
			     



  " " " " " "     2 2 2 2 2 2 2 2      yP yP yP yP yP yP yP yPv    Hi     r   