11from abc import ABC
22from pathlib import Path
3- from typing import Dict , Iterable , Iterator , List , Optional , Set , Tuple , Union
3+ from typing import Iterable , Iterator , Optional , Union
44
55from pydantic import BaseModel , Field , RootModel , field_validator , model_validator
66from pydantic_core import PydanticUndefinedType
1010
1111
1212class GlobalModules (RootModel ):
13- root : Set [str ]
13+ root : set [str ]
1414
1515
1616class BaseApp (BaseModel , ABC ):
@@ -19,32 +19,32 @@ class BaseApp(BaseModel, ABC):
1919 module_name : str = Field (alias = "module" )
2020 """Importable module name.
2121 """
22- dependencies : Set [str ] = Field (default_factory = set )
22+ dependencies : set [str ] = Field (default_factory = set )
2323 """Other apps that this app depends on. They are guaranteed to be loaded and started before this one.
2424 """
25- global_dependencies : Set [str ] = Field (default_factory = set )
25+ global_dependencies : set [str ] = Field (default_factory = set )
2626 """Global modules that this app depends on.
2727 """
2828 global_ : bool = Field (alias = "global" )
2929
3030
3131class GlobalModule (BaseApp ):
3232 global_ : bool = Field (default = True , alias = "global" )
33- global_dependencies : Set [str ] = Field (default_factory = set )
33+ global_dependencies : set [str ] = Field (default_factory = set )
3434 """Global modules that this app depends on.
3535 """
3636
3737
3838class Sequence (RootModel ):
3939 class SequenceItem (BaseModel ):
4040 class SequenceStep (RootModel ):
41- root : Dict [str , Dict ]
41+ root : dict [str , dict ]
4242
4343 name : str
4444 namespace : str = "default"
45- steps : List [SequenceStep ]
45+ steps : list [SequenceStep ]
4646
47- root : Dict [str , SequenceItem ]
47+ root : dict [str , SequenceItem ]
4848
4949
5050class AppConfig (BaseApp , extra = "allow" ):
@@ -61,23 +61,23 @@ class AppConfig(BaseApp, extra="allow"):
6161
6262 @field_validator ("dependencies" , "global_dependencies" , mode = "before" )
6363 @classmethod
64- def coerce_to_list (cls , value : Union [str , Set [str ]]) -> Set [str ]:
64+ def coerce_to_list (cls , value : Union [str , set [str ]]) -> set [str ]:
6565 return set ((value ,)) if isinstance (value , str ) else value
6666
6767 def __getitem__ (self , key : str ):
6868 return getattr (self , key )
6969
7070 @property
71- def args (self ) -> Dict [str , Dict ]:
71+ def args (self ) -> dict [str , dict ]:
7272 return self .model_dump (by_alias = True , exclude_unset = True )
7373
7474
7575class AllAppConfig (RootModel ):
76- root : Dict [str , Union [AppConfig , GlobalModule , GlobalModules , Sequence ]] = {}
76+ root : dict [str , Union [AppConfig , GlobalModule , GlobalModules , Sequence ]] = {}
7777
7878 @model_validator (mode = "before" )
7979 @classmethod
80- def set_app_names (cls , values : Dict ):
80+ def set_app_names (cls , values : dict ):
8181 if not isinstance (values , PydanticUndefinedType ):
8282 for app_name , cfg in values .items ():
8383 match app_name :
@@ -117,19 +117,19 @@ def from_config_files(cls, paths: Iterable[Path]):
117117 self .root .update (cls .from_config_file (p ).root )
118118 return self
119119
120- def depedency_graph (self ) -> Dict [str , Set [str ]]:
120+ def depedency_graph (self ) -> dict [str , set [str ]]:
121121 """Maps the app names to the other apps that they depend on"""
122122 return {app_name : cfg .dependencies | cfg .global_dependencies for app_name , cfg in self .root .items () if isinstance (cfg , (AppConfig , GlobalModule ))}
123123
124- def reversed_dependency_graph (self ) -> Dict [str , Set [str ]]:
124+ def reversed_dependency_graph (self ) -> dict [str , set [str ]]:
125125 """Maps each app to the other apps that depend on it"""
126126 return reverse_graph (self .depedency_graph ())
127127
128128 def app_definitions (self ):
129129 """Returns the app name and associated config for user-defined apps. Does not include global module apps"""
130130 yield from ((app_name , cfg ) for app_name , cfg in self .root .items () if isinstance (cfg , AppConfig ))
131131
132- def app_names (self ) -> Set [str ]:
132+ def app_names (self ) -> set [str ]:
133133 """Returns all the app names for regular user apps and global module apps"""
134134 return set (app_name for app_name , cfg in self .root .items () if isinstance (cfg , BaseApp ))
135135
@@ -144,7 +144,7 @@ def active_app_count(self) -> int:
144144 """Active in this case means not disabled"""
145145 return len ([cfg for cfg in self .root .values () if isinstance (cfg , AppConfig ) and not cfg .disable ])
146146
147- def get_active_app_count (self ) -> Tuple [int , int , int ]:
147+ def get_active_app_count (self ) -> tuple [int , int , int ]:
148148 active = 0
149149 inactive = 0
150150 glbl = 0
0 commit comments