a
    ©ˆcƒ  ã                   @   sH   d Z ddlZddlmZ ddd„Zdd„ Zdd	„ Zdd
d„Zdd„ ZdS )z1 Utility functions for working with Python Eggs. é    N)Útopological_sortc                 C   sV   t  |¡}|  |¡\}}t|ƒdkr>|r2||ƒ ntd| ƒ‚|D ]}|  |¡ qBdS )z2 Add all eggs found on the path to a working set. r   zCannot find eggs %sN)Úpkg_resourcesÚEnvironmentÚfind_pluginsÚlenÚSystemErrorÚadd)Úworking_setÚpathZon_errorÚenvironmentÚdistributionsÚerrorsÚdistribution© r   úU/home/yuhw/wc/wire-cell-python/wcpy/lib/python3.9/site-packages/envisage/egg_utils.pyÚadd_eggs_on_path   s    

r   c                 C   sB   t | |ƒ}t| |ƒ}g }|D ] }| |¡}| t| ¡ ƒ¡ q|S )z. Return entry points in Egg dependency order. )Ú"get_distributions_with_entry_pointÚget_distributions_in_egg_orderÚget_entry_mapÚextendÚlistÚvalues)r	   Úentry_point_namer   Zentry_pointsr   Z	entry_mapr   r   r   Úget_entry_points_in_egg_order(   s    ÿ

r   c                 C   s.   g }| D ] }t | |¡ƒdkr| |¡ q|S )zB Return all distributions that contribute to an entry point.

    r   )r   r   Úappend)r	   r   r   r   r   r   r   r   <   s
    r   c                 C   sJ   |du r| }i }|D ] }|  |g ¡}| t| |ƒ¡ qt|ƒ}| ¡  |S )z3 Return all distributions in Egg dependency order. N)Ú
setdefaultr   Úget_requiresr   Úreverse)r	   r   Úgraphr   Zarcsr   r   r   r   I   s    r   c                 C   s8   g }|  ¡ D ]&}|  |¡}|dur| |  |¡¡ q|S )zE Return all of the other distributions that a distribution requires. N)ÚrequiresÚfindr   )r	   r   r   ÚrequirementÚrequiredr   r   r   r   ]   s    
r   )N)N)	Ú__doc__r   Ztraits.util.toposortr   r   r   r   r   r   r   r   r   r   Ú<module>
   s   

