ó
    ‰óýjª)  ã                   óâ   • S r SSKrSSKrSSKJrJr  SSKJr  SSKJ	r	  SSK
JrJrJr  SSKJrJr  SSKJr  SS	KJrJrJrJrJrJr  \(       a  SS
KJrJr   " S S5      r\ " S S\5      5       rg)z:Handles all file writing and post-installation processing.é    N)Ú
CollectionÚIterable)Ú	dataclass)ÚPath)ÚTYPE_CHECKINGÚBinaryIOÚUnion)ÚHashÚRecordEntry)ÚScript)Ú_WINDOWSÚSchemeÚconstruct_record_fileÚcopyfileobj_with_hashingÚfix_shebangÚmake_file_executable)ÚLauncherKindÚScriptSectionc            
       óˆ   • \ rS rSrSrS\S\S\SSS\4
S	 jrS
\S\	\S4   S\
S\S\4
S jrS
\S\S\\\\4      SS4S jrSrg)ÚWheelDestinationé   z³Handles writing the unpacked files, script generation and ``RECORD`` generation.

Subclasses provide the concrete script generation logic, as well as the RECORD file
(re)writing.
ÚnameÚmoduleÚattrÚsectionr   Úreturnc                 ó   • [         e)aÎ  Write a script in the correct location to invoke given entry point.

:param name: name of the script
:param module: module path, to load the entry point from
:param attr: final attribute access, for the entry point
:param section: Denotes the "entry point section" where this was specified.
    Valid values are ``"gui"`` and ``"console"``.
:type section: str

Example usage/behaviour::

    >>> dest.write_script("pip", "pip._internal.cli", "main", "console")

©ÚNotImplementedError)Úselfr   r   r   r   s        ÚA/usr/local/lib/python3.13/site-packages/installer/destinations.pyÚwrite_scriptÚWheelDestination.write_script$   s
   € ô" "Ð!ó    ÚschemeÚpathúos.PathLike[str]ÚstreamÚis_executablec                 ó   • [         e)aÖ  Write a file to correct ``path`` within the ``scheme``.

:param scheme: scheme to write the file in (like "purelib", "platlib" etc).
:param path: path within that scheme
:param stream: contents of the file
:param is_executable: whether the file should be made executable

The stream would be closed by the caller, after this call.

Example usage/behaviour::

    >>> with open("__init__.py") as stream:
    ...     dest.write_file("purelib", "pkg/__init__.py", stream)

r   )r    r%   r&   r(   r)   s        r!   Ú
write_fileÚWheelDestination.write_file7   s
   € ô, "Ð!r$   Úrecord_file_pathÚrecordsNc                 ó   • [         e)ae  Finalize installation, after all the files are written.

Handles (re)writing of the ``RECORD`` file.

:param scheme: scheme to write the ``RECORD`` file in
:param record_file_path: path of the ``RECORD`` file with that scheme
:param records: entries to write to the ``RECORD`` file

Example usage/behaviour::

    >>> dest.finalize_installation("purelib")

r   )r    r%   r-   r.   s       r!   Úfinalize_installationÚ&WheelDestination.finalize_installationO   s
   € ô& "Ð!r$   © )Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__Ústrr   r"   r   r	   r   Úboolr+   r   Útupler0   Ú__static_attributes__r2   r$   r!   r   r      s®   † ñð"Øð"Ø!$ð"Ø,/ð"Ø:Ið"à	ô"ð&"àð"ð �CÐ+Ð+Ñ,ð"ð ð	"ð
 ð"ð 
ô"ð0"àð"ð ð"ð ˜% ¨Ð 3Ñ4Ñ5ð	"ð
 
÷"r$   r   c            
       óN  • \ rS rSr% Sr\\\4   \S'    \\S'    S\S'    Sr\\S'    S	r	\
\   \S
'    Sr\S-  \S'    Sr\\S'    S\S\S\4S jrS\S\S\S\S\4
S jrS\S\\S4   S\S\S\4
S jrS\S\S\SSS\4
S jrS\S\SS4S jrS\S \S!\\\\4      SS4S" jrS	rg)#ÚSchemeDictionaryDestinationée   z>Destination, based on a mapping of {scheme: file-system-path}.Úscheme_dictÚinterpreterr   Úscript_kindÚsha256Úhash_algorithmr2   Úbytecode_optimization_levelsNÚdestdirFÚoverwrite_existingr%   r&   r   c                 óŽ  • [        [        R                  R                  U R                  U   5      5      n[        [        R                  R                  X2-  5      5      nUR                  U5      (       d  [        SU S35      eU R                  b3  UR                  UR                  5      n[        U R                  5      U-  $ U$ )NzAttempting to write z  outside of the target directory)
r   Úosr&   Úabspathr?   Úis_relative_toÚ
ValueErrorrE   Úrelative_toÚanchor)r    r%   r&   Ú
target_dirÚfileÚrel_paths         r!   Ú_path_with_destdirÚ.SchemeDictionaryDestination._path_with_destdirŠ   s¤   € ô œ"Ÿ'™'Ÿ/™/¨$×*:Ñ*:¸6Ñ*BÓCÓDˆ
Ü”B—G‘G—O‘O JÑ$5Ó6Ó7ˆà×"Ñ" :×.Ñ.ÜØ& t fÐ,LÐMóð ð �<‰<Ñ#Ø×'Ñ'¨¯©Ó4ˆHÜ˜Ÿ™Ó%¨Ñ0Ð0Øˆr$   r(   r)   c                 óÞ  • U R                  X5      nU R                  (       d&  UR                  5       (       a  SU< 3n[        U5      eUR                  nUR                  5       (       d  UR                  SS9  UR                  S5       n[        X8U R                  5      u  pšSSS5        U(       a  [        U5        [        U[        U R                  W	5      W
5      $ ! , (       d  f       NA= f)a§  Write contents of ``stream`` to the correct location on the filesystem.

:param scheme: scheme to write the file in (like "purelib", "platlib" etc).
:param path: path within that scheme
:param stream: contents of the file
:param is_executable: whether the file should be made executable

- Ensures that an existing file is not being overwritten.
- Hashes the written content, to determine the entry in the ``RECORD`` file.
zFile already exists: T)ÚparentsÚwbN)rQ   rF   ÚexistsÚFileExistsErrorÚparentÚmkdirÚopenr   rC   r   r   r
   )r    r%   r&   r(   r)   Útarget_pathÚmessageÚparent_folderÚfÚhash_Úsizes              r!   Úwrite_to_fsÚ'SchemeDictionaryDestination.write_to_fs¢   sÈ   € ð" ×-Ñ-¨fÓ;ˆØ×&×&¨;×+=Ñ+=×+?Ñ+?Ø-¨k©_Ð=ˆGÜ! 'Ó*Ð*à#×*Ñ*ˆØ×#Ñ#×%Ñ%Ø×Ñ¨ÐÑ-à×Ñ˜dÔ# qÜ2°6¸d×>QÑ>QÓR‰KˆE÷ $ö Ü  Ô-ä˜4¤ d×&9Ñ&9¸5Ó!AÀ4ÓHÐH÷ $Õ#ús   Â
CÃ
C,r'   c                 óâ   • [         R                  " U5      nUS:X  a1  [        X0R                  5       nU R	                  XXd5      sSSS5        $ U R	                  XX45      $ ! , (       d  f       N = f)a¥  Write a file to correct ``path`` within the ``scheme``.

:param scheme: scheme to write the file in (like "purelib", "platlib" etc).
:param path: path within that scheme
:param stream: contents of the file
:param is_executable: whether the file should be made executable

- Changes the shebang for files in the "scripts" scheme.
- Uses :py:meth:`SchemeDictionaryDestination.write_to_fs` for the
  filesystem interaction.
ÚscriptsN)rH   Úfspathr   r@   ra   )r    r%   r&   r(   r)   Úpath_Ústream_with_different_shebangs          r!   r+   Ú&SchemeDictionaryDestination.write_fileÄ   sd   € ô$ —	’	˜$“ˆà�YÓÜ˜V×%5Ñ%5Ô6Ð:WØ×'Ñ'ØÐ#@ó÷ 7Ñ6ð
 ×Ñ ¨vÓEÐE÷ 7Õ6ús   ²A Á 
A.r   r   r   r   r   c                 ó¤  • [        XX45      nUR                  U R                  U R                  5      u  pg[        R
                  " U5       nU R                  [        S5      XhSS9n	U R                  [        S5      U5      n
U
R                  5       R                  nX»S-  S-	  -  nU
R                  U5        U	sSSS5        $ ! , (       d  f       g= f)a   Write a script to invoke an entrypoint.

:param name: name of the script
:param module: module path, to load the entry point from
:param attr: final attribute access, for the entry point
:param section: Denotes the "entry point section" where this was specified.
    Valid values are ``"gui"`` and ``"console"``.
:type section: str

- Generates a launcher using :any:`Script.generate`.
- Writes to the "scripts" scheme.
- Uses :py:meth:`SchemeDictionaryDestination.write_to_fs` for the
  filesystem interaction.
rd   T©r)   i$  é   N)r   Úgenerater@   rA   ÚioÚBytesIOra   r   rQ   ÚstatÚst_modeÚchmod)r    r   r   r   r   ÚscriptÚscript_nameÚdatar(   Úentryr&   Úmodes               r!   r"   Ú(SchemeDictionaryDestination.write_scriptà   s´   € ô" ˜ dÓ4ˆØ"ŸO™O¨D×,<Ñ,<¸d×>NÑ>NÓOÑˆä�ZŠZ˜Ô Ø×$Ñ$Ü�yÓ! ;Àdð %ð ˆEð ×*Ñ*¬6°)Ó+<¸kÓJˆDØ—9‘9“;×&Ñ&ˆDØ˜E‘\ aÑ'Ñ'ˆDØ�J‰J�tÔà÷ ××ús   ÁA,CÃ
CÚrecordc                 ó  • U R                   (       a  US;  a  gSSKnU R                  XR                  5      n[	        U R
                  U   5      UR                  -  R                  nU R                    H  nUR                  XFSUS9  M     g)z'Compile bytecode for a single .py file.)ÚpurelibÚplatlibNr   é   )ÚoptimizeÚquietÚddir)rD   Ú
compileallrQ   r&   r   r?   rX   Úcompile_file)r    r%   rx   r€   r[   Údir_path_to_embedÚlevels          r!   Ú_compile_bytecodeÚ-SchemeDictionaryDestination._compile_bytecode   s„   € à×0×0°Fð C
ó 5
ð ãà×-Ñ-¨f·k±kÓBˆÜ! $×"2Ñ"2°6Ñ":Ó;¸f¿k¹kÑI×QÑQÐà×6Ô6ˆEØ×#Ñ#Ø°1Ð;Lð $ó ò 7r$   r-   r.   c                 óò   ^ ^• S[         S[         S-  4UU 4S jjn[        U5      n[        XT5       nT R                  TX&SS9  SSS5        U H  u  pxT R	                  Xx5        M     g! , (       d  f       N+= f)a  Finalize installation, by writing the ``RECORD`` file & compiling bytecode.

:param scheme: scheme to write the ``RECORD`` file in
:param record_file_path: path of the ``RECORD`` file with that scheme
:param records: entries to write to the ``RECORD`` file
Úfile_schemer   Nc                 ó  >• U T:X  a  g [         (       a1  [        R                  R                  TR                  U    5      nUS-   $ [        R                  R                  TR                  U    TR                  T   S9nUS-   $ )N)ÚstartÚ/)r   rH   r&   rI   r?   Úrelpath)r‡   r&   r%   r    s     €€r!   Úprefix_for_schemeÚLSchemeDictionaryDestination.finalize_installation.<locals>.prefix_for_scheme  s}   ø€ Ø˜fÓ$ØßŠxÜ—w‘w—‘ t×'7Ñ'7¸Ñ'DÓE�ð ˜#‘:Ðô	 —w‘w—‘Ø×$Ñ$ [Ñ1Ø×*Ñ*¨6Ñ2ð 'ð �ð ˜#‘:Ðr$   Frj   )r8   Úlistr   ra   r„   )	r    r%   r-   r.   rŒ   Úrecord_listÚrecord_streamÚscheme_rx   s	   ``       r!   r0   Ú1SchemeDictionaryDestination.finalize_installation  s{   ù€ ð
	¬3ð 
	´3¸±:÷ 
	ð 
	ô ˜7“mˆÜ" ;ÔBÀmØ×ÑØÐ(Àuð ñ ÷ Có
  +‰OˆGØ×"Ñ" 7Ö3ò  +÷ CÕBús   ±A(Á(
A6)r3   r4   r5   r6   r7   Údictr8   Ú__annotations__rC   rD   r   ÚintrE   rF   r9   r   r   rQ   r   r   ra   r	   r+   r"   r„   r   r:   r0   r;   r2   r$   r!   r=   r=   e   s�  ‡ áHà�c˜3�h‘ÓØ1àÓØ8àÓØ/à"€N�CÓ"ðð 57Ð  *¨S¡/Ó6ðð €GˆS�4‰ZÓðð  %Ð˜Ó$Ø,ð¨ð °sð ¸tô ð0 Iàð Ið ð Ið ð	 Ið
 ð Ið 
ô IðDFàðFð �CÐ+Ð+Ñ,ðFð ð	Fð
 ðFð 
ôFð8ØðØ!$ðØ,/ðØ:Iðà	ôð@¨ð ¸ð Èô ð$ 4àð 4ð ð 4ð ˜% ¨Ð 3Ñ4Ñ5ð	 4ð
 
÷ 4r$   r=   )r7   rm   rH   Úcollections.abcr   r   Údataclassesr   Úpathlibr   Útypingr   r   r	   Úinstaller.recordsr
   r   Úinstaller.scriptsr   Úinstaller.utilsr   r   r   r   r   r   r   r   r   r=   r2   r$   r!   Ú<module>r�      sg   ðÙ @ã 	Û 	ß 0Ý !Ý ÷ñ ÷ 0Ý $÷÷ ö ß=÷E"ñ E"ðP ôL4Ð"2ó L4ó ñL4r$   