U
    [ei                     @   sf   d Z ddlZddlZddlZddlZddlmZ ddlmZ e	e
ZdddZdddZd	d
 ZdS )aw  
    lml.loader
    ~~~~~~~~~~~~~~~~~~~

    Plugin discovery module. It supports plugins installed via pip tools
    and pyinstaller. :func:`~lml.loader.scan_plugins` is expected to be
    called in the main package of yours at an earliest time of convenience.

    :copyright: (c) 2017-2020 by Onni Software Ltd.
    :license: New BSD License, see LICENSE for more details
    N)chain)	do_importc                 C   s&   d|  }t d t||||d dS )a  
    Implicitly discover plugins via pkgutil and pyinstaller path

    Parameters
    -----------------

    prefix:string
      module prefix. This prefix should become the prefix of the module name
      of all plugins.

      In the tutorial, robotchef-britishcuisine is a plugin package
      of robotchef and its module name is 'robotchef_britishcuisine'. When
      robotchef call scan_plugins to load its cuisine plugins, it specifies
      its prefix as "robotchef_". All modules that starts with 'robotchef_'
      will be auto-loaded: robotchef_britishcuisine, robotchef_chinesecuisine,
      etc.

    pyinstaller_path:string
       used in pyinstaller only. When your end developer would package
       your main library and its plugins using pyinstaller, this path
       helps pyinstaller to find the plugins.

    black_list:list
       a list of module names that should be skipped.

    white_list:list
       a list of modules that comes with your main module. If you have a
       built-in module, the module name should be inserted into the list.

       For example, robot_cuisine is a built-in module inside robotchef. It
       is listed in white_list.
    z^%s.+$z?Deprecated! since version 0.0.3. Please use scan_plugins_regex!)plugin_name_patternspyinstaller_path
black_list
white_listN)warningswarnscan_plugins_regex)prefixr   r   r   r   Z__plugin_name_patterns r   L/var/www/html/services/stratfitenv/lib/python3.8/site-packages/lml/loader.pyscan_plugins   s    'r   c           	         s   t d |dkrg }|dkr"g } fddt D }t |}t|||}|D ]h}||krnt d|  qRzt| W qR tk
r } z t | t | W Y qRW 5 d}~X Y qRX qRt d dS )ak  
    Implicitly discover plugins via pkgutil and pyinstaller path using
    regular expression

    Parameters
    -----------------

    plugin_name_patterns: python regular expression
       it is used to match all your plugins, either it is a prefix,
       a suffix, some text in the middle or all.

    pyinstaller_path:string
       used in pyinstaller only. When your end developer would package
       your main library and its plugins using pyinstaller, this path
       helps pyinstaller to find the plugins.

    black_list:list
       a list of module names that should be skipped.

    white_list:list
       a list of modules that comes with your main module. If you have a
       built-in module, the module name should be inserted into the list.

       For example, robot_cuisine is a built-in module inside robotchef. It
       is listed in white_list.
    zscanning for plugins...Nc                 3   s.   | ]&}|d  rt  |d r|d V  qdS )      N)rematch).0Zmodule_infor   r   r   	<genexpr>s   s    z%scan_plugins_regex.<locals>.<genexpr>zignored zscanning done)logdebugpkgutiliter_modulesscan_from_pyinstallerr   r   ImportError)	r   r   r   r   Zmodule_namesZmodule_names_from_pyinstallerZall_modulesmodule_nameer   r   r   r
   J   s8    !

   

r
   c                 c   sT   t  }dd ttj|D D ]}||O }q|D ] }d|kr<q.t| |r.|V  q.dS )z+
    Discover plugins from pyinstaller
    c                 s   s   | ]}t |d r|jV  qdS )tocN)hasattrr   )r   importerr   r   r   r      s   
z(scan_from_pyinstaller.<locals>.<genexpr>.N)setmapr   get_importerr   r   )r   pathZtable_of_contentZa_tocr   r   r   r   r      s    


r   )NNN)NNNN)__doc__r   loggingr   r   	itertoolsr   Z	lml.utilsr   	getLogger__name__r   r   r
   r   r   r   r   r   <module>   s"   
   
4    
L