
    kjA                         d Z ddlZddlmZ ddlmZmZ ddlmZ ddl	m
Z
 ddlmZ ddlmZ dd	lmZ  G d
 d          ZdS )z
Base registry class
    N)	lru_cache)Any	Generator)settings)ImproperlyConfigured)
BaseLoader)ResourceDescription)import_stringc                   $   e Zd ZdZdZ	 ddZedefd            Zede	e
e         ddf         fd            Z ed          d	ede
e         fd
            ZdedefdZdeddfdZde	eeef         ddf         fdZdeddfdZdeddfdZdS )BaseRegistryz!Base class for all resource pools returnNc                     g | _         dS )zInitialize internal attributesN)
_resourcesselfs    Y/home/agentuser/manim-venv/lib/python3.11/site-packages/moderngl_window/resources/base.py__init__zBaseRegistry.__init__   s    57    c                 *    t          | j                  S )zxint: The number of resource descriptions added.
        This is only relevant when using `add` and `load_pool`.
        )lenr   r   s    r   countzBaseRegistry.count   s    
 4?###r   c              #   r   K   t          t          | j                  D ]}|                     |          V  dS )z0Generator: Loader classes for this resource typeN)getattrr   settings_attr_loader_cls)r   loaders     r   loaderszBaseRegistry.loaders#   sK       h(:;; 	+ 	+F""6******	+ 	+r   )maxsizepython_pathc                 h    t          |          }t          |t                    sJ | d            |S )Nz does not lead to a Loader)r
   
issubclassr   )r   r    clss      r   r   zBaseRegistry._loader_cls)   s;    K((#z**VV{,V,V,VVV*
r   metac                     |                      |           |                     |           |                    |          }|J d| d            |                                S )z
        Loads a resource using the configured finders and loaders.

        Args:
            meta (ResourceDescription): The resource description
        NzCould not load z!, no arributes named 'loader_cls')_check_metaresolve_loader
loader_clsload)r   r$   r#   s      r   r)   zBaseRegistry.load/   sf     	D!!!ood## Y$ Y Y Yxxzzr   c                     |                      |           |                     |           | j                            |           dS )z
        Adds a resource description without loading it.
        The resource is loaded and returned when ``load_pool()`` is called.

        Args:
            meta (ResourceDescription): The resource description
        N)r&   r'   r   appendr   r$   s     r   addzBaseRegistry.add<   sH     	D!!!t$$$$$r   c              #   b   K   | j         D ]}|                     |          }||fV  g | _         dS )z
        Loads all the data files using the configured finders.

        This is only relevant when resource have been added to this
        pool using ``add()``.

        Returns:
            Generator of (meta, resource) tuples
        N)r   r)   )r   r$   resources      r   	load_poolzBaseRegistry.load_poolH   sF       O 	! 	!DyyH.    r   c                 ^   |j         r\| j        D ]}|j         |j         k    r
||_         dS t          d                    |j         |d | j        D                                 | j        D ]!}|                    |          r
||_         dS "t          d                    |                    )z
        Attempts to assign a loader class to a ResourceDescription.

        Args:
            meta (:py:class:`~moderngl_window.meta.base.ResourceDescription`):
            The resource description instance
        Nz?Resource has invalid loader kind '{}': {}
Available loaders: {}c                     g | ]	}|j         
S  )kind).0r   s     r   
<listcomp>z/BaseRegistry.resolve_loader.<locals>.<listcomp>i   s    %M%M%Mffk%M%M%Mr   zCould not find a loader for: {})r4   r   r(   r   formatsupports_file)r   r$   r(   s      r   r'   zBaseRegistry.resolve_loaderX   s     9 
	"l  
?di//&0DOFF 0 'RYYIt%M%M%M%M%M    , 	 	J''-- ", ##D#K#KD#Q#QRRRr   c                     t          j        t          |                    rt          |j        t
                    rdS t          d                    t          |                              )zCheck is the instance is a resource description
        Raises:
            ImproperlyConfigured if not a ResourceDescription instance
        Nz7Resource loader got type {}, not a resource description)inspectisclasstyper"   	__class__r	   r   r7   r,   s     r   r&   zBaseRegistry._check_metau   s`    
 ?4::&& 	$.*=>> "ELLTRVZZXX
 
 	
r   )r   N)__name__
__module____qualname____doc__r   r   propertyintr   r   r<   r   r   r   strr   r	   r   r)   r-   tupler0   r'   r&   r3   r   r   r   r      s       ++M8 8 8 8 $s $ $ $ X$ +4
#3T4#?@ + + + X+
 Yts tJ/?    
,     
%+ 
% 
% 
% 
% 
%9U+>+C%DdD%PQ     S#6 S4 S S S S:
 
 
 
 
 
 
 
r   r   )rA   r:   	functoolsr   typingr   r   moderngl_window.confr   moderngl_window.exceptionsr   moderngl_window.loaders.baser   moderngl_window.meta.baser	   $moderngl_window.utils.module_loadingr
   r   r3   r   r   <module>rM      s            ! ! ! ! ! ! ! ! ) ) ) ) ) ) ; ; ; ; ; ; 3 3 3 3 3 3 9 9 9 9 9 9 > > > > > >p
 p
 p
 p
 p
 p
 p
 p
 p
 p
r   