
    ?wg                         d 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	 ddl
mZ ddlmZ dd	lmZ dd
lmZ  ej$                  d      Z	 eZ G d de      Zy)zRdistutils.command.build_scripts

Implements the Distutils 'build_scripts' command.    N)	sysconfig)log)ST_MODE)ClassVar   )newer)Command)convert_pathz^#!.*python[0-9.]*([ 	].*)?$c                       e Zd ZU dZg dZeeeeeef         e	d<   dgZ
d Zd Zd Zd Zd	 Zd
 Zd Zd Zed        Zy)build_scriptsz("build" scripts (copy and fixup #! line)))z
build-dir=dzdirectory to "build" (copy) to)forcefz1forcibly build everything (ignore file timestamps)zexecutable=ez*specify final destination interpreter pathuser_optionsr   c                 <    d | _         d | _        d | _        d | _        y N)	build_dirscriptsr   
executableselfs    b/var/www/horilla/myenv/lib/python3.12/site-packages/setuptools/_distutils/command/build_scripts.pyinitialize_optionsz build_scripts.initialize_options%   s    
    c                 b    | j                  dddd       | j                  j                  | _        y )Nbuild)r   r   )r   r   )r   r   )set_undefined_optionsdistributionr   r   s    r   finalize_optionszbuild_scripts.finalize_options+   s1    ""*(		
 ((00r   c                     | j                   S r   )r   r   s    r   get_source_fileszbuild_scripts.get_source_files4   s    ||r   c                 >    | j                   sy | j                          y r   )r   copy_scriptsr   s    r   runzbuild_scripts.run7   s    ||r   c                     | j                  | j                         g }g }| j                  D ]  }| j                  |||        | j	                  |       ||fS )a2  
        Copy each script listed in ``self.scripts``.

        If a script is marked as a Python script (first line matches
        'shebang_pattern', i.e. starts with ``#!`` and contains
        "python"), then adjust in the copy the first line to refer to
        the current Python interpreter.
        )mkpathr   r   _copy_script_change_modes)r   outfilesupdated_filesscripts       r   r$   zbuild_scripts.copy_scripts<   s^     	DNN#ll 	?Ffh>	? 	8$&&r   c           	      @   d }t        |      }t        j                  j                  | j                  t        j                  j                  |            }|j                  |       | j                  s#t        ||      st        j                  d|       y 	 t        j                  |      }|j                         }|s| j                  | d       y t        j!                  |      }|j                  |       |rUt        j&                  d|| j                         | j$                  st(        j*                  s| j,                  }nit        j                  j                  t)        j.                  d      dj1                  t)        j.                  d      t)        j.                  d                  }|j3                  d      xs d	}	d
|z   |	z   dz   }
| j5                  |
|j6                         t        |d|j6                        5 }|j9                  |
       |j;                  |j=                                d d d        |r|j?                          y y |r|j?                          | jA                  ||       y # t"        $ r | j$                  s d }Y w xY w# 1 sw Y   axY w)Nznot copying %s (up-to-date)z is an empty file (skipping)zcopying and adjusting %s -> %sBINDIRz
python{}{}VERSIONEXE    z#!
w)encoding)!r
   ospathjoinr   basenameappendr   r   r   debugtokenizeopenreadlinewarnshebang_patternmatchOSErrordry_runinfor   python_buildr   get_config_varformatgroup_validate_shebangr5   write
writelines	readlinesclose	copy_file)r   r,   r*   r+   shebang_matchoutfiler   
first_liner   post_interpshebangoutfs               r   r(   zbuild_scripts._copy_scriptO   s   f%'',,t~~rww/?/?/GH zz%"8II3V<	>f%A J		VH$@AB+11*=MW%HH5vt~~N<< --!%J!#!00:$++%44Y?%44U;"J ,11!4:+k9D@&&w

;'3< 3JJw'OOAKKM23 	  	NN67+K  	<<A	:3 3s   I5 1J5JJJc                 \    t         j                  dk7  ry |D ]  }| j                  |        y )Nposix)r6   name_change_mode)r   r*   files      r   r)   zbuild_scripts._change_modes   s.    77g 	$Dd#	$r   c                     | j                   rt        j                  d|       y t        j                  |      t
           dz  }|dz  dz  }||k7  r/t        j                  d|||       t        j                  ||       y y )Nzchanging mode of %si  im  z!changing mode of %s from %o to %o)rC   r   rD   r6   statr   chmod)r   rY   oldmodenewmodes       r   rX   zbuild_scripts._change_mode   sn    <<HH*D1''$-(61U?f,gHH8$QHHT7# r   c                     	 | j                  d       	 | j                  |       y # t        $ r t        d| d      w xY w# t        $ r t        d| d| d      w xY w)Nzutf-8zThe shebang (z) is not encodable to utf-8z+) is not encodable to the script encoding ())encodeUnicodeEncodeError
ValueError)rS   r5   s     r   rI   zbuild_scripts._validate_shebang   s    	UNN7#	NN8$ " 	U}WK7RSTT	U " 	{ +++3*A7 	s   & A ?AN)__name__
__module____qualname__descriptionr   r   listtuplestr__annotations__boolean_optionsr   r    r"   r%   r$   r(   r)   rX   staticmethodrI    r   r   r   r      sp    >K:L(4c3m 456  iO1
'&3,j$	$  r   r   )__doc__r6   rer<   	distutilsr   distutils._logr   r[   r   typingr   	_modifiedr   corer	   utilr
   compiler@   first_line_rer   rn   r   r   <module>ry      sU   5 
 	        "**<=
  QG Qr   