
    ZQdX                         d 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mZ ddlmZ ddlZ ej        d	          Z G d
 de          Z G d dee          ZdS )zRdistutils.command.build_scripts

Implements the Distutils 'build_scripts' command.    N)ST_MODE)	sysconfig)Command)newer)convert_path	Mixin2to3)logs   ^#!.*python[0-9.]*([ 	].*)?$c                   >    e Zd ZdZg dZdgZd Zd Zd Zd Z	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 pathr   c                 L    d | _         d | _        d | _        d | _        d | _        d S N)	build_dirscriptsr   
executableoutfilesselfs    6/usr/lib/python3.11/distutils/command/build_scripts.pyinitialize_optionsz build_scripts.initialize_options   s)    
    c                 X    |                      dddd           | j        j        | _        d S )Nbuild)r   r   )r   r   )r   r   )set_undefined_optionsdistributionr   r   s    r   finalize_optionszbuild_scripts.finalize_options%   s;    ""7#A#5#?	A 	A 	A (0r   c                     | j         S r   )r   r   s    r   get_source_fileszbuild_scripts.get_source_files,   s
    |r   c                 @    | j         sd S |                                  d S r   )r   copy_scriptsr   s    r   runzbuild_scripts.run/   s)    | 	Fr   c           	      R   |                      | j                   g }g }| j        D ]o}d}t          |          }t          j                            | j        t          j                            |                    }|                    |           | j	        s&t          ||          st          j        d|           	 t          |d          }t          j        |j                  \  }}|                    d           |                                }	|	s|                     d|z             
t&                              |	          }
|
rd}|
                    d          pd}n# t,          $ r | j        s d	}Y nw xY w|rt          j        d
|| j                   |                    |           | j        st2          j        s| j        }n[t          j                            t3          j        d          dt3          j        d          t3          j        d                    }t	          j        |          }d|z   |z   dz   }	 |                    d           n0# t>          $ r# tA          d!                    |                    w xY w	 |                    |           n1# t>          $ r$ tA          d!                    ||                    w xY wt          |d          5 }|"                    |           |#                    |$                                           d	d	d	           n# 1 swxY w Y   |r|%                                 .|r|%                                 |                    |           | &                    ||           qt          j'        dk    r~|D ]{}| j        rt          j        d|           t	          j(        |          tR                   dz  }|dz  dz  }||k    r,t          j        d|||           t	          j*        ||           |||fS )a"  Copy each script listed in 'self.scripts'; if it's marked as a
        Python script in the Unix way (first line matches 'first_line_re',
        ie. starts with "\#!" and contains "python"), then adjust the first
        line to refer to the current Python interpreter as we copy.
        Fznot copying %s (up-to-date)rbr   z%s is an empty file (skipping)T   r   Nzcopying and adjusting %s -> %sBINDIRpythonVERSIONEXEs   #!   
zutf-8z.The shebang ({!r}) is not decodable from utf-8zAThe shebang ({!r}) is not decodable from the script encoding ({})wbposixzchanging mode of %si  im  z!changing mode of %s from %o to %o)+mkpathr   r   r   ospathjoinbasenameappendr   r   r	   debugopentokenizedetect_encodingreadlineseekwarnfirst_line_rematchgroupOSErrordry_runinfor   python_buildr   get_config_varfsencodedecodeUnicodeDecodeError
ValueErrorformatwrite
writelines	readlinesclose	copy_filenamestatr   chmod)r   r   updated_filesscriptadjustoutfiler   encodinglines
first_liner=   post_interpr   shebangoutffileoldmodenewmodes                     r   r#   zbuild_scripts.copy_scripts5   s    	DN###l L	0 L	0FF!&))Fgll4>273C3CF3K3KLLGOOG$$$: eFG&<&< 	7@@@
8&& #+":1:"F"F%q			ZZ\\
! II>GHHH%++J77 8!F"'++a.."7CK    | "  ,096) ) )$$W---| !7$1 M%)_

%'W\\%4X>>>+4+CI+N+N+N+4+CE+J+J+JL&M &M
 "$Z!8!8J#j0;>FG:w////- : : :())/: : ::8x0000- 8 8 8(<#VGX668 8 88
 gt,, 7

7+++6667 7 7 7 7 7 7 7 7 7 7 7 7 7 7  GGIII GGIII$$W---vw////7g  	0 	0< 0H2D9999 gdmmG4v=G&&8G'))!D!%w9 9 9w///&&s<   ?E&&E=<E=
I  -JJ''.K(=L11L5	8L5	N)__name__
__module____qualname__descriptionuser_optionsboolean_optionsr   r   r!   r$   r#    r   r   r   r      s        >K
 
 
L iO  1 1 1    c' c' c' c' c'r   r   c                       e Zd Zd ZdS )build_scripts_2to3c                 |    t                               |           \  }}| j        s|                     |           ||fS r   )r   r#   r@   run_2to3)r   r   rQ   s      r   r#   zbuild_scripts_2to3.copy_scripts   sA    "/"<"<T"B"B-| 	)MM-(((&&r   N)r^   r_   r`   r#   rd   r   r   rf   rf      s#        ' ' ' ' 'r   rf   )__doc__r0   rerO   r   	distutilsr   distutils.corer   distutils.dep_utilr   distutils.utilr   r   r	   r7   compiler<   r   rf   rd   r   r   <module>rp      s  5 5              " " " " " " $ $ $ $ $ $ 2 2 2 2 2 2 2 2        
;<<G' G' G' G' G'G G' G' G'R' ' ' ' '	 ' ' ' ' 'r   