
    h:                         S SK r S SKrS SKrS SKrS SKJr  S/r\" SSSSSS9 " S S5      5       rS r\ R                  R                  R                  \5         " S	 S
\SS9r " S S\5      rg)    N)	dataclassConfigFT)initeqslotskw_only
match_argsc                       \ rS rSrSrSS jrS rS rS rS r	S r
S	 rS
 rS rS rS rS rS rS r\	rSS jrS rS rS rS rS r\S 5       rS rS rS rSrg)r   
   a  The base class for NetworkX configuration.

There are two ways to use this to create configurations. The recommended way
is to subclass ``Config`` with docs and annotations.

>>> class MyConfig(Config):
...     '''Breakfast!'''
...
...     eggs: int
...     spam: int
...
...     def _on_setattr(self, key, value):
...         assert isinstance(value, int) and value >= 0
...         return value
>>> cfg = MyConfig(eggs=1, spam=5)

Another way is to simply pass the initial configuration as keyword arguments to
the ``Config`` instance:

>>> cfg1 = Config(eggs=1, spam=5)
>>> cfg1
Config(eggs=1, spam=5)

Once defined, config items may be modified, but can't be added or deleted by default.
``Config`` is a ``Mapping``, and can get and set configs via attributes or brackets:

>>> cfg.eggs = 2
>>> cfg.eggs
2
>>> cfg["spam"] = 42
>>> cfg["spam"]
42

For convenience, it can also set configs within a context with the "with" statement:

>>> with cfg(spam=3):
...     print("spam (in context):", cfg.spam)
spam (in context): 3
>>> print("spam (after context):", cfg.spam)
spam (after context): 42

Subclasses may also define ``_on_setattr`` (as done in the example above)
to ensure the value being assigned is valid:

>>> cfg.spam = -1
Traceback (most recent call last):
    ...
AssertionError

If a more flexible configuration object is needed that allows adding and deleting
configurations, then pass ``strict=False`` when defining the subclass:

>>> class FlexibleConfig(Config, strict=False):
...     default_greeting: str = "Hello"
>>> flexcfg = FlexibleConfig()
>>> flexcfg.name = "Mr. Anderson"
>>> flexcfg
FlexibleConfig(default_greeting='Hello', name='Mr. Anderson')
c                     Xl         g N)_strict)clsstricts     H/var/www/html/env/lib/python3.13/site-packages/networkx/utils/configs.py__init_subclass__Config.__init_subclass__H   s        c           
         U nU [         L a9  [        U R                  U 4SU Vs0 s H  o3[        R                  _M     sn05      n [        SU R                  U R                  SSS9" U 5      n U R                  (       d  [        U l        X l	        S U l
        / U l        [        R                  U 5      nUR                  " S0 UD6  U$ s  snf )N__annotations__FT)r   reprr   r   r	    )r   type__name__typingAnyr   r   _flexible_repr__repr___orig_class_prev_context_stackobject__new____init__)r   kwargs
orig_classkeyinstances        r   r#   Config.__new__K   s    
&="$G&**_$GHC
 ++
  {{)CL$	>>#&#F#! %Hs   Cc                     U$ )zJProcess config value and check whether it is valid. Useful for subclasses.r   selfr'   values      r   _on_setattrConfig._on_setattrd   s    r   c                     g)zHCallback for when a config item is being deleted. Useful for subclasses.Nr   r,   r'   s     r   _on_delattrConfig._on_delattrh   s    r   c                 6    U R                   R                  5       $ r   )__dataclass_fields__keysr,   s    r   __dir__Config.__dir__l   s    ((--//r   c                     U R                   (       a  XR                  ;  a  [        SU< 35      eU R                  X5      n[        R                  XU5        S U R                  l        g )NInvalid config name: )r   r5   AttributeErrorr.   r"   __setattr__	__class__r    r+   s      r   r=   Config.__setattr__o   sS    <<C'@'@@ #8!@AA  ,4e,#r   c                     U R                   (       a  [        SU< S35      eU R                  U5        [        R	                  X5        S U R
                  l        g )Nz3Configuration items can't be deleted (can't delete z).)r   	TypeErrorr2   r"   __delattr__r>   r    r1   s     r   rB   Config.__delattr__v   sL    <<EcWBO  	4%#r   c                 \    U R                   (       a  XR                  ;   $ XR                  ;   $ r   )r   r5   __dict__r1   s     r   __contains__Config.__contains__   s(    04C,,,	
BEBV	
r   c                 n    [        U R                  (       a  U R                  5      $ U R                  5      $ r   )iterr   r5   rE   r7   s    r   __iter__Config.__iter__   s%    D--QQ4==QQr   c                 n    [        U R                  (       a  U R                  5      $ U R                  5      $ r   )lenr   r5   rE   r7   s    r   __len__Config.__len__   s%    4,,PP$--PPr   c                 n    [        U R                  (       a  U R                  5      $ U R                  5      $ r   )reversedr   r5   rE   r7   s    r   __reversed__Config.__reversed__   s%    T\\11UUt}}UUr   c                 d     [        X5      $ ! [         a  n[        UR                  6 S eS nAff = fr   )getattrr<   KeyErrorargsr,   r'   errs      r   __getitem__Config.__getitem__   s3    	04%% 	0CHH%4/	0s   
 
/*/c                 r     U R                  X5        g ! [         a  n[        UR                  6 S eS nAff = fr   )r=   r<   rV   rW   )r,   r'   r-   rY   s       r   __setitem__Config.__setitem__   s6    	0S( 	0CHH%4/	0    
616c                 r     U R                  U5        g ! [         a  n[        UR                  6 S eS nAff = fr   )rB   r<   rV   rW   rX   s      r   __delitem__Config.__delitem__   s6    	0S! 	0CHH%4/	0r_   Nc                     [        XU5      $ r   )rU   )r,   r'   defaults      r   get
Config.get   s    t'**r   c                 @    [         R                  R                  U 5      $ r   )collectionsabc	ItemsViewr7   s    r   itemsConfig.items   s    ((..r   c                 @    [         R                  R                  U 5      $ r   )rh   ri   KeysViewr7   s    r   r6   Config.keys   s    ''--r   c                 @    [         R                  R                  U 5      $ r   )rh   ri   
ValuesViewr7   s    r   valuesConfig.values   s    ))$//r   c                     [        U[        5      (       d  [        $ U R                  UR                  :H  =(       a!    U R	                  5       UR	                  5       :H  $ r   )
isinstancer   NotImplementedr   rk   )r,   others     r   __eq__Config.__eq__   sB    %((!!5#4#44V9VVr   c                 H    U R                   U R                  [        U 5      44$ r   )_deserializer   dictr7   s    r   
__reduce__Config.__reduce__   s"      4#3#3T$Z"@@@r   c                     U " S0 UD6$ )Nr   r   )r   r%   s     r   r{   Config._deserialize   s    }V}r   c           	          UR                  5        VVs0 s H  u  p#X R                  X#5      _M     nnn[        U 5      nUR                  5        H  u  p#[        XU5        M     X@R                  l        U $ s  snnf r   )rk   r.   r|   setattrr>   r    )r,   r%   r'   valprevs        r   __call__Config.__call__   sf    BH,,.Q.hc#''11.QDzHCDs# '# Rs   A6c                     U R                   R                  c  [        S5      eU R                   R                  R	                  U R                   R                  5        S U R                   l        U $ )Na  Config being used as a context manager without config items being set. Set config items via keyword arguments when calling the config object. For example, using config as a context manager should be like:

    >>> with cfg(breakfast="spam"):
    ...     ...  # Do stuff
)r>   r    RuntimeErrorr!   appendr7   s    r   	__enter__Config.__enter__   sY    >>'0  	%%,,T^^-A-AB#r   c                     U R                   R                  R                  5       nUR                  5        H  u  pV[	        XU5        M     g r   )r>   r!   poprk   r   )r,   exc_type	exc_value	tracebackr   r'   r   s          r   __exit__Config.__exit__   s6    ~~,,002

HCDs# %r   r   )Tr   ) r   
__module____qualname____firstlineno____doc__r   r#   r.   r2   r8   r=   rB   rF   rJ   rN   rR   rZ   r]   ra   _ipython_key_completions_re   rk   r6   rr   rx   r}   staticmethodr{   r   r   r   __static_attributes__r   r   r   r   r   
   s    :x2W0$$

RQV000 !(+/.0WA  $r   c                     U R                   R                   S3SR                  S U R                  R	                  5        5       5      -   S-   $ )N(, c              3   6   #    U  H  u  pU S U< 3v   M     g7f)=Nr   ).0r'   r   s      r   	<genexpr>!_flexible_repr.<locals>.<genexpr>   s     K5Jse1SG$5Js   ))r>   r   joinrE   rk   r7   s    r   r   r      sI    >>&&
'q)
))KT]]5H5H5JK
K	L
	r   c                   F    \ rS rSr% Sr\\   \S'   \\   \S'   S rS r	Sr
g)	BackendPriorities   a  Configuration to control automatic conversion to and calling of backends.

Priority is given to backends listed earlier.

Parameters
----------
algos : list of backend names
    This controls "algorithms" such as ``nx.pagerank`` that don't return a graph.
generators : list of backend names
    This controls "generators" such as ``nx.from_pandas_edgelist`` that return a graph.
kwargs : variadic keyword arguments of function name to list of backend names
    This allows each function to be configured separately and will override the config
    in ``algos`` or ``generators`` if present. The dispatchable function name may be
    gotten from the ``.name`` attribute such as ``nx.pagerank.name`` (it's typically
    the same as the name of the function).
algos
generatorsc                    SSK JnJn  US;   a  OX;  a  [        SU< S35      e[	        U[
        5      (       a  [        S U 5       5      (       d  [        U< SU< 35      eU Vs1 s H  oUU;  d  M
  UiM     sn=n(       a:  SR                  [        [        [        U5      5      5      n[        S	U< S
U 35      eU$ s  snf )N   )_registered_algorithmsbackend_info   r   r   r;   zp. Expected 'algos', 'generators', or a name of a dispatchable function (e.g. `.name` attribute of the function).c              3   B   #    U  H  n[        U[        5      v   M     g 7fr   ru   strr   xs     r   r   0BackendPriorities._on_setattr.<locals>.<genexpr>  s     /REq
1c0B0BE   z- config must be a list of backend names; got r   Unknown backend when setting : )backendsr   r   r<   ru   listallrA   r   mapr   sorted
ValueError)r,   r'   r-   r   r   r   missings          r   r.   BackendPriorities._on_setattr   s    B)). 'w /W W  5$''C/RE/R,R,R'FuiP  #(A%QL+@q%AA7AiiD&/ :;G<SG2gYOPP Bs   '	C 4C c                 .    US;   a  [        U< S35      eg )Nr   z% configuration item can't be deleted.)rA   r1   s     r   r2   BackendPriorities._on_delattr  s#    ))sg%JKLL *r   r   N)r   r   r   r   r   r   r   r   r.   r2   r   r   r   r   r   r      s(    " 9S	&Mr   r   )r   c                   X    \ rS rSr% Sr\\S'   \\S'   \\S'   \\S'   \	\
   \S'   S rS	rg
)NetworkXConfigi  aC  Configuration for NetworkX that controls behaviors such as how to use backends.

Attribute and bracket notation are supported for getting and setting configurations::

    >>> nx.config.backend_priority == nx.config["backend_priority"]
    True

Parameters
----------
backend_priority : list of backend names or dict or BackendPriorities
    Enable automatic conversion of graphs to backend graphs for functions
    implemented by the backend. Priority is given to backends listed earlier.
    This is a nested configuration with keys ``algos``, ``generators``, and,
    optionally, function names. Setting this value to a list of backend names
    will set ``nx.config.backend_priority.algos``. For more information, see
    ``help(nx.config.backend_priority)``. Default is empty list.

backends : Config mapping of backend names to backend Config
    The keys of the Config mapping are names of all installed NetworkX backends,
    and the values are their configurations as Config mappings.

cache_converted_graphs : bool
    If True, then save converted graphs to the cache of the input graph. Graph
    conversion may occur when automatically using a backend from `backend_priority`
    or when using the `backend=` keyword argument to a function call. Caching can
    improve performance by avoiding repeated conversions, but it uses more memory.
    Care should be taken to not manually mutate a graph that has cached graphs; for
    example, ``G[u][v][k] = val`` changes the graph, but does not clear the cache.
    Using methods such as ``G.add_edge(u, v, weight=val)`` will clear the cache to
    keep it consistent. ``G.__networkx_cache__.clear()`` manually clears the cache.
    Default is True.

fallback_to_nx : bool
    If True, then "fall back" and run with the default "networkx" implementation
    for dispatchable functions not implemented by backends of input graphs. When a
    backend graph is passed to a dispatchable function, the default behavior is to
    use the implementation from that backend if possible and raise if not. Enabling
    ``fallback_to_nx`` makes the networkx implementation the fallback to use instead
    of raising, and will convert the backend graph to a networkx-compatible graph.
    Default is False.

warnings_to_ignore : set of strings
    Control which warnings from NetworkX are not emitted. Valid elements:

    - `"cache"`: when a cached value is used from ``G.__networkx_cache__``.

Notes
-----
Environment variables may be used to control some default configurations:

- ``NETWORKX_BACKEND_PRIORITY``: set ``backend_priority.algos`` from comma-separated names.
- ``NETWORKX_CACHE_CONVERTED_GRAPHS``: set ``cache_converted_graphs`` to True if nonempty.
- ``NETWORKX_FALLBACK_TO_NX``: set ``fallback_to_nx`` to True if nonempty.
- ``NETWORKX_WARNINGS_TO_IGNORE``: set `warnings_to_ignore` from comma-separated names.

and can be used for finer control of ``backend_priority`` such as:

- ``NETWORKX_BACKEND_PRIORITY_ALGOS``: same as ``NETWORKX_BACKEND_PRIORITY`` to set ``backend_priority.algos``.

This is a global configuration. Use with caution when using from multiple threads.
backend_priorityr   cache_converted_graphsfallback_to_nxwarnings_to_ignorec                    SSK Jn  US:X  a  [        U[        5      (       a  U[	        X5      l        [	        X5      nU$ [        U[        5      (       a3  Un[        / / S9nUR                  5        H  u  p[        X!U5        M     U$ [        U[        5      (       d  [        U< SU< 35      e U$ US:X  a  [        U[        5      (       a<  [        S U 5       5      (       a%  [        S UR                  5        5       5      (       d  [        U< S	U< 35      eU Vs1 s H  ofU;  d  M
  UiM     sn=n(       a:  S
R                  [        [         [#        U5      5      5      n[%        SU< SU 35      e U$ US;   a*  [        U[&        5      (       d  [        U< SU< 35      e U$ US:X  a  [        U[(        5      (       a  [        S U 5       5      (       d  [        U< SU< 35      eS1nU Vs1 s H  ofU;  d  M
  UiM     sn=n(       aV  S
R                  [        [         [#        U5      5      5      n[%        SU< SU S3S
R                  [#        U5      5      -   5      eU$ s  snf s  snf )Nr   )r   r   )r   r   z6 config must be a dict of lists of backend names; got r   c              3   B   #    U  H  n[        U[        5      v   M     g 7fr   r   )r   r'   s     r   r   -NetworkXConfig._on_setattr.<locals>.<genexpr>k  s     >
3,,r   c              3   B   #    U  H  n[        U[        5      v   M     g 7fr   )ru   r   )r   r   s     r   r   r   l  s     J>C
3//>r   z1 config must be a Config of backend configs; got r   r   r   >   r   r   z# config must be True or False; got r   c              3   B   #    U  H  n[        U[        5      v   M     g 7fr   r   r   s     r   r   r   x  s     2Uu!:a3E3Eur   z, config must be a set of warning names; got cachezUnknown warning when setting z. Valid entries: )r   r   ru   r   rU   r   r|   r   rk   r   rA   r   r   rr   r   r   r   r   r   boolset)	r,   r'   r-   r   r%   r   r   r   known_warningss	            r   r.   NetworkXConfig._on_setattrX  s}   *$$%&&+0"(*J I E4(()rB &HCE, !/B ?  '899gSTYS\]  :> 7 J5&))>>>>J5<<>JJJgNuiX  ',Ee/D1eEEwE))CfWo$>? #@r'!STT F$  @@eT**3')LUI VWW +  ((uc**s2Uu2U/U/UgI%S  &YN&+Ge/F1eGGwG))CfWo$>? 3C7"WIEVWii~ 678  % F Hs   	I(+I(3	I- I-r   N)r   r   r   r   r   r   r   r   r   r   r   r.   r   r   r   r   r   r     s1    <| ('  C +r   r   )rh   osr   warningsdataclassesr   __all__r   r   ri   Mappingregisterr   r   r   r   r   <module>r      s     	   !* %tTeLL$ L$ ML$^        (*Mu *MZpV pr   