File: //opt/osm/venv/lib64/python3.10/site-packages/setuptools/config/__pycache__/expand.cpython-310.pyc
o
0i�? � @ s� d Z ddlZddlZddlZddlZddlZddlZddlZddlm Z ddl
mZ ddlm
Z
ddlmZ ddlmZmZmZmZmZmZmZmZmZmZmZmZ ddlmZ dd lmZ dd
l m!Z! ddl"m#Z$ er~dd
l%m&Z& ddl'm(Z( ddl)m*Z* ej+Z,ee-ej.f Z/ed�Z0eddd�Z1G dd� d�Z2 dQdee- dee/ dee- fdd�Z3dQdee-e4ee/ f de-fdd�Z5dee/ dee/ fdd�Z6d ee4e/f de-fd!d"�Z7d e/de-fd#d$�Z8 dRd%e-d&eee-e-f dee/ fd'd(�Z9d)e-d*ee/ de
fd+d,�Z:d-e
d)e-defd.d/�Z;d)e-d&eee-e-f de/dee/ee- e-f fd0d1�Z< dRd2e-d&eee-e-f dee/ defd3d4�Z= dRd5ee-e-f d&eee-e-f dee/ dee-ef fd6d7�Z>dddd8�d9eee-e-f dee/ dee- fd:d;�Z?d<e/d=e/de-fd>d?�Z@d@eeeee-eAf e-f de-fdAdB�ZBdCeCdeCfdDdE�ZD dQdFeeEeCf dee/ deee-ee- f fdGdH�ZFdSdJe-dee-eCf fdKdL�ZGG dMdN� dN�ZHG dOdP� dPee0e1f �ZIdS )Tai Utility functions to expand configuration directives or special values
(such glob patterns).
We can split the process of interpreting configuration files into 2 steps:
1. The parsing the file contents from strings to value objects
that can be understand by Python (for example a string with a comma
separated list of keywords into an actual Python list of strings).
2. The expansion (or post-processing) of these values according to the
semantics ``setuptools`` assign to them (for example a configuration field
with the ``file:`` directive should be expanded from a list of file paths to
a single string with the contents of those files concatenated)
This module focus on the second step, and therefore allow sharing the expansion
functions among several configuration file formats.
**PRIVATE MODULE**: API reserved for setuptools internal usage only.
� N)�iglob)�ConfigParser)�
ModuleSpec)�chain)�
TYPE_CHECKING�Callable�Dict�Iterable�Iterator�List�Mapping�Optional�Tuple�TypeVar�Union�cast)�Path)�
ModuleType)�DistutilsOptionError� )� same_path)�Distribution)�ConfigDiscovery)�DistributionMetadata�_K�_VT)� covariantc @ sH e Zd ZdZdedefdd�Zdeee j
e j
f fdd�Zd d
� ZdS )�StaticModulez>Proxy to a module object that avoids executing arbitrary code.�name�specc C s. t �t�|j��� �}t| ��t� � | ` d S �N)
�ast�parse�pathlibr �origin�
read_bytes�vars�update�locals�self)r) r r �module� r+ �F/opt/osm/venv/lib/python3.10/site-packages/setuptools/config/expand.py�__init__B s zStaticModule.__init__�returnc # s\ � | j jD ]&� t� tj�r� fdd�� jD �E d H qt� tj�r+� jr+� j� jfV qd S )Nc 3 s � | ]}|� j fV qd S r ��value)�.0�target�Z statementr+ r, � <genexpr>J s � z1StaticModule._find_assignments.<locals>.<genexpr>) r* �body�
isinstancer! �Assign�targets� AnnAssignr0 r2 �r) r+ r3 r, �_find_assignmentsG s ���zStaticModule._find_assignmentsc
sL zt � fdd�| �� D ��W S ty% } zt| j� d� � ��|�d}~ww )zHAttempt to load an attribute "statically", via :func:`ast.literal_eval`.c 3 s4 � | ]\}}t |tj�r|j� krt�|�V qd S r )r6 r! �Name�id�literal_eval)r1 r2 r0 ��attrr+ r, r4 Q s �
�
��z+StaticModule.__getattr__.<locals>.<genexpr>z has no attribute N)�nextr; � Exception�AttributeErrorr )r) r@ �er+ r? r, �__getattr__N s
���zStaticModule.__getattr__N)
�__name__�
__module__�__qualname__�__doc__�strr r- r
r r! �ASTr; rE r+ r+ r+ r, r ? s
r �patterns�root_dirr. c s� h d�}g }� pt �� � | D ]<�t�fdd�|D ��r9t j�t j�� ���}|�t� fdd�t|dd�D ��� qt j� �� ��
t jd�}|�|� q|S )a Expand the list of glob patterns, but preserving relative paths.
:param list[str] patterns: List of glob patterns
:param str root_dir: Path to which globs should be relative
(current directory by default)
:rtype: list
> �]�{�?�}�*�[c 3 s � | ]}|� v V qd S r r+ )r1 �charr/ r+ r, r4 j s � z glob_relative.<locals>.<genexpr>c 3 s( � | ]}t j�|� ��t jd �V qdS )�/N)�os�path�relpath�replace�sep�r1 rW �rM r+ r, r4 m s
� �
�T)� recursiverU )
rV �getcwd�anyrW �abspath�join�extend�sortedr rX rY rZ �append)rL rM Zglob_charactersZexpanded_valuesZ glob_pathrW r+ )rM r0 r, �
glob_relativeZ s
�re � filepathsc sR ddl m} tj�� pt�� �� � fdd�|| �D �}d�� fdd�t|�D ��S )z�Return the content of the files concatenated using ``
`` as str
This function is sandboxed and won't reach anything outside ``root_dir``
(By default ``root_dir`` is the current directory).
r )�always_iterablec 3 s � | ]
}t j�� |�V qd S r )rV rW ra r[ r\ r+ r, r4 � s � zread_files.<locals>.<genexpr>�
c 3 s"