o
    Zh                     @   s   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dZ	 eZG dd deZdS )zRdistutils.command.build_scripts

Implements the Distutils 'build_scripts' command.    N)	sysconfig)log)ST_MODE)ClassVar   )newer)Command)convert_pathz^#!.*python[0-9.]*([ 	].*)?$c                   @   s   e Zd ZU dZg dZeeeeeef   e	d< dgZ
dd Zdd Zd	d
 Zdd Zdd Zdd Zdd Zdd Zedd ZdS )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                 C   s   d | _ d | _d | _d | _d S N)	build_dirscriptsr   
executableself r   b/var/www/html/lang_env/lib/python3.10/site-packages/setuptools/_distutils/command/build_scripts.pyinitialize_options%   s   
z build_scripts.initialize_optionsc                 C   s   |  dddd | jj| _d S )Nbuild)r
   r   )r   r   )r   r   )Zset_undefined_optionsdistributionr   r   r   r   r   finalize_options+   s   zbuild_scripts.finalize_optionsc                 C   s   | j S r   )r   r   r   r   r   get_source_files4   s   zbuild_scripts.get_source_filesc                 C   s   | j sd S |   d S r   )r   copy_scriptsr   r   r   r   run7   s   zbuild_scripts.runc                 C   s@   |  | j g }g }| jD ]	}| ||| q| | ||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.
        )Zmkpathr   r   _copy_script_change_modes)r   outfilesupdated_filesscriptr   r   r   r   <   s   	

zbuild_scripts.copy_scriptsc              	   C   s  d }t |}tj| jtj|}|| | js't||s't	
d| d S zt|}W n ty=   | js9 d }Y nw | }|sN| | d d S t|}|| |rt	d|| j | jstjsl| j}ntjtddtdtd}|dpd	}	d
| |	 d }
| |
|j t|d|jd}||
 ||  W d    n1 sw   Y  |r|  d S d S |r|  |  || d S )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OSErrordry_runreadlinewarnshebang_patternmatchinfor   python_buildr   get_config_varformatgroup_validate_shebangr+   write
writelines	readlinesclose	copy_file)r   r#   r!   r"   Zshebang_matchoutfiler   
first_liner   post_interpshebangoutfr   r   r   r   O   sZ   



zbuild_scripts._copy_scriptc                 C   s&   t jdkrd S |D ]}| | q	d S )Nposix)r,   name_change_mode)r   r!   filer   r   r   r       s
   
zbuild_scripts._change_modesc                 C   s`   | j rtd| d S t|t d@ }|dB d@ }||kr.td||| t|| d S d S )Nzchanging mode of %si  im  z!changing mode of %s from %o to %o)r5   r   r:   r,   statr   chmod)r   rM   ZoldmodeZnewmoder   r   r   rL      s   zbuild_scripts._change_modec              	   C   sd   z|  d W n ty   td| dw z|  | W d S  ty1   td| d| dw )Nzutf-8zThe shebang (z) is not encodable to utf-8z+) is not encodable to the script encoding ())encodeUnicodeEncodeError
ValueError)rH   r+   r   r   r   r?      s   zbuild_scripts._validate_shebangN)__name__
__module____qualname__descriptionr   r   listtuplestr__annotations__Zboolean_optionsr   r   r   r   r   r   r    rL   staticmethodr?   r   r   r   r   r
      s   
 "	5r
   )__doc__r,   rer2   	distutilsr   Zdistutils._logr   rN   r   typingr   Z	_modifiedr   corer   utilr	   compiler8   Zfirst_line_rer
   r   r   r   r   <module>   s    
