📄 create.cpython-310.pyc

Size: 7,183 bytes
Path: //opt/saltstack/salt/lib/python3.10/site-packages/relenv/__pycache__/create.cpython-310.pyc
Modified: 2026-06-18 13:40:20
o

�j��@s�dZddlmZddlZddlZddlZddlZddlZddlZddl	Z	ddl
mZddlm
Z
mZmZmZmZmZddlmZmZmZejd*dd
��ZGdd�de
�Zd+dd�Z			d,d-dd�Zd.d d!�Zd/d"d#�Zd/d$d%�Zd0d(d)�ZdS)1z 
The ``relenv create`` command.
�)�annotationsN)�Iterator�)�RelenvException�arches�archived_build�
build_arch�format_shebang�relative_interpreter)�get_default_python_version�python_versions�resolve_python_version�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__rrrrr1sr�
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.13.7) [default: %(default)s])r%r'r$N)
�
add_parser�set_defaults�main�add_argumentrr�sys�platform�strr)rZ	subparserZdefault_versionrrr�setup_parser7s(	��
�r/r#r.�dest�str | os.PathLike[str] | None�arch�
str | None�versionc
Csf|durt�}|rt�|�|}nt�|���}|durt�}t�|���r*td��tj}|dkrB|t	|vr>d�
||�}n0td��|dkrV|t	|vrRd�
|�}ntd��|dkrj|t	|vrfd	�
|�}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.�linuxz	{}-{}-gnuzUnknown arch�darwinz{}-macos�win32z{}-winzUnknown platform�-zError, build archive for z doesn't exist: z,
You might try relenv fetch to resolve this.zr:xz)r�pathlib�Path�resolver�existsrr,r-r�formatr�tarfile�open�extract�_sync_relenv_package�_repair_script_shebangs)
r#r0r2r4Zwriteto�plat�triplet�tar�fp�frrrr YsF���
r �root�pathlib.PathcCsDd�|�d�dd��}tjdkr|ddS|dd|��dS)	zL
    Return the site-packages directory within the created environment.
    �.N�r7ZLibz
site-packages�lib�python)�join�splitr,r-)rHr4�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<r9r:�__file__r;�parent�shutil�rmtree�copytree�ignore_patterns)rHr4Ztarget_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.
    r7N�binrJrKrMrZpython3�/z#!/bin/sh
"true" ''''
z
'''zutf-8)�encoding����
)r,r-�is_dirrNrOr<r
�
ValueErrorr	r.r9�
PurePosixPath�	Exception�iterdir�is_file�	read_text�OSError�UnicodeDecodeError�
startswith�find�len�lstrip�
write_text)rHr4�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)r2r4)
r#r2r�printr
rM�RuntimeErrorrrNr,�exitr r)ryr#Zcreate_version�e�
pyversionsZstrversions�excrrrr*�s,�����r*)rrrr)rrrr)NNN)
r#r.r0r1r2r3r4r3rr)rHrIr4r.rrI)rHrIr4r.rr)ryrzrr) r�
__future__r�argparse�
contextlibrr9rXr,r>�collections.abcr�commonrrrrr	r
r�rrr
�contextmanagerrrr/r rQrArBr*rrrr�<module>s0 
$�
B


A