HEX
Server: LiteSpeed
System: Linux s1049.use1.mysecurecloudhost.com 4.18.0-477.27.2.lve.el8.x86_64 #1 SMP Wed Oct 11 12:32:56 UTC 2023 x86_64
User: xedaptot (3356)
PHP: 8.3.31
Disabled: NONE
Upload Files
File: //opt/saltstack/salt/lib/python3.10/site-packages/relenv/__pycache__/create.cpython-310.pyc
o

;j��@sdZddlmZddlZddlZddlZddlZddlZddlZddl	m
Z
ddlmZm
Z
mZmZmZmZddlmZmZmZe
rLddlZddlmZejd+d
d��ZGdd�de�Zd,dd�Z			d-d.dd�Zd/d!d"�Zd0d#d$�Zd0d%d&�Z d1d)d*�Z!dS)2z 
The ``relenv create`` command.
�)�annotationsN)�
TYPE_CHECKING�)�RelenvException�arches�archived_build�
build_arch�format_shebang�relative_interpreter)�get_default_python_version�python_versions�resolve_python_version)�Iterator�path�str | os.PathLike[str]�return�Iterator[None]c	cs8�t��}zt�|�dVWt�|�dSt�|�w)z�
    Context manager that changes to the specified directory and back.

    :param path: The path to temporarily change to
    :type path: str
    N)�os�getcwd�chdir)r�cwd�r�A/opt/saltstack/salt/lib/python3.10/site-packages/relenv/create.pyr$s�
rc@seZdZdZdS)�CreateExceptionzJ
    Raised when there is an issue creating a new relenv environment.
    N)�__name__�
__module__�__qualname__�__doc__rrrrr4sr�
subparsers�3argparse._SubParsersAction[argparse.ArgumentParser]�NonecCs`|jddd�}|jtd�|jddd�|jdt�ttjtd	d
�t	�}|jd|tdd
�dS)z�
    Setup the subparser for the ``create`` command.

    :param subparsers: The subparsers object returned from ``add_subparsers``
    :type subparsers: argparse._SubParsersAction
    �createzrCreate a Relenv environment. This will create a directory of the given name with newly created Relenv environment.)�description)�func�namez#The name of the directory to create)�helpz--archz,The host architecture [default: %(default)s])�default�choices�typer%z--pythonz>The python version (e.g., 3.10, 3.14.4) [default: %(default)s])r&r(r%N)
�
add_parser�set_defaults�main�add_argumentrr�sys�platform�strr)rZ	subparserZdefault_versionrrr�setup_parser:s(	��
�r0r$r/�dest�str | os.PathLike[str] | None�arch�
str | None�versionc
Csj|durt�}|rt�|�|}nt�|���}|durt�}t�|���r*td��tj}|dkrD|t	|vr@|�d|�d�}n0td��|dkrX|t	|vrT|�d�}ntd��|d	krl|t	|vrh|�d
�}ntd��td��t
|�d|���}|��s�td|�d
|�d���t�|d��}|D]}	|�
|	|�q�Wd�n1s�wYt||�t||�dS)ai
    Create a relenv environment.

    :param name: The name of the environment
    :type name: str
    :param dest: The path the environment should be created under
    :type dest: str
    :param arch: The architecture to create the environment for
    :type arch: str

    :raises CreateException: If there is a problem in creating the relenv environment
    Nz"The requested path already exists.�linux�-z-gnuzUnknown arch�darwinz-macos�win32z-winzUnknown platformzError, build archive for z doesn't exist: z,
You might try relenv fetch to resolve this.zr:xz)r�pathlib�Path�resolver�existsrr-r.rr�tarfile�open�extract�_sync_relenv_package�_repair_script_shebangs)
r$r1r3r5Zwriteto�plat�triplet�tar�fp�frrrr!\sF���
r!�root�pathlib.PathcCsDd�|�d�dd��}tjdkr|ddS|dd|��dS)	zL
    Return the site-packages directory within the created environment.
    �.N�r9ZLibz
site-packages�lib�python)�join�splitr-r.)rHr5�major_minorrrr�_site_packages_dir�s
rQc	Cs`t||�}|��sdS|d}t�t���j}|��r t�|�tj	||dt�
ddd�d�dS)zT
    Ensure the relenv package within the created environment matches this CLI.
    N�relenvT�__pycache__z*.pycz*.pyo)�
dirs_exist_ok�ignore)rQr=r:r;�__file__r<�parent�shutil�rmtree�copytree�ignore_patterns)rHr5Ztarget_site�target�sourcerrrrA�s


�rAc
Cs�tjdkrdS|d}|��sdSd�|�d�dd��}|d|��|d|�d�d��|d|dg}d}|D]
}|��rD|}nq:|durKdSzt|||�}Wn
ty]YdSwz
tt	t
�d	�|��}Wn
tyuYdSwd
}	d}
|�
�D]P}|��s�q~z|jdd
�}Wnttfy�Yq~w|�|	�s�q~|�|
�}
|
dkr�q~|
t|
�}||d�}||�d�}z	|j|dd
�Wq~ty�Yq~wdS)a�
    Update legacy shell-wrapped entry points to the current shebang format.

    Older archives shipped scripts that started with the ``"true" ''''`` preamble.
    Those files break when executed directly under Python (the parser sees the
    unmatched triple-quoted literal). Patch any remaining copies to the new
    `format_shebang` layout so fresh installs do not inherit stale loaders.
    r9N�binrJrKrMrZpython3�/z#!/bin/sh
"true" ''''
z
'''zutf-8)�encoding����
)r-r.�is_dirrNrOr=r
�
ValueErrorr	r/r:�
PurePosixPath�	Exception�iterdir�is_file�	read_text�OSError�UnicodeDecodeError�
startswith�find�len�lstrip�
write_text)rHr5�scripts_dirrPZinterpreter_candidatesZinterpreter_path�	candidateZrel_interpreter�shebangZ
legacy_prefix�markerZscript�text�idxZidy�rest�updatedrrrrB�sj
	�����

��rB�args�argparse.Namespacec
Cs�|j}|jt�kr
td�zt|j�}Wn2tyF}z&td|���t�}d�dd�|D��}td|���t	�
d�WYd}~nd}~wwzt||j|d	�WdStyn}zt|�t	�
d�WYd}~dSd}~ww)
z�
    The entrypoint into the ``relenv create`` command.

    :param args: The args passed to the command
    :type args: argparse.Namespace
    zVWarning: Cross compilation support is experimental and is not fully tested or working!zError: rbcSsg|]}t|��qSr)r/)�.0�_rrr�
<listcomp>szmain.<locals>.<listcomp>zKnown versions are:
rN)r3r5)
r$r3r�printr
rM�RuntimeErrorrrNr-�exitr!r)ryr$Zcreate_version�e�
pyversionsZstrversions�excrrrr+�s(����r+)rrrr)rrrr )NNN)
r$r/r1r2r3r4r5r4rr )rHrIr5r/rrI)rHrIr5r/rr )ryrzrr )"r�
__future__r�
contextlibrr:rXr-r>�typingr�commonrrrrr	r
r�rrr
�argparse�collections.abcr�contextmanagerrrr0r!rQrArBr+rrrr�<module>s4 
$�
A


A