
    .~hi                         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j                  e
      Z	 	 	 ddZ	 	 	 	 d	dZd Zy)
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                 V    d| z  }t        j                  d       t        ||||       y)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_patternss         S/var/www/peopleoo.sandbox-dev.co.uk/venv/lib/python3.12/site-packages/lml/loader.pyscan_pluginsr      s5    N &.MMI 3)	    c                     t         j                  d       |g }|g } fdt        j                         D        }t	         |      }t        |||      }|D ]+  }||v rt         j                  d|z           	 t        |       - t         j                  d       y# t        $ r4}t         j                  |       t         j                  |       Y d}~|d}~ww xY w)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   d   K   | ]'  }|d    r t        j                  |d         r|d    ) yw)      N)rematch).0module_infor   s     r   	<genexpr>z%scan_plugins_regex.<locals>.<genexpr>s   s6      q>bhh';[^L 	As   -0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es	   `        r   r   r   J   s    B II'(

"//1L %:.%! 3ZK # *$IIj;./	k" IIo	  	IIk"IIaL	s   8B	C$*CCc              #      K   t               }d t        t        j                  |      D        D ]  }||z  }	 |D ]"  }d|v rt	        j
                  | |      s| $ yw)z+
    Discover plugins from pyinstaller
    c              3   L   K   | ]  }t        |d       r|j                    yw)tocN)hasattrr(   )r   importers     r   r   z(scan_from_pyinstaller.<locals>.<genexpr>   s&      8U# 	s   "$.N)setmapr   get_importerr   r   )r   pathtable_of_contenta_tocr$   s        r   r   r      st      uG00$7 "
 	E!" ( +88(+6	s   AA A )NNN)NNNN)__doc__r   loggingr   r
   	itertoolsr   	lml.utilsr   	getLogger__name__r   r   r   r    r   r   <module>r9      s[   
 
     g! 0h 	DXr   