
     f@                     z    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m	Z	m
Z
 ddlmZ ddlmZ  G d d	e          ZdS )
zHdistutils.command.build_py

Implements the Distutils 'build_py' command.    N   )Command)DistutilsOptionErrorDistutilsFileError)convert_path)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    i/var/www/api.educacionweb.es/myenv/lib/python3.11/site-packages/setuptools/_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   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AssertionErrorr   )r   namepaths      r   finalize_optionszbuild_py.finalize_options.   sM   ""/1C	
 	
 	
 )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.runG   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>w   s!    XXXdeeXXXr   )
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_filese   s    } 	K} 	B 	BG**733G '7'--:L:L'LNI D (7||a' YXXX1E1Egw1W1WXXXI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:   )r@   r+   isfile)r;   fnfiless     r   r>   z,build_py.find_data_files.<locals>.<listcomp>   s0    QQQ"E//bgnnR>P>P////r   )	r   getglobr@   r+   rA   escaper   extend)r   r   rG   globspatternfilelistrO   s         @r   rD   zbuild_py.find_data_files{   s    !%%b"--0A0E0Egr0R0RR 	 	GyT[11<3H3HII H LLQQQQhQQQ    r   c                 >   | j         D ]\  }}}}|D ]}t          j                            ||          }|                     t          j                            |                     |                     t          j                            ||          |d           dS )z$Copy data files into build directoryFpreserve_modeN)r%   r@   r+   rA   mkpathdirname	copy_file)r   r   rG   rH   rI   filenametargets          r   r1   zbuild_py.build_package_data   s    6:o 	 	2GWi%  i::BGOOF33444GLL(33V5     	 	r   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).r6   rK   r   )rB   r   r@   r+   rA   insertKeyErrorrP   )r   r   r+   tailpdirs        r   r?   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            |rAt           j                            |d          }t           j                            |          r|S d S )NrK   z%package directory '%s' does not existz>supposed package directory '%s' exists, but is not a directoryz__init__.py)r@   r+   existsr   isdirrA   rM   )r   r   r   init_pys       r   check_packagezbuild_py.check_package   s    
 "7>>+.. (;kI   7==-- (-/:;    	gll;>>Gw~~g&&  tr   c                 t    t           j                            |          st          j        d||           dS dS )Nz!file %s (for module %s) not foundFT)r@   r+   rM   r   warning)r   modulemodule_files      r   check_modulezbuild_py.check_module   s7    w~~k** 	K;[&QQQ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)ri   rQ   r@   r+   rA   rR   abspathr!   script_namesplitextbasenamerE   debug_print)	r   r   r   module_filesmodulessetup_scriptr   abs_frl   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.
        r6   r   r`   r7   __init__.py)
r   rB   rA   rb   r?   ri   rE   r@   r+   rn   )r   r"   rv   rl   r+   r   module_baser   checkedrh   rm   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   rS   r   r"   r?   ry   )r   rv   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 )r`   r:   )r;   rl   s     r   r>   z-build_py.get_source_files.<locals>.<listcomp>0  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|   )listr@   r+   rA   )r   rH   r   rl   outfile_paths        r   get_module_outfilezbuild_py.get_module_outfile2  s/    !{T']]2fun5EEw|\**r   r7   c                    |                                  }g }|D ]\  }}}|                    d          }|                     | j        ||          }|                    |           |r| j        r4|                    t          j                            |d                     | j	        dk    r9|                    t          j                            || j	                             |d | j
        D             z  }|S )Nr6   rK   )optimizationr   c                 b    g | ],\  }}}}|D ]"}t           j                            ||          #-S r:   )r@   r+   rA   )r;   r   rG   rH   rI   r]   s         r   r>   z(build_py.get_outputs.<locals>.<listcomp>I  sW     
 
 
6)Y%
 
  GLLH--
 
 
 
r   )r   rB   r   r   rE   r   	importlibutilcache_from_sourcer   r%   )r   r.   rv   outputsr   rl   rm   r]   s           r   r3   zbuild_py.get_outputs6  s#   '')).5 	 	*WfkmmC((G..t~wOOHNN8$$$ 
< NN!88PR8SS   =1$$NN!88$4= 9     	 
 
:>/
 
 
 	
 r   c                 ~   t          |t                    r|                    d          }n+t          |t          t          f          st          d          |                     | j        ||          }t          j	        
                    |          }|                     |           |                     ||d          S )Nr6   z:'package' must be a string (dot-separated), list, or tupler   rX   )r&   strrB   r   tuple	TypeErrorr   r   r@   r+   r[   rZ   r\   )r   rl   rm   r   outfiledirs         r   build_modulezbuild_py.build_moduleQ  s    gs## 	mmC((GGGdE]33 	L   ))$.'6JJgoog&&C~~k7!~DDDr   c                 n    |                                  }|D ]\  }}}|                     |||           d S r9   )r   r   )r   rv   r   rl   rm   s        r   r/   zbuild_py.build_modulesa  sP    ##%%.5 	< 	<*Wfk
 fk7;;;;	< 	<r   c                     | j         D ]U}|                     |          }|                     ||          }|D ]%\  }}}||k    sJ |                     |||           &Vd S r9   )r"   r?   ry   r   )r   r   r   rv   package_rl   rm   s          r   r0   zbuild_py.build_packagesj  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   )r2   r`   r   )r   r   prefixdry_run)sysdont_write_bytecodewarnr   r2   r   r@   sepr   r   r   r   )r   rO   r2   r   s       r   r2   zbuild_py.byte_compile~  s    " 	II=>>>F''''''":bf_F
 < 	LFDL    =1Lj      r   N)r7   )__name__
__module____qualname__descriptionuser_optionsboolean_optionsnegative_optr   r,   r4   r$   rD   r1   r?   ri   rn   ry   r   r   r   r   r3   r   r/   r0   r2   r:   r   r   r
   r
      ss       KK  L !'*O ),L  J J J2@ @ @<  ,    % % %N  4    2 2 2h   B B B+ + +   6E E E < < <@ @ @(    r   r
   )__doc__r@   importlib.utilr   r   rQ   corer   errorsr   r   r   r   distutils._logr   r
   r:   r   r   <module>r      s   0 0 
			     



        = = = = = = = =            G G G G Gw G G G G Gr   