A singleton application with full configuration support.
| 150 | |
| 151 | |
| 152 | class Application(SingletonConfigurable): |
| 153 | """A singleton application with full configuration support.""" |
| 154 | |
| 155 | # The name of the application, will usually match the name of the command |
| 156 | # line application |
| 157 | name: str | Unicode[str, str | bytes] = Unicode("application") |
| 158 | |
| 159 | # The description of the application that is printed at the beginning |
| 160 | # of the help. |
| 161 | description: str | Unicode[str, str | bytes] = Unicode("This is an application.") |
| 162 | # default section descriptions |
| 163 | option_description: str | Unicode[str, str | bytes] = Unicode(option_description) |
| 164 | keyvalue_description: str | Unicode[str, str | bytes] = Unicode(keyvalue_description) |
| 165 | subcommand_description: str | Unicode[str, str | bytes] = Unicode(subcommand_description) |
| 166 | |
| 167 | python_config_loader_class = PyFileConfigLoader |
| 168 | json_config_loader_class = JSONFileConfigLoader |
| 169 | |
| 170 | # The usage and example string that goes at the end of the help string. |
| 171 | examples: str | Unicode[str, str | bytes] = Unicode() |
| 172 | |
| 173 | # A sequence of Configurable subclasses whose config=True attributes will |
| 174 | # be exposed at the command line. |
| 175 | classes: ClassesType = [] |
| 176 | |
| 177 | def _classes_inc_parents( |
| 178 | self, classes: ClassesType | None = None |
| 179 | ) -> t.Generator[type[Configurable], None, None]: |
| 180 | """Iterate through configurable classes, including configurable parents |
| 181 | |
| 182 | :param classes: |
| 183 | The list of classes to iterate; if not set, uses :attr:`classes`. |
| 184 | |
| 185 | Children should always be after parents, and each class should only be |
| 186 | yielded once. |
| 187 | """ |
| 188 | if classes is None: |
| 189 | classes = self.classes |
| 190 | |
| 191 | seen = set() |
| 192 | for c in classes: |
| 193 | # We want to sort parents before children, so we reverse the MRO |
| 194 | for parent in reversed(c.mro()): |
| 195 | if issubclass(parent, Configurable) and (parent not in seen): |
| 196 | seen.add(parent) |
| 197 | yield parent |
| 198 | |
| 199 | # The version string of this application. |
| 200 | version: str | Unicode[str, str | bytes] = Unicode("0.0") |
| 201 | |
| 202 | # the argv used to initialize the application |
| 203 | argv: list[str] | List[str] = List() |
| 204 | |
| 205 | # Whether failing to load config files should prevent startup |
| 206 | raise_config_file_errors = Bool(TRAITLETS_APPLICATION_RAISE_CONFIG_FILE_ERROR) |
| 207 | |
| 208 | # The log level for the application |
| 209 | log_level = Enum( |
searching dependent graphs…