U
    -c                     @   s   d dl Z d dlZd dlZddlmZ ddlmZ ddlmZ ddl	m
Z
 ddlmZ ddlmZ d	d
 Zdd Zdd Ze
jdddZe jdd Zeedd Zeeddd  ee
jdddZdd ZdS )    N   )OptionError)yield_lines)	pass_none)metadata)ensure_unique)consumec              
   C   sH   z
| j  W n8 tk
rB } zd|  d}t||W 5 d}~X Y nX dS )zR
    Exercise one of the dynamic properties to trigger
    the pattern match.
    zProblems to parse zq.
Please ensure entry-point follows the spec: https://packaging.python.org/en/latest/specifications/entry-points/N)extrasAttributeErrorr   )epexmsg r   </tmp/pip-unpacked-wheel-izj_87as/setuptools/_entry_points.pyensure_valid   s    

r   c                 C   s*   t | }d| dd| }tj|S )zf
    Given a value of an entry point or series of entry points,
    return each as an EntryPoint.
    []

)r   joinr   EntryPoints
_from_text)valuegrouplinestextr   r   r   
load_group   s    r   c                 C   s   | j | jfS N)r   name)r   r   r   r   by_group_and_name'   s    r   epsc                 C   s   t ttt| td | S )zM
    Ensure entry points are unique by group and name and validate each.
    key)r   mapr   r   r   r   r   r   r   validate+   s    r$   c                 C   s(   t jdd |  D }tt|S )zA
    Given a Distribution.entry_points, produce EntryPoints.
    c                 s   s   | ]\}}t ||V  qd S r   )r   ).0r   r   r   r   r   	<genexpr>8   s   zload.<locals>.<genexpr>)	itertoolschainfrom_iterableitemsr$   r   r   )r    groupsr   r   r   load3   s    r,   c                 C   s   t ttj| S )z
    >>> ep, = load('[console_scripts]\nfoo=bar')
    >>> ep.group
    'console_scripts'
    >>> ep.name
    'foo'
    >>> ep.value
    'bar'
    )r$   r   r   r   r   r   r   r   _>   s    r-   c                 C   s   | S r   r   )xr   r   r   <lambda>L       r/   c                 C   s2   t d}tt| |d|}ddd |D S )Nr   r!   r   c                 s   s(   | ] \}}d | dt | dV  qdS )r   r   r   N)render_items)r%   r   r*   r   r   r   r&   T   s   zrender.<locals>.<genexpr>)operator
attrgetterr'   groupbysortedr   )r    Zby_groupr+   r   r   r   renderO   s
    

r6   c                 C   s   d dd t| D S )Nr   c                 s   s    | ]}|j  d |j V  qdS )z = N)r   r   )r%   r   r   r   r   r&   [   s   zrender_items.<locals>.<genexpr>)r   r5   r   r   r   r   r1   Z   s    
r1   )	functoolsr2   r'   errorsr   Zextern.jaraco.textr   Zextern.jaraco.functoolsr   Z
_importlibr   
_itertoolsr   Zextern.more_itertoolsr   r   r   r   r   r$   singledispatchr,   registerstrr-   typer6   r1   r   r   r   r   <module>   s(   



