K i;ddlZddlZddlmZdgZedddddGddZdZejjjeGd d ed Z Gd d eZ y)N) dataclassConfigFT)initeqslotskw_only match_argsceZdZdZddZdZdZdZdZdZ dZ d Z d Z d Z d Zd ZdZdZeZddZdZdZdZdZdZedZdZdZdZy)raCThe 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||_yN)_strict)clsstricts \/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/networkx/utils/configs.py__init_subclass__zConfig.__init_subclass__Fs  c |}|tur>#&#F#rc|S)zJProcess config value and check whether it is valid. Useful for subclasses.rselfkeyvalues r _on_setattrzConfig._on_setattrbs rcy)zHCallback for when a config item is being deleted. Useful for subclasses.Nrr*r+s r _on_delattrzConfig._on_delattrfsrc6|jjSr )__dataclass_fields__keysr*s r__dir__zConfig.__dir__js((--//rc|jr||jvrtd||j||}tj |||d|j _y)NInvalid config name: )r r2AttributeErrorr-r" __setattr__ __class__r r)s rr9zConfig.__setattr__msY <>> with cfg(breakfast="spam"): ... ... # Do stuff )r:r RuntimeErrorr!appendr4s r __enter__zConfig.__enter__sY >>   '0  %%,,T^^-A-AB# rc|jjj}|jD]\}}t |||yr )r:r!popr\rl)r*exc_type exc_value tracebackrnr+rms r__exit__zConfig.__exit__s?~~,,002  $HC D#s # $r)Tr )r __module__ __qualname____doc__rr#r-r0r5r9r=r@rCrFrIrPrRrT_ipython_key_completions_rWr\r3rarfri staticmethodrhrorsryrrrrrs:x2W0$$ RQV0 0 0 !(+/.0W A $rc|jjddjd|jj DzdzS)N(, c30K|]\}}|d|yw)=Nr).0r+rms r z!_flexible_repr..sKcse1SG$Ks))r:r{joinr?r\r4s rrrsI >> & & 'q) ))KT]]5H5H5JK K L  rc>eZdZUdZeeed<eeed<dZdZy)BackendPrioritiesa)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 generatorscTddlm}m}|dvrn||vrtd|dt |t rt d|Dst|d||Dchc] }||vs| c}x}r9djttt|}td |d ||Scc}w) N)_registered_algorithms backend_inforrr7zp. Expected 'algos', 'generators', or a name of a dispatchable function (e.g. `.name` attribute of the function).c3<K|]}t|tywr rcstrrxs rrz0BackendPriorities._on_setattr..s/Rq 1c0B/Rz- config must be a list of backend names; got rUnknown backend when setting : ) backendsrrr8rclistallr<rmaprsorted ValueError)r*r+r,rrrmissings rr-zBackendPriorities._on_setattrsB ) )  . . 'w/WW 5$'C/RE/R,R'FuiP #(AQ1L+@qA A7 AiiD&/ :;G>> 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_priorityrcache_converted_graphsfallback_to_nxwarnings_to_ignorec ddlm}|dk(rt|tr.os> 3,>rc3<K|]}t|tywr )rcr)rrms rrz-NetworkXConfig._on_setattr..psJC 3/Jrz1 config must be a Config of backend configs; got rrr>rrz# config must be True or False; got rc3<K|]}t|tywr rrs rrz-NetworkXConfig._on_setattr..|s2U!:a3E2Urz, config must be a set of warning names; got cachezUnknown warning when setting z. Valid entries: r)rrrcrrrrr-r\rlr<rrrarrrrrboolset) r*r+r,rr%rmrrknown_warningss rr-zNetworkXConfig._on_setattrWsv* $ $%&)--"33??OT IE4()rB & -HCE3,-B ? '89gSTYS\]< 7J 5&)>>>J5<<>JJgNuiX',Eq /D1EEwE))CfWo$>? #@r'!STT  @ @eT*3')LUI VWW ( (uc*s2Uu2U/UgI%S&YN&+Gq/F1GGwG))CfWo$>? 3C7"WIEVWii~ 678 %FHs H7%H7 H<H<N) rrzr{r|rrrrrrr-rrrrrs1=~('  C 0rr) rYr dataclassesr__all__rrrZMappingregisterrrrrrrs~ ! * %tTeLL$L$ML$^  (*Mu*MZvVvr