📄 runtime.cpython-310.pyc

Size: 31,004 bytes
Path: //opt/saltstack/salt/lib/python3.10/site-packages/relenv/__pycache__/runtime.cpython-310.pyc
Modified: 2026-06-18 13:40:17
o

�j���
@stUdZddlmZddlZddlZddlZddlZddl	Z
ddlZddlZddl
ZddlZddlZddlZddlZddlZddlmZddlmZddlmZmZmZm Z m!Z!m"Z"m#Z#m$Z$m%Z%e%ee
�Z	e%ee�Ze%ee�Ze%ee�Ze%ee�Ze%ee�Ze%ee�Z
e%ee�Zgd�Z&e$e'ej(e'fZ)ee'e'fZ*d�dd�Z+da,de-d<da.de-d<da/de-d<d�dd�Z0d�dd�Z1d�dd�Z2d�dd�Z3ej4d�dd��Z5d�d"d#�Z6d�d%d&�Z7d�d,d-�Z8d�d/d0�Z9d1d2d3d4d5d6d7d8d9d:d8d;�Z:d<e-d=<da;d>e-d?<d�d@dA�Z<d�dDdE�Z=d�dHdI�Z>d�dKdL�Z?d�dMdN�Z@d�dOdP�ZAGdQdR�dR�ZBGdSdT�dT�ZCd�dUdV�ZDd�dWdX�ZEd�dYdZ�ZFd�d[d\�ZGd�d]d^�ZHd�d`da�ZId�dbdc�ZJGddde�de�ZKd�dfdg�ZLd�dhdi�ZMd�djdk�ZNd�dldm�ZOd�dndo�ZPeCeBdpeD�eBdqeE�eBdreF�eBdseG�eBdteH�eBdueJ�eBdveM�eBdweN�eBdxeO�eBdyeP�g
dz�ZQd�d{d|�ZRd�d}d~�ZSd�dd��ZTd�d�d��ZUd�d�d��ZVd�d�d��ZWd�d�d��ZXdS)�a�
This code is run when initializing the python interperter in a Relenv environment.

- Point Relenv's Openssl to the system installed Openssl certificate path
- Make sure pip creates scripts with a shebang that points to the correct
  python using a relative path.
- On linux, provide pip with the proper location of the Relenv toolchain
  gcc. This ensures when using pip any c dependencies are compiled against the
  proper glibc version.
�)�annotationsN)�
ModuleSpec)�
ModuleType)	�Any�Callable�Dict�Iterable�Iterator�Optional�Sequence�Union�cast)�sys�shutil�
subprocess�json�	importlib�site�ctypes�warnings�name�str�path�PathType�returnrcCsbddl}|j�||�}|dus|jdurtd|�d|����|j�|�}|j�|�|tj|<|S)z�
    Import module from a path.

    This causes hashlib to be imported because of importing importlib.util so
    it can not be used until after openssl has been configured.
    rNzUnable to load module z from )	�importlib.util�util�spec_from_file_location�loader�ImportError�module_from_spec�exec_moduler�modules)rrr�spec�module�r%�B/opt/saltstack/salt/lib/python3.10/site-packages/relenv/runtime.py�path_importMs
r'�Optional[ModuleType]�_COMMON�	_RELOCATE�	_BUILDENVcC�&tdurtdtt�t�jd��atS)z+Return the cached ``relenv.common`` module.Nz
relenv.commonz	common.py)r)r'r�pathlib�Path�__file__�parentr%r%r%r&�commond�
�r1cCr,)z-Return the cached ``relenv.relocate`` module.Nzrelenv.relocatezrelocate.py)r*r'rr-r.r/r0r%r%r%r&�relocatenr2r3cCr,)z-Return the cached ``relenv.buildenv`` module.Nzrelenv.buildenvzbuildenv.py)r+r'rr-r.r/r0r%r%r%r&�buildenvxr2r4cCsdjtj�S)z'
    Current python major version.
    z{}.{})�formatr�version_infor%r%r%r&�get_major_version��r7�new_dir�Iterator[None]c	cs8�t��}t�|�zdVWt�|�dSt�|�w)z
    Changedir context.
    N)�os�getcwd�chdir)r9Zold_dirr%r%r&�pushd�s�
r>�string�NonecCs&tj�d�rt|�tj��dSdS)z�
    Prints the provided message if RELENV_DEBUG is truthy in the environment.

    :param string: The message to print
    :type string: str
    ZRELENV_DEBUGN)r;�environ�get�printr�stdout�flush)r?r%r%r&�debug�s�rF�pathlib.PathcCs0t�t���j}tjdkr|jjjS|jjjjS)z(
    Return the relenv module root.
    �win32)r-r.r/�resolver0r�platform)Z
MODULE_DIRr%r%r&�relenv_root�s

rK�func�Callable[..., bytes]�argsr�kwargscst���d
�fdd��}|S)zf
    Build a shebang to point to the proper location.

    :return: The shebang
    :rtype: bytes
    �selfrrNrOr�bytescs�t�|j�}tjrt�t����d}zt��tj	|t�tj
����}WntyBt
d|j����|g|�Ri|��}|YSwt
d|�d|���tjdkr_tt�d�|���dStt�d�|�}ttt��|��}|��S)	N�binz$Relenv Value Error - _build_shebang zRelenv - _build_shebang � rHz#!<launcher_dir>s
�/)r-r.�
target_dir�TARGET�_ensure_target_path�absoluter1Zrelative_interpreterr�RELENV�
executablerI�
ValueErrorrFrJr�encode�
PurePosixPathr
Zformat_shebang)rPrNrO�scriptsZinterpreterZoriginal_resultZrel_path�	formatted�rLr%r&�wrapped�s&��
�z_build_shebang.<locals>.wrappedN)rPrrNrrOrrrQ��	functools�wraps)rLrNrOrar%r`r&�_build_shebang�s
re�Callable[[str], Any]cst���d�fdd��}|S)	�H
    Return a wrapper to resolve paths relative to the relenv root.
    rrrrcsl|dkr&�|�}tj�d�rt�}nt�d}td|�d|�d|���|S�|�}td|�d|���|S)NZBINDIR�RELENV_PIP_DIRZScriptszget_config_var call z old: z new: rS)r;rArBrKrF)rZorig�valr`r%r&ra�s
z'get_config_var_wrapper.<locals>.wrappedN)rrrrrb)rLrar%r`r&�get_config_var_wrapper�srjZar�gccz?-Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wallz-I. -I./Includezg++z/usr/local/lib/python3.10z/usr/local/libzgcc -shared�zg++ -shared�ZARZCCZCFLAGSZCPPFLAGSZCXXZLIBDESTZ	SCRIPTDIRZ	BLDSHAREDZLDFLAGSZLDCXXSHAREDZLDSHARED�
ConfigVars�CONFIG_VARS_DEFAULTSzOptional[ConfigVars]�_SYSTEM_CONFIG_VARScCs�tdurtSt�d�}|��r>tjt|�ddgdd�}zt�|j	�
��aWtStjy=td|j	�
����t
aYtSwtd�t
atS)	z�
    Read the system python's sysconfig values.

    Th system python isthe one installed by your package manager. Memoize them
    to avoid the overhead of shelling out.
    Nz/usr/bin/python3z-czFimport json, sysconfig; print(json.dumps(sysconfig.get_config_vars()))T)�capture_outputzFailed to load JSON from: zSystem python not found)rpr-r.�existsr�runrr�loadsrD�stripZJSONDecodeErrorrFro)Zpyexec�pr%r%r&�system_sysconfig�s,
����rw�Callable[..., ConfigVars]�modcst���d��fdd��}|S)	rgrNrrrncsRtjdks
dtjvr�|�S��}t�}dD]}||||<qt�d|��|�S)NrH�RELENV_BUILDENVrmZ_CONFIG_VARS)rrJr;rArw�setattr)rNZconfig_varsZsystem_config_varsr�rLryr%r&ra s
z(get_config_vars_wrapper.<locals>.wrappedN)rNrrrnrb)rLryrar%r|r&�get_config_vars_wrappersr}�Callable[..., Dict[str, str]]�default_schemecs$t���|ddfd
�fdd�
�}|S)rgNT�scheme�
Optional[str]�vars�Optional[Dict[str, str]]�expand�boolr�Dict[str, str]cs4�|||d�}dtjvrtt��|d<|dt_|S)N)r�r�r�rhr^)r;rArrKr�exec_prefix)r�r�r��pathsr`r%r&raBs


z"get_paths_wrapper.<locals>.wrapped)r�r�r�r�r�r�rr�rb)rLrrar%r`r&�get_paths_wrapper;s�r��Callable[..., Any]cst���d
�fdd��}|S)zl
    Wrapper around build_ext.finalize_options.

    Used to add the relenv environment's include path.
    rPrrNrOrr@cs>�|g|�Ri|��dtjvr|j�tt�d��dSdS)NrzZinclude)r;rAZinclude_dirs�appendrrK)rPrNrOr`r%r&�wrapperXs
�z)finalize_options_wrapper.<locals>.wrapperN)rPrrNrrOrrr@rb�rLr�r%r`r&�finalize_options_wrapperQsr�cst���d�fd
d��}|S)z{
    Wrap pip's wheel install function.

    This method determines any newly installed files and checks their RPATHs.
    rr�
wheel_pathrr�r�req_description�	pycompile�warn_script_location�
direct_url�	requestedrc	sjddlm}ddlm}	||��}
|	|
|�\}}Wd�n1s"wY�||||||||�dtjvr�t�|j�}
t	�}t
|
|d��a}|��D]S}|
|�dd�d}|�
�setd|���qMt��|�r�td	|���t��|
||d
d|�qMt��|�r�t�d�}|r�t��t|
|�t|�d�qMtd
�qMWd�dS1s�wYdSdS)Nr)�ZipFile)�parse_wheelrzZRECORD�,��Relenv - File not found �Relenv - Found elf �libTZotoolzGThe otool command is not available, please run `xcode-select --install`)Zzipfiler�Zpip._internal.utils.wheelr�r;rAr-r.�platlibrK�open�	readlines�splitrrrFr3�is_elf�
handle_elfZis_machor�whichZhandle_machor)rr�r�r�r�r�r�r�r�r�ZzfZinfo_dirZmetadata�plat�rootdir�fp�line�fileZ	otool_binr`r%r&r�hsT
��

�
����"��z&install_wheel_wrapper.<locals>.wrapperN)rrr�rr�rr�rr�rr�rr�rr�rrrrbr�r%r`r&�install_wheel_wrapperas3r�cst���d�fdd��}|S)z|
    Wrap pip's legacy install function.

    This method determines any newly installed files and checks their RPATHs.
    �install_optionsr�global_options�root�home�prefix�
use_user_siter�r��
setup_py_path�isolated�req_name�	build_env�unpacked_source_directoryr�rcsTt�|�jd}t|��}|��}Wd�n1swYd}d}|��D]&}|�d�r<|�d�d��}|r<n|�d�rN|�d�d��}|rNnq(�||||||||||	|
|||
�d}|r�t�|�ddt	���d	}t
|�d
��D]}|j�|�d|���r�|}nqzt
t�|j
��d
��D]}|j�|�d|���r�|}nq�|dur�td|
���dSt�|j�}t�}t|��\td
��>}|��D]1}t�|�����}|��s�td|���q�t��|�r�td|���t��|||dd|�q�Wd�n1�s
wYWd�dSWd�dS1�s#wYdS)NzPKG-INFOzVersion:z	Version: r�zName:zName: r��python�
site-packagesz
*.egg-info�-z*Relenv was not able to find egg info for: zinstalled-files.txtr�r�T)r-r.r0r��read�
splitlines�
startswithr�rur7�sorted�globr�purelibrFr�rKr>r�rIrrr3r�r�)r�r�r�r�r�r�r�r�r�r�r�r�r�r�Zpkginfor�Zpkg_info�versionrr�ZegginfoZsitepackrr�r�r�r`r%r&r��s�

�

���
�����

��� ��$�z'install_legacy_wrapper.<locals>.wrapperN)r�rr�rr�rr�rr�rr�rr�rr�rr�rr�rr�rr�rr�rr�rrrrbr�r%r`r&�install_legacy_wrapper�s	Qr�c@s4eZdZdZ		ddd
d�Zddd�Zddd�ZdS)�Wrapperz-
    Wrap methods of an imported module.
    �equalsFr$rr��Callable[[str], ModuleType]�matcher�_loadingr�rr@cCs||_||_||_||_dS�N)r$r�r��loading)rPr$r�r�r�r%r%r&�__init__s
zWrapper.__init__rP�	'Wrapper'cCs |jdkr|�|j�S|j|kS)zA
        Check if wrapper metches module being imported.
        r�)r�r�r$�rPr$r%r%r&�matchess

zWrapper.matches�module_namercCs
|�|�S)z0
        Preform the wrapper operation.
        )r�)rPr�r%r%r&�__call__s
zWrapper.__call__N)r�F)
r$rr�r�r�rr�r�rr@)rPr�r$rrr�)rPr�r�rrr)�__name__�
__module__�__qualname__�__doc__r�r�r�r%r%r%r&r��s�
r�c@s\eZdZdZ		d%d&d	d
�Z		d%d'dd�Z	d(d)dd�Zd*dd�Zd+d d!�Zd,d#d$�Z	dS)-�RelenvImporterz4
    Handle runtime wrapping of module methods.
    N�wrappers�Optional[Iterable[Wrapper]]�_loads�Optional[Dict[str, ModuleType]]rr@cCs,|durg}t|�|_|duri}||_dSr�)�setr�r�)rPr�r�r%r%r&r�"s

zRelenvImporter.__init__rP�'RelenvImporter'r�r�package_path�Optional[Sequence[str]]�targetr�Optional[ModuleSpec]cCs`|jD]*}|�|�r-|js-td|�d|�d|���d|_tj�||�}ttt	|�SqdS)�.
        Find modules being imported.
        �RelenvImporter - match rSTN)
r�r�r�rFrr�spec_from_loaderr
r
r)rPr�r�r�r�r#r%r%r&�	find_spec.s
	�zRelenvImporter.find_spec�Optional['RelenvImporter']cCs<|jD]}|�|�r|jstd|���d|_|SqdS)r�r�TN)r�r�r�rF)rPr�r�r�r%r%r&�find_module?s
�zRelenvImporter.find_modulerrcCsZd}|jD]}|�|�rtd|���||�}d|_nq|dur&t�|�}|tj|<|S)z*
        Load an imported module.
        NzRelenvImporter - load_module F)r�r�rFr�r�
import_modulerr")rPrryr�r%r%r&�load_moduleNs

�

zRelenvImporter.load_moduler#rr(cCs|�|j�S)z/
        Create the module via a spec.
        )r�r)rPr#r%r%r&�
create_module^r8zRelenvImporter.create_moduler$cCsdS)z#
        Exec module noop.
        Nr%r�r%r%r&r!dszRelenvImporter.exec_module�NN)r�r�r�r�rr@)
rPr�r�rr�r�r�rrr�r�)rPr�r�rr�r�rr�)rPr�rrrr)rPr�r#rrr()rPr�r$rrr@)
r�r�r�r�r�r�r�r�r�r!r%r%r%r&r�s���

r�cCsnt�d�}tt|�}t|j�|_t|j|�|_d|_z|�	�}Wn
t
y-|��}Ynwt|j
|�|_
|S)z
    Sysconfig wrapper.
    �	sysconfigT)rr�r
rrjZget_config_varr}Zget_config_varsZ_PIP_USE_SYSCONFIGZget_default_scheme�AttributeErrorZ_get_default_schemer�Z	get_paths)rr$ryr�r%r%r&�wrap_sysconfigks

�r�cCs(t�|�}tt|�}t|jj�|j_|S)z&
    pip.distlib.scripts wrapper.
    )rr�r
rreZScriptMaker�rr$ryr%r%r&�wrap_pip_distlib_scripts~s

r�cCs(t�|�}tt|�}t|jj�|j_|S)z$
    distutils.command wrapper.
    )rr�r
rr�Z	build_extZfinalize_optionsr�r%r%r&�wrap_distutils_command�s

�r�cC�$t�|�}tt|�}t|j�|_|S)z9
    pip._internal.operations.install.wheel wrapper.
    )rr�r
rr�Z
install_wheelr�r%r%r&�wrap_pip_install_wheel��

r�cCr�)z:
    pip._internal.operations.install.legacy wrapper.
    )rr�r
rr��installr�r%r%r&�wrap_pip_install_legacy�r�r��valuecCsX|tjvrtj||krtd|�d|�dtj|���dStd|���|tj|<dS)z�
    Set an environment variable if not already set.

    If the environment variable is already set and not equal to value, warn the
    user.
    z	Warning: z1 environment not set to relenv's root!
expected: z

current: zRelenv set N)r;rArCrF)rr�r%r%r&�set_env_if_not_set�s���r�cC�.t�|�}tt|�}ddd�}||j�|_|S)z1
    pip._internal.operations.build wrapper.
    rLr�rcst���d�fdd��}|S)NrNrrOrcs�tjdkr�|i|��St���}tt�jd�}|dus!|��s&td�n ttj�}d|�d|�d|�d�}t	d|�t	d|�t	d	|��|i|��S)
N�linux�cargo�,Unable to set CARGO_HOME no toolchain existsz-C link-arg=-Wl,-rpath,z/lib -C link-arg=-Lz/sysroot/libZ
CARGO_HOMEZOPENSSL_DIRZ	RUSTFLAGS)
rrJr1�
get_toolchainrZDATA_DIRrrrFrYr�)rNrO�	toolchain�
cargo_homeZ
relenvrootZ	rustflagsr`r%r&r��s"



���


z3wrap_pip_build_wheel.<locals>.wrap.<locals>.wrapper)rNrrOrrrrbr�r%r`r&�wrap�sz"wrap_pip_build_wheel.<locals>.wrapN�rLr�rr�)rr�r
rZbuild_wheel_pep517)rr$ryr�r%r%r&�wrap_pip_build_wheel�s



r�c@sBeZdZUdZdZded<dZded<dZded<dZded<dS)	rVz0
    Container for global pip target state.
    Fr�Nr��PATH�IGNORE�INSTALL)	r�r�r�r�rV�__annotations__r�r�r�r%r%r%r&rV�s
rVcCstjdur	td��tjS)zF
    Return the stored target path, raising if it is unavailable.
    Nz)TARGET path requested but not initialized)rVr��RuntimeErrorr%r%r%r&rW�s
rWcCsXt�|�}tt|�}d
dd�}||jj�|j_d
dd�}t|jd�r*||jj�|j_|S)zB
    Wrap pip install command to store target argument state.
    rLr�rcst���d	�fdd��}|S)
NrPr�optionsrN�
Sequence[str]rcs.|js|jrdt_|jt_|jt_�|||�S)NT)r�rUrVr��ignore_installedr�)rPrrNr`r%r&r��sz3wrap_cmd_install.<locals>.wrap_run.<locals>.wrapper)rPrrrrNrrrrbr�r%r`r&�wrap_run�sz"wrap_cmd_install.<locals>.wrap_runcSst�|�dd
d��}|S)
NrPrrUr�target_temp_dir�upgrader�r�intcSsddlm}|S)Nr)�SUCCESS)Zpip._internal.cli.status_codesr)rPrUrrrr%r%r&r�sz=wrap_cmd_install.<locals>.wrap_handle_target.<locals>.wrapper)
rPrrUrrrrr�rrrbr�r%r%r&�wrap_handle_targetsz,wrap_cmd_install.<locals>.wrap_handle_target�_handle_target_dirNr�)rr�r
rZInstallCommandrs�hasattrr
)rr$ryrr	r%r%r&�wrap_cmd_install�s



�rcCr�)zJ
    Wrap pip locations to fix locations when installing with target.
    rLr�rcs(t���					dd�fd
d�
�}|S)NF�	dist_namer�userr�r��Optional[PathType]r�r�r�rrc	sL�||||||�}tjr$tjr$ddlm}t�}||||j|j|jd�}|S)Nr)�Scheme)r�r��headersr^�data)rVr�Zpip._internal.models.schemerrWrr^r)	r
rr�r�r�r�r�rZtarget_pathr`r%r&r�s	�z<wrap_locations.<locals>.make_scheme_wrapper.<locals>.wrapper)FNNFN)r
rrr�r�rr�rr�r�r�rrrrbr�r%r`r&�make_scheme_wrappers�z+wrap_locations.<locals>.make_scheme_wrapperNr�)rr�r
rZ
get_scheme)rr$ryrr%r%r&�wrap_locationss



rcCs2t�|�}tt|�}ddd�}||jj�|j_|S)�5
    Honor ignore installed option from pip cli.
    rLr�rcs"t���		d
d�fdd	�
�}|S)NrPrr�session�
target_python�ignore_requires_pythonrcstjrtj|_�|||||�Sr�)rVr�r)rPrrrrr`r%r&r�HszFwrap_req_command.<locals>.make_package_finder_wrapper.<locals>.wrapperr�)rPrrrrrrrrrrrrbr�r%r`r&�make_package_finder_wrapperGs
�z5wrap_req_command.<locals>.make_package_finder_wrapperNr�)rr�r
rZRequirementCommandZ_build_package_finder)rr$ryrr%r%r&�wrap_req_command@s


�rcs
t�|�}tt|�}|jj��jj}|dkr/t�	��						dd�fdd�
�}||j_|S|dkrMt�	��							dd�fdd�
�}||j_|S|dkrkt�	��							dd �fdd�
�}||j_|St�	��							dd�fdd�
�}||j_|S)!r�NTFrPrr�rr�r�r�r�r�r�rcs8ztjr
dt_t�}�|||||||�Wdt_Sdt_w�NTF�rVr�rW)rPr�r�r�r�r�r��Zoriginalr%r&�install_wrapper_pep517hs
�
z0wrap_req_install.<locals>.install_wrapper_pep517�r�c	�:ztjr
dt_t�}�||||||||�Wdt_Sdt_wrr�rPr�r�r�r�r�r�r�rr%r&�install_wrapper_pep517_opts���z5wrap_req_install.<locals>.install_wrapper_pep517_opts�	r�c		
s<ztjr
dt_t�}�|||||||||�	Wdt_Sdt_wrr)	rPr�r�r�r�r�r�r�r�rr%r&�install_wrapper_legacy�s �z0wrap_req_install.<locals>.install_wrapper_legacyc	r!rrr"rr%r&�install_wrapper_generic�r$z1wrap_req_install.<locals>.install_wrapper_generic)NNNTFT)rPrr�rr�rr�rr�r�r�r�r�r�rr)NNNNTFT)rPrr�rr�rr�rr�rr�r�r�r�r�r�rr)rPrr�rr�rr�rr�rr�rr�r�r�r�r�r�rr)
rr�r
rZInstallRequirementr��__code__�co_argcountrcrd)rr$ryZargcountrr#r&r'r%rr&�wrap_req_install\sd

�c��C��!��r*r�zpip._vendor.distlib.scriptszdistutils.command.build_extz&pip._internal.operations.install.wheelz'pip._internal.operations.install.legacyz$pip._internal.operations.build.wheelzpip._internal.commands.installzpip._internal.locationszpip._internal.cli.req_commandzpip._internal.req.req_install)r�cs�tjdkrdSt���}|jd}t���}d}zt���}Wn	ty(Ynw|s1td�dS|�	�s;td�dS|j
ddd�|d�|d	krMd
�nd�|d|�d
�}d��fdd�}|�t|�krv��t
�d�j�|d��dSdS)z
    Setup cargo config.
    r�Nr�z3Unable to set CARGO_HOME ppbt package not installedr�T)�parents�exist_okzconfig.tomlzx86_64-linux-gnuzx86_64-unknown-linux-gnuzaarch64-unknown-linux-gnurRz-gccr�
str | Nonecs����sdSz���}Wn
tyYdSwd��d�}||vr#dS|��D] }|��}|�d�rG|�d�\}}}|���d�}|rG|Sq'dS)Nz[target.�]�linker�=�")rr�	read_text�OSErrorr�rur��	partition)�contentsZmarkerr��stripped�_Z
value_partZ	value_str�Zcargo_configZ
cargo_tripletr%r&�existing_linkers&�
�z-install_cargo_config.<locals>.existing_linkerzK            [target.{triplet}]
            linker = "{linker}"
            )�tripletr/)rr-)rrJr1Z	work_dirsrZget_tripletr��PermissionErrorrFrr�mkdirr�
write_text�textwrap�dedentr5)�dirsr�r:r�rkr9r%r8r&�install_cargo_config�sB



�����rAcCsPtjdkrdSt�d�}|s3td�tttjdd��td�dkr'td	�td
�dkr1td�dSdt	j
vr�tj|d
dgddddd�}|j
dkr\d}|jrW|d|j��7}t|�n/z|j�dd�\}}Wntyutd�YdSw|���d�}t|�td�dkr�td�tttjdd��td�dkr�td	�td
�dkr�td�dt	j
v�r"tj|d
dgddddd�}|j
dkr�d}|jr�|d|j��7}t|�dSz|j�dd�\}}Wnty�td�YdSwt�|���d��}t	j
�d��s	t|d�t	j
d<|d}|���r$t	j
�d ��s&t|�t	j
d <dSdSdSdS)!z2
    Configure openssl certificate locations.
    rHNZopensslz/Could not find the 'openssl' binary in the pathr�zossl-modules�defaultrz+Unable to load the default openssl providerZlegacyz*Unable to load the legacy openssl providerZOPENSSL_MODULESr�z-mTF)Zuniversal_newlines�shellZcheckrqz0Unable to get the modules directory from opensslz: �:r�zUnable to parse modules dirr1Zfipsz(Unable to load the fips openssl providerZSSL_CERT_DIRz-dz5Unable to get the certificates directory from opensslzUnable to parse openssldirZcertszcert.pemZ
SSL_CERT_FILE)rrJrr�rF�set_openssl_modules_dirrrY�load_openssl_providerr;rArrs�
returncode�stderrrDr�r[rur-r.rBrr)Zopenssl_bin�proc�msgr7Z	directoryrZ	cert_filer%r%r&�
setup_openssl<s�


�

��
��rKcCsltjdkrttjdd�}n	ttjdd�}t�|�}tj}|j}|tjf|_	tj
|_|d|���dS)z>
    Set the default search location for openssl modules.
    �darwinr��libcrypto.dylib�libcrypto.soN)
rrJrrYr�CDLL�c_void_p�%OSSL_PROVIDER_set_default_search_path�c_char_p�argtypes�c_int�restyper\)r�
cryptopath�	libcrypto�
POSSL_LIB_CTXrQr%r%r&rE�s

�rErcCsptjdkrttjdd�}n	ttjdd�}t�|�}tj}|j}|tjf|_	tj
|_|d|���}t
|�S)z!
    Load an openssl module.
    rLr�rMrNN)rrJrrYrrOrP�OSSL_PROVIDER_loadrRrSrTrUr\r)rrVrWrXrY�resultr%r%r&rF�s

rFcCs�tj�dd�}|rLt�|���}t|�t_t|�t_	dtj
j�dtj
j��}t|d|�t|d|d�t|d|d�gdd	�tj
D�t_
d
Sd
S)z%
    Setup cross root if needed.
    ZRELENV_CROSSrlr��.r�zlib-dynloadr�cSsg|]}d|vr|�qS)r�r%)�.0r7r%r%r&�
<listcomp>�sz#setup_crossroot.<locals>.<listcomp>N)r;rArBr-r.rIrrr�r�r6�major�minorr)ZcrossZ	crossrootZpyverr%r%r&�setup_crossroot�s

�
��r`�Callable[[], Any]�Callable[[], None]cst���d�fdd��}|S)z�
    Wrap site.execsitecustomize.

    This allows relenv a hook to be the last thing that runs when pythong is
    setting itself up.
    rr@c
s���d}zddl}|}Wnty%}z|jdkr�WYd}~nd}~ww|dus/d|jvrRtjdd�}t��tj�tjdd�<td|���tdtj���ntd�dt	_
td�dS)	Nr�
sitecustomizez
pip-build-envzoriginal sys.path was znew sys.path is zSkip path mungingFzAfter site customize wrapper)rcrrr/rrr1Zsanitize_sys_pathrFr�ENABLE_USER_SITE)Zsitecustomize_moduleZ_sitecustomize�excZ_origr`r%r&r��s(
���	
z"wrapsitecustomize.<locals>.wrapperN�rr@rbr�r%r`r&�wrapsitecustomize�srgcCsbtjddtddd�t�t_t�ttj	�t_	t
�t�tgtj
t_
tjdkr/td�dSdS)	z+
    Bootstrap the relenv environment.
    �ignorez.*falling back to find_module.*zimportlib._bootstrapi�)�message�categoryr$�lineno)��
r�N)r�filterwarnings�
ImportWarningrKrrYrKrgr�execsitecustomizer`rA�importer�	meta_pathr6r�r%r%r%r&�	bootstrap�s �
�rs)rrrrrr)rr)rr)r9rrr:)r?rrr@)rrG)rLrMrNrrOrrrM)rLrfrrf)rrn)rLrxryrrrx)rLr~rrrr~r�)rrrr)rrr�rrr@rf)rrrr@)rrrr)rLrarrb)Yr�Z
__future__r�
contextlibrZ_ctypesrcrZ
_importlibrZ_jsonr;r-rZ_shutilrZ_siterZ_subprocessr�_sysr>r�	_warningsZimportlib.machineryr�typesr�typingrrrrr	r
rrr
�__all__r�PathLikerrnr'r)r�r*r+r1r3r4r7�contextmanagerr>rFrKrerjrorprwr}r�r�r�r�r�r�r�r�r�r�r�r�r�rVrWrrrr*rqrArKrErFr`rgrsr%r%r%r&�<module>s�
,




















#�


"


>^ 
N








"

	
'
*

��

D
V


+