o
    k¨Êhi  ã                   @   st   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-2018 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   Ú__plugin_name_patterns© r   ú</var/www/html/env/lib/python3.10/site-packages/lml/loader.pyÚscan_plugins   s   'ÿ
ür   c           	         sÂ   t  d¡ |du rg }|du rg }‡ fdd„t ¡ D ƒ}tˆ |ƒ}t|||ƒ}|D ]0}||v r7t  d| ¡ q)zt|ƒ W q) tyY } zt  |¡ t  |¡ W Y d}~q)d}~ww t  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   s0   � | ]}|d  rt  ˆ |d ¡r|d V  qdS )é   é   N)ÚreÚmatch)Ú.0Ú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   Úmodule_namesÚmodule_names_from_pyinstallerÚall_modulesÚmodule_nameÚer   r   r   r
   J   s6   
!
þÿÿ

€ýr
   c                 c   sV   � t ƒ }dd„ ttj|ƒD ƒD ]}||O }q|D ]}d|v 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   ÚpathÚtable_of_contentÚa_tocr!   r   r   r   r   –   s   €

þ
€ür   )NNN)NNNN)Ú__doc__r   Úloggingr   r   Ú	itertoolsr   Ú	lml.utilsr   Ú	getLoggerÚ__name__r   r   r
   r   r   r   r   r   Ú<module>   s$    

û4
üL