
    kj*                         d Z ddlZddlZddlZddlmZmZ ddlmZ ddl	m
Z ddlmZmZmZ ddlmZ ddlmZ d	Z G d
 d          Z e            ZdS )z
Bag of settings values
    N)	GeneratorIterable)pformat)
ModuleType)AnyOptionalUnion)default)ImproperlyConfiguredMODERNGL_WINDOW_SETTINGS_MODULEc                      e Zd ZU dZ e            Zeeef         ed<   	 dZ	e
e         ed<   	 g Zee         ed<   	 g Zee         ed<   	 g Zee         ed<   	 g Zee         ed<   	 g Zeeeej        f                  ed	<   	 g Zeeeej        f                  ed
<   	 g Zeeeej        f                  ed<   	 g Zeeeej        f                  ed<   	 g Zee         ed<   	 g Zee         ed<   	 g Zee         ed<   	 g Zee         ed<   	 d!dZd!dZd!dZdeddfdZdeeef         ddfdZde ddfdZ!deddfdZ"de#e$eef                  ddfdZ%deeef         fdZ&defd Z'dS )"SettingsaD  
    Bag of settings values. New attributes can be freely added runtime.
    Various apply* methods are supplied so the user have full control over how
    settings values are initialized. This is especially useful for more custom usage.
    And instance of the `Settings` class is created when the `conf` module is imported.

    Attribute names must currently be in upper case to be recognized.

    Some examples of usage::

        from moderngl_window.conf import settings

        # Mandatory settings values
        try:
            value = settings.VALUE
        except KeyError:
            raise ValueError("This settings value is required")

        # Fallback in code
        value = getattr(settings, 'VALUE', 'default_value')

        # Pretty printed string representation for easy inspection
        print(settings)
    WINDOWNSCREENSHOT_PATHPROGRAM_FINDERSTEXTURE_FINDERSSCENE_FINDERSDATA_FINDERSPROGRAM_DIRSTEXTURE_DIRS
SCENE_DIRS	DATA_DIRSPROGRAM_LOADERSTEXTURE_LOADERSSCENE_LOADERSDATA_LOADERSreturnc                 .    |                                   dS )z'Initialize settings with default valuesN)apply_default_settingsselfs    X/home/agentuser/manim-venv/lib/python3.11/site-packages/moderngl_window/conf/__init__.py__init__zSettings.__init__   s    ##%%%%%    c                 :    |                      t                     dS )ab  
        Apply keys and values from the default settings module
        located in this package. This is to ensure we always
        have the minimal settings for the system to run.

        If replacing or customizing the settings class
        you must always apply default settings to ensure
        compatibility when new settings are added.
        N)apply_from_moduler
   r    s    r"   r   zSettings.apply_default_settings   s     	w'''''r$   c                     t           j                            t                    }|r|                     |           dS dS )au  
        Apply settings from ``MODERNGL_WINDOW_SETTINGS_MODULE`` environment variable.
        If the environment variable is undefined no action will be taken.
        Normally this would be used to easily be able to switch between
        different configuration by setting env vars before executing the program.

        Example::

            import os
            from moderngl_window.conf import settings

            os.environ['MODERNGL_WINDOW_SETTINGS_MODULE'] = 'python.path.to.module'
            settings.apply_settings_from_env()

        Raises:
            ImproperlyConfigured if the module was not found
        N)osenvirongetSETTINGS_ENV_VARapply_from_module_name)r!   names     r"   apply_settings_from_envz Settings.apply_settings_from_env   sD    $ z~~.// 	.''-----	. 	.r$   settings_module_namec                     	 t          j        |          }n5# t          $ r(}t          d                    ||                    d}~ww xY w|                     |           dS )a  
        Apply settings from a python module by supplying the full
        pythonpath to the module.

        Args:
            settings_module_name (str): Full python path to the module

        Raises:
            ImproperlyConfigured if the module was not found
        z2Settings module '{}' not found. From importlib: {}N)	importlibimport_moduleImportErrorr   formatr&   )r!   r/   moduleexs       r"   r,   zSettings.apply_from_module_name   s    	,-ABBFF 	 	 	&DKK(   	 	v&&&&&s    
A	#AA	datac                 T    |                      |                                           dS )z
        Apply settings values from a dictionary

        Example::

            >> from moderngl_window.conf import settings
            >> settings.apply_dict({'SOME_VALUE': 1})
            >> settings.SOME_VALUE
            1
        N)apply_from_iterableitems)r!   r7   s     r"   apply_from_dictzSettings.apply_from_dict  s&     	  .....r$   r5   c                 ^    |                      |j                                                   dS )ak  
        Apply settings values from a python module

        Example::

            my_settings.py module containing the following line:
            SOME_VALUE = 1

            >> from moderngl_window.conf import settings
            >> import my_settings
            >> settings.apply_module(my_settings)
            >> settings.SOME_VALUE
            1
        Nr9   __dict__r:   )r!   r5   s     r"   r&   zSettings.apply_from_module$  s,     	  !6!6!8!899999r$   clsc                 ^    |                      |j                                                   dS )a7  
        Apply settings values from a class namespace

        Example::

            >> from moderngl_window.conf import settings
            >> class MySettings:
            >>    SOME_VALUE = 1
            >>
            >> settings.apply(MySettings)
            >> settings.SOME_VALUE
            1
        Nr=   )r!   r?   s     r"   apply_from_clszSettings.apply_from_cls5  s,     	  !3!3!5!566666r$   iterablec                    t          |t                    sDt          | t                    s/t          d                    t          |                              |D ]*\  }}|                                rt          | ||           +dS )zH
        Apply (key, value) pairs from an iterable or generator
        z;Input value is not a generator or iterable, but of type: {}N)
isinstancer   r   
ValueErrorr4   typeisuppersetattr)r!   rB   r-   values       r"   r9   zSettings.apply_from_iterableE  s     (H-- 	jy6Q6Q 	MTTUYZbUcUcdd   $ 	+ 	+KD%||~~ +dE***	+ 	+r$   c                 H    d | j                                         D             S )zCreate a dict representation of the settings
        Only uppercase attributes are included

        Returns:
            dict: dict representation
        c                 B    i | ]\  }}|                                 ||S  )upper.0kvs      r"   
<dictcomp>z$Settings.to_dict.<locals>.<dictcomp>Y  s+    DDDA!''))D1DDDr$   )r>   r:   r    s    r"   to_dictzSettings.to_dictR  s'     ED!4!4!6!6DDDDr$   c                 n    d                     d | j                                        D                       S )N
c              3      K   | ]@\  }}|                                 d                     |t          |d                    V  AdS )z{}={}   )indentN)rG   r4   r   rN   s      r"   	<genexpr>z$Settings.__repr__.<locals>.<genexpr>\  sg       
 
8<1YZYbYbYdYd
NN1ga22233
 
 
 
 
 
r$   )joinr>   r:   r    s    r"   __repr__zSettings.__repr__[  sB    yy 
 
@D@S@S@U@U
 
 
 
 
 	
r$   )r   N)(__name__
__module____qualname____doc__dictr   strr   __annotations__r   r   r   listr   r   r   r   r	   pathlibPathr   r   r   r   r   r   r   r#   r   r.   r,   r;   Moduler&   rA   r   tupler9   rS   r[   rL   r$   r"   r   r      s         2 "TVVFDcN###+X &*OXc]))) "$OT#Y###	 "$OT#Y###	  "M49!!!
 !L$s)   	 46L$uS',./0555 46L$uS',./0555 24JU3,-.333 13ItE#w|+,-222 "$OT#Y###
 "$OT#Y###
  "M49!!! !L$s)   & & & &
( 
( 
( 
(. . . .,'3 '4 ' ' ' './DcN /t / / / /: :4 : : : :"7# 7$ 7 7 7 7 +HU38_,E +$ + + + +Ec3h E E E E
# 
 
 
 
 
 
r$   r   )r_   r1   r(   rd   collections.abcr   r   pprintr   typesr   rf   typingr   r   r	   moderngl_window.confr
   moderngl_window.exceptionsr   r+   r   settingsrL   r$   r"   <module>ro      s    
     				  / / / / / / / /       & & & & & & ' ' ' ' ' ' ' ' ' ' ( ( ( ( ( ( ; ; ; ; ; ;4 J
 J
 J
 J
 J
 J
 J
 J
Z
 8::r$   