
    +d%                         d dl Z d dlZd dlZd dlZd dlZd dlZd dlZd dlZddlm	Z	  ej
        d          Z G d d          Z e            Zd Zdd	Zd
 Zd Z G d de          ZdS )    N   confintakec                        e Zd ZdZddZed             Zej        d             Zd Zd Z	 fdZ
 fd	Zed
             Zd Zd Zd ZddZd ZddZd Z xZS )DriverSouceszJ
    Handles the various ways in which drivers can be known to Intake
    Nc                 h    |pt           | _         || _        d| _        d| _        d| _        d| _        dS )a  

        Parameters
        ----------
        config: intake.config.Config oinstance, optional
            If not given, will use ``intake.config.conf`` singleton
        do_scan: bool or None
            Whether to scan packages with names ``intake_*`` for valid drivers.
            This is for backward compatibility only. If not given, value comes
            from the config key "package_scan", default False.
        N)r   do_scan_scanned_entrypoints_registered	_disabled)selfconfigr
   s      7lib/python3.11/site-packages/intake/source/discovery.py__init__zDriverSouces.__init__   s8     Nd	     c                 T    | j         | j                            dd          n| j         S )Npackage_scanF)r
   r   getr   s    r   r   zDriverSouces.package_scan/   s(    7;|]ty}}^U333QUQ]]r   c                     || j         d<   d S )Nr   r   )r   vals     r   r   zDriverSouces.package_scan3   s    $'	.!!!r   c                 j    | j         &t          t          j        d                    | _         | j         S )Nzintake.drivers)r   listentrypointsget_group_allr   s    r   from_entrypointszDriverSouces.from_entrypoints7   s3     	R $[%>?O%P%P Q QD  r   c                 p    d | j                             di                                           D             S )Nc           
      .   g | ]\  }}|t          j        |d |v r|                    d d          d         n|                    dd          d         d |v r|                    d d          d         n|                    dd          d                   S ):   r   .)namemodule_nameobject_name)r   
EntryPointrsplit.0kvs      r   
<listcomp>z*DriverSouces.from_conf.<locals>.<listcomp>>   s     
 
 
 1
"3!8$\AHHS!$4$4Q$7$7RUWXIYIYZ[I\  BE  IJ  BJ  kcjkjrjrsvxyjzjz{|j}j}  PQ  PX  PX  Y\  ^_  P`  P`  ab  Pc  
 
 
r   drivers)r   r   itemsr   s    r   	from_confzDriverSouces.from_conf=   sA    
 
 	i44::<<	
 
 
 	
r   c                     t          t          |                               ||           |                                  d S N)superr   __setitem__save)r   keyvalue	__class__s      r   r4   zDriverSouces.__setitem__F   s4    lD!!--c5999		r   c                     t          t          |                               |           |                                  d S r2   )r3   r   __delitem__r5   )r   r6   r8   s     r   r:   zDriverSouces.__delitem__J   s2    lD!!--c222		r   c                 D    | j         t                      | _         | j         S r2   )r   _package_scanr   s    r   scannedzDriverSouces.scannedN   s!     = 	,)OODM}r   c                     | j         <d | j                            di                                           D             | _         | j         S )Nc                      h | ]\  }}|d u 	|S )F r)   s      r   	<setcomp>z(DriverSouces.disabled.<locals>.<setcomp>X   s(    ___DAqTUY^T^_a___r   r.   )r   r   r   r/   r   s    r   disabledzDriverSouces.disabledV   sF    > 	`__DIMM)R,H,H,N,N,P,P___DN~r   c                     | j         `i }| j        r|                    | j                   |                                 |                                 z   D ]}|||j        <   || _         | j         S r2   )r   r   updater=   r   r0   r$   )r   outeps      r   
registeredzDriverSouces.registered\   sy     	#C  )

4<(((++--0@0@@ " "!BG"Dr   c                 h      fd                                                                  D             S )Nc                 H    i | ]\  }}|                                 v||S r@   )rB   )r*   r+   r,   r   s      r   
<dictcomp>z0DriverSouces.enabled_plugins.<locals>.<dictcomp>k   s1    WWWAat}}>VW1WWWr   )rG   r/   r   s   `r   enabled_pluginszDriverSouces.enabled_pluginsj   s3    WWWW!2!2!8!8!:!:WWWWr   Fc                 B   t          |          }||                                 v r|st          d| d          ||                                 v r7|r|                     ||           nt
                              d| d           ||                                 |<   dS )a  Add runtime driver definition to list of registered drivers (drivers in global scope with corresponding ``intake.open_*`` function)

        Parameters
        ----------
        name: str
            Name of the driver
        value: str, entrypoint or class
            Pointer to the implementation
        clobber: bool
            If True, perform the operation even if the driver exists
        do_enable: bool
            If True, unset the disabled flag for this driver
        zDriver z already enabledzAdding driver z, but it is disabledN)
_normalizerG   
ValueErrorrB   enableloggerwarning)r   r$   r7   clobber	do_enables        r   register_driverzDriverSouces.register_driverm   s     $4??$$$ 	?W 	?=t===>>>4==??" 	L LD%((((JJJJKKK"'$r   c                 r    t          |          }|                                                     |           dS )z Remove runtime registered driverN)rM   rG   pop)r   r$   s     r   unregister_driverzDriverSouces.unregister_driver   s3    $d#####r   c                 0   | j         }d|vri |d<   |r||d         |<   n&|d                             |          du r	|d         |= ||                                 v r'|                                                     |           |                                 dS )a  
        Explicitly assign a driver to a name, or remove ban

        Updates the associated config, which will be persisted

        Parameters
        ----------
        name : string
            As in ``'zarr'``
        driver : string
            Dotted object name, as in ``'intake_xarray.xzarr.ZarrSource'``.
            If None, simply remove driver disable flag, if it is found
        r.   FN)r   r   rB   remover5   )r   r$   driverr   s       r   rO   zDriverSouces.enable   s     F" 	# "F9 	(&,F9d##I""4((E1 	(y!$'4==??" 	)MMOO""4(((r   c                     t          |          }| j        }d|vri |d<   d|d         |<   |                                 |                                                     |           dS )zDisable a driver by name.

        Updates the associated config, which will be persisted

        Parameters
        ----------
        name : string
            As in ``'zarr'``
        r.   FN)rM   r   r5   rB   add)r   r$   r   s      r   disablezDriverSouces.disable   sm     $F" 	# "F9"'y$D!!!!!r   )NN)FFr2   )__name__
__module____qualname____doc__r   propertyr   setterr   r0   r4   r:   r=   rB   rG   rK   rT   rW   rO   r]   __classcell__)r8   s   @r   r   r      s[           & ^ ^ X^ ( ( (! ! !
 
 
           X       X X X( ( ( (2$ $ $
   2" " " " " " "r   r   c           
          	 |                                  S # t          $ r&}t          d| j         d| j         d          |d}~wt
          $ r.}t          d| j         d| j         d| j         d          |d}~ww xY w)zQ
    Call entrypoint.load() and, if it fails, raise context-specific errors.
    zFailed to load z driver because module z could not be imported.Nz  driver because no object named z could be found in the module r#   )loadImportErrorConfigurationErrorr$   r%   AttributeErrorr&   )
entrypointerrs     r   _load_entrypointrl      s    	    Y Y Y   "O:?  "O  "O_i_u  "O  "O  "O  P  P  VY  	Y    )jo ) )+) )%) ) )
 
 		s     
A<!AA<)A77A<intake_c                 ,   t          j        dt                     i }t          j        |           D ]\  }}}|                    |          rt          j                    }t          |          }|                                D ][\  }}	||v rMt          j
        ||                   }
t          j
        |	          }t          j        d|d|
d|d           V|	||<   \t                              d|t          j                    |z
  fz             |S )	ar  Scan for intake drivers and return a dict of plugins.

    This searches path (or sys.path) for packages with names that start with
    plugin_prefix.  Those modules will be imported and scanned for subclasses
    of intake.source.base.Plugin.  Any subclasses found will be instantiated
    and returned in a dictionary, with the plugin's name attribute as the key.
    zPackage scanning may be removed)category)pathzPlugin name collision for "z" from
    z	
and
    z$
Keeping plugin from first location.zImport %s took: %7.2f s)warningswarnPendingDeprecationWarningpkgutiliter_modules
startswithtimeload_plugins_from_moduler/   inspectgetfilerP   debug)rp   plugin_prefixpluginsimporterr$   ispkgtnew_pluginsplugin_nameplugin	orig_pathnew_paths               r   r<   r<      s=    M3>WXXXXG!(!54!@!@!@ N N$??=)) 	N	A2488K'2'8'8':': 2 2#V') 2 '0D E EI&v66HMM
 DO;;PYPYPY[c[c[c	e    ,2GK((LL2dDIKK!O5LLMMMNr   c                     |                                  st          j        dd|           } |                                  st          j        d| d           | S )Nz
[-=~^&|@+]_z&Invalid Intake plugin name "%s" found.r   )
stacklevel)isidentifierresubrq   rr   )r$   s    r   rM   rM      s\     /vlC.. T>QRSSSSKr   c                    ddl m} ddlm} i }	 	 t	          j        |           }n8# t          $ r+}|                     d          rt          d          | d}~ww xY wnG# t          $ r:}t          
                    d                    | |                     i cY d}~S d}~ww xY wt          j        |t          j                  D ]!\  }}t          |||f          r
|||j        <   "|S )zImports a module and returns dictionary of discovered Intake plugins.

    Plugin classes are instantiated and added to the dictionary, keyed by the
    name attribute of the plugin object.
    r   )Catalog)
DataSourcez.pyzIntake formerly supported executing arbitrary Python files not on the sys.path. This is no longer supported. Drivers must be specific with a module path like 'package_name.module_name, not a Python filename like 'module.py'.NzImport module <{}> failed: {})intake.catalogr   intake.sourcer   	importlibimport_modulerg   endswith	ExceptionrP   r{   formatry   
getmembersisclass
issubclassr$   )	r%   r   r   r}   moderrorer   clss	            r   rx   rx      sF    '&&&&&((((((G	)+66CC 	 	 	##E**  "#   	     4;;KKKLLL						 $S'/:: $ $3cGZ011 	$ #GCHNs7   & A 
A&AAA 
B#)/BB#B#c                       e Zd ZdS )rh   N)r^   r_   r`   r@   r   r   rh   rh     s        Dr   rh   )Nrm   )r   ry   loggingrt   r   rw   rq   r   r   r   	getLoggerrP   r   r.   rl   r<   rM   rx   r   rh   r@   r   r   <module>r      s.          				            		8	$	$]" ]" ]" ]" ]" ]" ]" ]"@ ,..      D  # # #L	 	 	 	 	 	 	 	 	 	r   