File: //usr/local/lib/python3.7/site-packages/setuptools/config/__pycache__/expand.cpython-37.pyc
B
N��g�? � @ sz d Z ddlZddlZddlZddlZddlZddlZddlmZ ddl m
Z
ddlmZ ddl
mZ ddlmZmZmZmZmZmZmZmZmZmZmZmZ ddlmZ dd lmZ dd
lm Z ddl!m"Z# dd
l$m%Z% e�rddl&m'Z' ddl(m)Z) ddl*m+Z+ ej,Z-ee.ej/f Z0ed�Z1eddd�Z2G dd� d�Z3dOee. ee0 ee. d�dd�Z4dPee.e5ee0 f e.d�dd�Z6ee0 ee0 d�dd�Z7ee5e0f e.d�d d!�Z8e0e.d"�d#d$�Z9dQe.eee.e.f ee0 d%�d&d'�Z:e.ee0 ed(�d)d*�Z;ee.ed+�d,d-�Z<e.eee.e.f e0ee0ee. e.f d.�d/d0�Z=dRe.eee.e.f ee0 ed1�d2d3�Z>dSee.e.f eee.e.f ee0 ee.ef d4�d5d6�Z?dddd7�eee.e.f ee0 ee. d8�d9d:�Z@e0e0e.d;�d<d=�ZAeeeee.eBf e.f e.d>�d?d@�ZCeDeDdA�dBdC�ZEdTeeFeDf ee0 eee.ee. f dD�dEdF�ZGdUe.ee.eDf dH�dIdJ�ZHG dKdL� dL�ZIG dMdN� dNee1e2f �ZJdS )Vai 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)�SetuptoolsWarning)�Distribution)�ConfigDiscovery)�DistributionMetadata�_K�_VT)� covariantc @ sF e Zd ZdZeed�dd�Zeee j
e j
f d�dd�Zdd � Zd
S )�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+ �</tmp/pip-unpacked-wheel-yrlplx0q/setuptools/config/expand.py�__init__B s zStaticModule.__init__)�returnc # s^ xX| j jD ]L� t� tj�r6� fdd�� jD �E d H q
t� tj�r
� jr
� j� jfV q
W d S )Nc 3 s | ]}|� j fV qd S )N)�value)�.0�target)� statementr+ r, � <genexpr>J s z1StaticModule._find_assignments.<locals>.<genexpr>) r* �body�
isinstancer! ZAssign�targetsZ AnnAssignr/ r1 )r) r+ )r2 r, �_find_assignmentsG s
zStaticModule._find_assignmentsc
sX yt � fdd�| �� D ��S tk
rR } zt| j� d� � ��|�W dd}~X Y nX dS )zHAttempt to load an attribute "statically", via :func:`ast.literal_eval`.c 3 s2 | ]*\}}t |tj�r|j� krt�|�V qd S )N)r5 r! �Name�id�literal_eval)r0 r1 r/ )�attrr+ r, r3 R s z+StaticModule.__getattr__.<locals>.<genexpr>z has no attribute N)�nextr7 � Exception�AttributeErrorr )r) r; �er+ )r; r, �__getattr__N s
zStaticModule.__getattr__N)
�__name__�
__module__�__qualname__�__doc__�strr r- r
r r! �ASTr7 r@ r+ r+ r+ r, r ? s r )�patterns�root_dirr. c s� ddddddh}g }� pt �� � x�| D ]x�t�fdd�|D ��r|t j�t j�� ���}|�t� fd d�t|d
d�D ��� q&t j� �� ��
t jd�}|�|� q&W |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 | ]}|� kV qd S )Nr+ )r0 �char)r/ r+ r, r3 j s z glob_relative.<locals>.<genexpr>c 3 s&