
    YHh+                    T   d dl mZ d dlZd dlZd dlZd dl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mZ erd dlmZ ddlmZ d d	lmZ d d
lmZ  G d ded      Z G d de      Z G d de      Z G d d      Z G d de      Z G d de      Z d Z!d Z"d Z#d Z$d Z%y)    )annotationsN)Iterable)TYPE_CHECKING	TypedDict   )metadata	resources)Self)SetuptoolsWarning)first_line_re)get_platformc                  "    e Zd ZU ded<   ded<   y)
_SplitArgsboolcommentsposixN)__name__
__module____qualname____annotations__     L/var/www/html/planif/env/lib/python3.12/site-packages/setuptools/_scripts.pyr   r      s    NKr   r   F)totalc                      e Zd ZU dZg Zded<    e       Zed        Z	ed        Z
edd       Zed        Zedd       Zdd	Zed
        Zd Zed        Zed        Zy)CommandSpeczm
    A command spec for a #! header, specified as a list of arguments akin to
    those passed to Popen.
    z	list[str]optionsc                    | S )zV
        Choose the best CommandSpec class based on environmental conditions.
        r   clss    r   bestzCommandSpec.best'   s	    
 
r   c                    t         j                  j                  t        j                        }t         j
                  j                  d|      S )N__PYVENV_LAUNCHER__)ospathnormpathsys
executableenvironget)r    _defaults     r   _sys_executablezCommandSpec._sys_executable.   s0    77##CNN3zz~~3X>>r   c                    t        ||       r|S t        |t              r| j                  |      S t        |t              r | |      S || j	                         S t        dt        |             )zg
        Construct a CommandSpec from a parameter to build_scripts, which may
        be None.
        z!Argument has an unsupported type )
isinstancestrfrom_stringr   from_environment	TypeErrortype)r    params     r   
from_paramzCommandSpec.from_param3   sk     eS!LeS!??5))eX&u:=''));DK=IJJr   c                0     | | j                         g      S N)r,   r   s    r   r1   zCommandSpec.from_environmentC   s    C'')*++r   c                R    t        j                  |fi | j                  } | |      S )z}
        Construct a command spec from a simple string representing a command
        line parseable by shlex.split.
        )shlexsplit
split_args)r    stringitemss      r   r0   zCommandSpec.from_stringG   s%     F5cnn55zr   c                    t        j                  | j                  |            | _        t	        j
                  |       }t        |      sdg| j                  d d y y )Nz-xr   )r9   r:   _extract_optionsr   
subprocesslist2cmdlineisascii)selfscript_textcmdlines      r   install_optionszCommandSpec.install_optionsP   sL    {{4#8#8#EF))$/w $vDLL!  r   c                    | dz   j                         d   }t               j                  |      }|r|j                  d      xs dnd}|j	                         S )zH
        Extract any options from the first line of the script.
        
r   r    )
splitlines_first_line_rematchgroupstrip)orig_scriptfirstrL   r   s       r   r?   zCommandSpec._extract_optionsV   sQ    
 t#//1!4 &&u-*/%++a.&BR}}r   c                P    | j                  | t        | j                        z         S r7   )_renderlistr   )rC   s    r   	as_headerzCommandSpec.as_header`   s    ||D4#5566r   c                l    d}|D ],  }| j                  |      s| j                  |      s'| dd c S  | S )Nz"'r   )
startswithendswith)item_QUOTESqs      r   _strip_quoteszCommandSpec._strip_quotesc   s@     	"Aq!dmmA&6Abz!	" r   c                J    t        j                  d | D              }d|z   dz   S )Nc              3  b   K   | ]'  }t         j                  |j                                ) y wr7   )r   r\   rN   ).0rY   s     r   	<genexpr>z&CommandSpec._render.<locals>.<genexpr>m   s&      *
8<K%%djjl3*
s   -/z#!rH   )r@   rA   )r=   rE   s     r   rR   zCommandSpec._renderk   s0    )) *
@E*
 
 g~$$r   N)r4   z!Self | str | Iterable[str] | Nonereturnr
   )r<   r/   ra   r
   )rD   r/   )r   r   r   __doc__r   r   r   r;   classmethodr!   r,   r5   r1   r0   rF   staticmethodr?   rT   r\   rR   r   r   r   r   r      s    
 GYJ  ? ? K K , ,  &  7   % %r   r   c                      e Zd Z ed      Zy)WindowsCommandSpecF)r   N)r   r   r   r   r;   r   r   r   rf   rf   s   s    %(Jr   rf   c                      e Zd ZdZ ej
                  d      j                         ZeZ	e
d	d       Zed        Ze
d        Ze
d        Ze
	 	 d
	 	 	 	 	 dd       Zy)ScriptWriterz`
    Encapsulates behavior around writing entry point scripts for console and
    gui apps.
    aJ  
        # EASY-INSTALL-ENTRY-SCRIPT: %(spec)r,%(group)r,%(name)r
        import re
        import sys

        # for compatibility with easy_install; see #2198
        __requires__ = %(spec)r

        try:
            from importlib.metadata import distribution
        except ImportError:
            try:
                from importlib_metadata import distribution
            except ImportError:
                from pkg_resources import load_entry_point


        def importlib_load_entry_point(spec, group, name):
            dist_name, _, _ = spec.partition('==')
            matches = (
                entry_point
                for entry_point in distribution(dist_name).entry_points
                if entry_point.group == group and entry_point.name == name
            )
            return next(matches).load()


        globals().setdefault('load_entry_point', importlib_load_entry_point)


        if __name__ == '__main__':
            sys.argv[0] = re.sub(r'(-script\.pyw?|\.exe)?$', '', sys.argv[0])
            sys.exit(load_entry_point(%(spec)r, %(group)r, %(name)r)())
        Nc              #  $  K   t        |d      s>t        j                  d       t        j                  j                  |j                        }|| j                         }|j                   d|j                   }dD ]  }| d}|j                  j                  |      D ]h  }|j                  }| j                  |j                         | j                  t               z  }| j                  ||j                  ||      }	|	E d{    j  y7 	w)z
        Yield write_script() argument tuples for a distribution's
        console_scripts and gui_scripts entry points.
        entry_pointsz%Unsupported distribution encountered.Nz==consolegui_scripts)rM   )hasattrr   emitr   Distributionategg_info
get_headernameversionrj   select_ensure_safe_nametemplatelocals_get_script_args)
r    distheaderspectype_rM   epru   rD   argss
             r   get_argszScriptWriter.get_args   s      t^,""#JK((++DMM:D>^^%F))Bt||n-% 	 EgX&E''..U.;  ww%%bgg.!llVX5++E277FKP 	   s   DDD
Dc                J    t        j                  d|       }|rt        d      y)z?
        Prevent paths in *_scripts entry point names.
        z[\\/]z+Path separators not allowed in script namesN)research
ValueError)ru   has_path_seps     r   rx   zScriptWriter._ensure_safe_name   s(    
 yy40JKK r   c                    t         j                  dk(  s&t        j                  dk(  r't        j                  dk(  rt
        j                         S | S )zD
        Select the best ScriptWriter for this environment.
        win32javant)r'   platformr$   ru   _nameWindowsScriptWriterr!   r   s    r   r!   zScriptWriter.best   s:    
 <<7"rww&'8RXX=M&++--Jr   c              #     K   |||z   f y wr7   r   )r    r   ru   r}   rD   s        r   r{   zScriptWriter._get_script_args   s      Vk)**s   c                    | j                   j                         j                  |      }|j                  |       |j	                         S )z;Create a #! line, getting options (if any) from script_text)command_spec_classr!   r5   rF   rT   )r    rD   r(   cmds       r   rt   zScriptWriter.get_header   s=     $$))+66zBK(}}r   r7   )rI   N)rD   r/   r(   z(str | CommandSpec | Iterable[str] | Nonera   r/   )r   r   r   rb   textwrapdedentlstripry   r   r   rc   r   rd   rx   r!   r{   rt   r   r   r   rh   rh   w   s    
 x!	#F fhG J %   0 L L   + +  ?C = 
	 r   rh   c                  P    e Zd ZeZed        Zed        Zed        Ze	d        Z
y)r   c                n    t        t        |       }t        j                  j	                  dd      }||   S )zC
        Select the best ScriptWriter suitable for Windows
        )r(   naturalSETUPTOOLS_LAUNCHERr(   )dictWindowsExecutableLauncherWriterr$   r)   r*   )r    writer_lookuplaunchers      r   r!   zWindowsScriptWriter.best   s6    
 6

 ::>>"7FX&&r   c              #    K   t        dd      |   }|t        j                  d   j                         j	                  d      vr/ dj
                  d
i t               }t        j                  |       g d}|j                  |       | j                  ||      }|D cg c]  }||z   	 }	}||z   ||z   d|	f y	c c}w w)z For Windows, add a .py extension.pya.pywrk   PATHEXT;zK{ext} not listed in PATHEXT; scripts will not be recognized as executables.)r   .py
-script.py.pyc.pyor   .exetNr   )r   r$   r)   lowerr:   formatrz   r   rp   remove_adjust_header)
r    r   ru   r}   rD   extmsgoldxblockerss
             r   r{   z$WindowsScriptWriter._get_script_args   s      6v.u5bjj+11399#>>-f! x!C ""3'K

3##E62&)*D1H**Sj&;.X== +s   BCB<+Cc                    d}d}|dk(  r||}}t        j                  t        j                  |      t         j                        }|j	                  ||      }| j                  |      r|S |S )z
        Make sure 'pythonw' is used for gui and 'python' is used for
        console (regardless of what sys.executable is).
        zpythonw.exez
python.exerm   )r<   repl)r   compileescape
IGNORECASEsub_use_header)r    r   orig_headerpatternr   
pattern_ob
new_headers          r   r   z"WindowsScriptWriter._adjust_header  sc      E> 'TGZZ		' 2BMMB
^^;T^B
 __Z8zIkIr   c                ~    | dd j                  d      }t        j                  dk7  xs t        j                  |      S )z
        Should _adjust_header use the replaced header?

        On non-windows systems, always use. On
        Windows systems, only use the replaced header if it resolves
        to an executable on the system.
           rV   "r   )rN   r'   r   shutilwhich)r   clean_headers     r   r   zWindowsScriptWriter._use_header  s8     "!B'--c2||w&D&,,|*DDr   N)r   r   r   rf   r   rc   r!   r{   r   rd   r   r   r   r   r   r      sZ    +
' 
' > > J J 	E 	Er   r   c                      e Zd Zed        Zy)r   c              #  
  K   |dk(  rd}d}dg}nd}d}g d}| j                  ||      }|D 	cg c]  }	||	z   	 }
}	||z   ||z   d|
f |dz   t        |      d	f t               s|d
z   }|t        |      df yyc c}	w w)zG
        For Windows, add a .py extension and an .exe launcher
        rm   z-script.pywr   clir   )r   r   r   r   r   bz.exe.manifestN)r   get_win_launcheris_64bitload_launcher_manifest)r    r   ru   r}   rD   launcher_typer   r   hdrr   r   m_names               r   r{   z0WindowsExecutableLauncherWriter._get_script_args  s     
 E>!MC(C!MC)C  /&)*D1H**cz3,c8<<6M]+
 	

 z O+F1$7==  +s   ,BA>A	BN)r   r   r   rc   r{   r   r   r   r   r     s    > >r   r   c                   |  d}t               r3t               dk(  r|j                  dd      }n%|j                  dd      }n|j                  dd      }t        j                  d      j                  |      j                         S )z
    Load the Windows launcher (executable) suitable for launching a script.

    `type` should be either 'cli' or 'gui'

    Returns the executable as a byte string.
    r   z	win-arm64.z-arm64.z-64.z-32.
setuptools)r   r   replacer	   filesjoinpath
read_bytes)r3   launcher_fns     r   r   r   <  sw     F$-Kz>[(%--c9=K%--c6:K!))#v6??<(11+>IIKKr   c                    t        j                  t              j                  d      }|j	                  d      t               z  S )Nzlauncher manifest.xmlzutf-8)encoding)r	   r   r   r   	read_textvars)ru   ress     r   r   r   O  s4    
//(
#
,
,-D
EC=='=*TV33r   c                     t        t        j                  t              rt        S t	        j
                  t        j                  j                               S )z_
    Return a regular expression based on first_line_re suitable for matching
    strings.
    )r.   r   r   r/   r   r   decoder   r   r   rK   rK   T  s:    
 -''- ::m++22455r   c                 2    t        j                  d      dk(  S )NP   )structcalcsizer   r   r   r   r   `  s    ??31$$r   c                F    	 | j                  d       y# t        $ r Y yw xY w)NasciiFT)encodeUnicodeError)ss    r   rB   rB   d  s,    	   s    	  )&
__future__r   r$   r   r9   r   r   r@   r'   r   collections.abcr   typingr   r   
_importlibr   r	   typing_extensionsr
   warningsr   distutils.command.build_scriptsr   distutils.utilr   r   rS   r   rf   rh   r   r   r   r   rK   r   rB   r   r   r   <module>r      s    " 	 	     
  $ + +& ' 9 '% 
R%$ R%j) )g gT8E, 8Ev>&9 >@L&4
	6%r   