
    ?wg@                     r    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	 ddl
mZmZ ddlmZ  G d d	e	      Zy)
zHdistutils.command.build_py

Implements the Distutils 'build_py' command.    N)log   )Command)DistutilsFileErrorDistutilsOptionError)convert_pathc                       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y)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                 t    d | _         d | _        d | _        d | _        d | _        d| _        d| _        d | _        y )NFr   )	build_lib
py_modulespackagepackage_datapackage_dirr   optimizer   selfs    ]/var/www/horilla/myenv/lib/python3.12/site-packages/setuptools/_distutils/command/build_py.pyinitialize_optionszbuild_py.initialize_options#   s<     
    c                    | j                  ddd       | j                  j                  | _        | j                  j                  | _        | j                  j                  | _        i | _        | j                  j
                  rD| j                  j
                  j                         D ]  \  }}t        |      | j
                  |<    | j                         | _	        t        | j                  t              s6	 t        | j                        | _        d| j                  cxk  rdk  sJ  J y y # t        t        f$ r t        d      w xY w)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-   s%   ""/1C	
 ))22++66 --::(("//;;AAC <
d)5d);  &<--/ $---J #DMM 2DMM.Q..... . / J*+HIIJs   64D, ,Ec                     | j                   r| j                          | j                  r | j                          | j	                          | j                  | j                  d             y )NF)include_bytecode)r   build_modulesr"   build_packagesbuild_package_databyte_compileget_outputsr   s    r   runzbuild_py.runF   sR    , ?? ==!##%$**E*BCr   c                 x   g }| j                   s|S | j                   D ]  }| j                  |      }t        j                  j                  | j
                  g|j                  d      z    }d}|rt        |      dz   }| j                  ||      D cg c]  }||d 	 }}|j                  ||||f        |S c c}w )z?Generate list of '(package,src_dir,build_dir,filenames)' tuples.r      N)
r"   get_package_dirosr+   joinr   splitlenfind_data_filesappend)r   datar   src_dir	build_dirplenfile	filenamess           r   r$   zbuild_py.get_data_filesd   s    }}K}} 	BG**73G '7'--:L'LNI D7|a' 261E1Egw1WXdeXIXKK'9i@A	B  Ys   B7c           	         | j                   j                  dg       | j                   j                  |g       z   }g }|D ]  }t        j                  t        j                  j                  t        j                  |      t        |                  }|j                  |D cg c])  }||vst        j                  j                  |      s(|+ c}        |S c c}w )z6Return filenames for package's data files in 'src_dir' )
r   getglobr9   r+   r:   escaper   extendisfile)r   r   r@   globsfilespatternfilelistfns           r   r=   zbuild_py.find_data_filesz   s    !!%%b"-0A0A0E0Egr0RR 	GyyT[[1<3HIH LL%5RWW^^B=O 	 s   	C
)C
	C
c                 >   | j                   D ]  \  }}}}|D ]  }t        j                  j                  ||      }| j	                  t        j                  j                  |             | j                  t        j                  j                  ||      |d         y)z$Copy data files into build directoryFpreserve_modeN)r%   r9   r+   r:   mkpathdirname	copy_file)r   _packager@   rA   rD   filenametargets          r   r1   zbuild_py.build_package_data   s    7; 	3Hgy)% i:BGGOOF34GGLL(3V5  	r   c                    |j                  d      }| j                  s|rt        j                  j                  | S yg }|rM	 | j                  dj	                  |         }|j                  d|       t        j                  j                  | S | j                  j                  d      }||j                  d|       |rt        j                  j                  | S y# t        $ r |j                  d|d          |d= Y nw xY w|rŌy)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   rF   r   )r;   r   r9   r+   r:   insertKeyErrorrG   )r   r   r+   tailpdirs        r   r8   zbuild_py.get_package_dir   s     }}S!ww||T**D/++CHHTN;D
 KK4(77<<.. ''++B/#KK4(77<<..+   !KK48,R! s   C !D ?D c                 L   |dk7  r\t         j                  j                  |      st        d| d      t         j                  j	                  |      st        d| d      |rAt         j                  j                  |d      }t         j                  j                  |      r|S y )NrF   zpackage directory 'z' does not existzsupposed package directory 'z ' exists, but is not a directoryz__init__.py)r9   r+   existsr   isdirr:   rK   )r   r   r   init_pys       r   check_packagezbuild_py.check_package   s    
 "77>>+.()+6FG  77==-(2;- @- -  ggll;>Gww~~g& r   c                 r    t         j                  j                  |      st        j                  d||       yy)Nz!file %s (for module %s) not foundFT)r9   r+   rK   r   warning)r   modulemodule_files      r   check_modulezbuild_py.check_module   s)    ww~~k*KK;[&Qr   c                 F   | j                  ||       t        j                  t        j                  j	                  t        j
                  |      d            }g }t        j                  j                  | j                  j                        }|D ]  }t        j                  j                  |      }||k7  rTt        j                  j                  t        j                  j                  |            d   }|j                  |||f       {| j                  d|         |S )Nz*.pyr   z
excluding )rd   rH   r9   r+   r:   rI   abspathr!   script_namesplitextbasenamer>   debug_print)	r   r   r   module_filesmodulessetup_scriptr   abs_frg   s	            r   find_package_moduleszbuild_py.find_package_modules   s    7K0yydkk+.F!OPwwt'8'8'D'DE 	>AGGOOA&E$))"''*:*:1*=>qA34  :l^!<=	> r   c                    i }g }| j                   D ]  }|j                  d      }dj                  |dd       }|d   }	 ||   \  }}|s/| j                  ||      }	|df||<   |	r|j                  |d|	f       t        j                  j                  ||dz         }
| j                  ||
      s|j                  |||
f        |S # t        $ r | j	                  |      }d}Y w xY w)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[   Fr7   __init__.py)
r   r;   r:   r]   r8   rd   r>   r9   r+   ri   )r   r"   rq   rg   r+   r   module_baser   checkedrc   rh   s              r   find_moduleszbuild_py.find_modules   s      oo 	@F<<$DhhtAbz*Gr(K )1'):&g
 ,,WkB%0!$4!NNGZ#AB
 '',,{K%4GHK$$V[9NNG[+>?1	@4 '   "227; s   CC%$C%c                    g }| j                   r|j                  | j                                | j                  rE| j                  D ]6  }| j	                  |      }| j                  ||      }|j                  |       8 |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   rJ   rz   r"   r8   rt   )r   rq   r   r   ms        r   find_all_moduleszbuild_py.find_all_modules  st     ??NN4,,./==== ""227;--g{Cq!" r   c                 N    | j                         D cg c]  }|d   	 c}S c c}w )Nr[   )r}   )r   rg   s     r   get_source_fileszbuild_py.get_source_files.  s#    )-)>)>)@Avr
AAAs   "c                 f    |gt        |      z   |dz   gz   }t        j                  j                  | S )Nrw   )listr9   r+   r:   )r   rA   r   rg   outfile_paths        r   get_module_outfilezbuild_py.get_module_outfile1  s1    !{T']2fun5EEww||\**r   c                    | j                         }g }|D ]  \  }}}|j                  d      }| j                  | j                  ||      }|j	                  |       |sI| j
                  r0|j	                  t        j                  j                  |d             | j                  dkD  s|j	                  t        j                  j                  || j                                || j                  D 	
cg c].  \  }}}	}
|
D ]"  }t        j                  j                  |	|      $ 0 c}}
}	}}z  }|S c c}}
}	}}w )Nr6   rF   )optimizationr   )r}   r;   r   r   r>   r   	importlibutilcache_from_sourcer   r%   r9   r+   r:   )r   r.   rq   outputsr   rg   _module_filerX   r@   rA   rD   s              r   r3   zbuild_py.get_outputs5  s(   '')-4 	)GV\mmC(G..t~~wOHNN8$<<NN!88PR8S ==1$NN!88$4== 9 	  	:>//
 
6)Y%
  GGLLH-
-
 	
 
s   93D7c                 J   t        |t              r|j                  d      }n!t        |t        t        f      st        d      | j                  | j                  ||      }t        j                  j                  |      }| j                  |       | j                  ||d      S )Nr6   z:'package' must be a string (dot-separated), list, or tupleFrR   )r&   strr;   r   tuple	TypeErrorr   r   r9   r+   rU   rT   rV   )r   rg   rh   r   outfiledirs         r   build_modulezbuild_py.build_moduleP  s    gs#mmC(GGdE]3L  ))$..'6Jggoog&C~~k7%~HHr   c                 `    | j                         }|D ]  \  }}}| j                  |||        y N)rz   r   )r   rq   r   rg   rh   s        r   r/   zbuild_py.build_modules`  s:    ##%,3 	<(GV[
 fk7;	<r   c                     | j                   D ]J  }| j                  |      }| j                  ||      }|D ]   \  }}}||k(  sJ | j                  |||       " L y r   )r"   r8   rt   r   )r   r   r   rq   package_rg   rh   s          r   r0   zbuild_py.build_packagesi  su    }} 	@G ..w7K//EG 29 @-&+(***!!&+w?@	@r   c                    t         j                  r| j                  d       y ddlm} | j
                  }|d   t        j                  k7  r|t        j                  z   }| j                  r! ||d| j                  || j                         | j                  dkD  r, ||| j                  | j                  || j                         y y )Nz%byte-compiling is disabled, skipping.r   )r2   r[   r   )r   r   prefixdry_run)sysdont_write_bytecodewarnr   r2   r   r9   sepr   r   r   r   )r   rM   r2   r   s       r   r2   zbuild_py.byte_compile}  s    ""II=>'":bff_F
 <<FDLL ==1jj r   N)T)__name__
__module____qualname__descriptionuser_optionsboolean_optionsnegative_optr   r,   r4   r$   r=   r1   r8   rd   ri   rt   rz   r}   r   r   r3   r   r/   r0   r2    r   r   r
   r
      s    KKL !'*O ),LJ2D<,%N42h B+6I <@(r   r
   )__doc__rH   importlib.utilr   r9   r   distutils._logr   corer   errorsr   r   r   r   r
   r   r   r   <module>r      s2   0   	 
   = Fw Fr   