|
14 | 14 |
|
15 | 15 | import dataclasses as _dataclasses |
16 | 16 | import itertools as _itertools |
17 | | -from typing import Self |
| 17 | +from typing import Self, assert_never, overload |
18 | 18 |
|
19 | 19 | import nox as _nox |
20 | 20 |
|
| 21 | +from .._core import RepositoryType |
21 | 22 | from . import util as _util |
22 | 23 |
|
23 | 24 |
|
@@ -177,12 +178,73 @@ def get() -> Config: |
177 | 178 | return _config |
178 | 179 |
|
179 | 180 |
|
180 | | -def configure(conf: Config, /) -> None: |
| 181 | +@overload |
| 182 | +def configure(conf: Config, /, *, import_default_sessions: bool = True) -> None: |
181 | 183 | """Configure nox using the provided configuration. |
182 | 184 |
|
183 | 185 | Args: |
184 | 186 | conf: The configuration to use to configure nox. |
| 187 | + import_default_sessions: Whether to import the default sessions or not. |
| 188 | + This is only necessary if you want to avoid using the default provided |
| 189 | + sessions and use your own. |
| 190 | + """ |
| 191 | + |
| 192 | + |
| 193 | +@overload |
| 194 | +def configure( |
| 195 | + repo_type: RepositoryType, /, *, import_default_sessions: bool = True |
| 196 | +) -> None: |
| 197 | + """Configure nox using the provided repository type. |
| 198 | +
|
| 199 | + Args: |
| 200 | + repo_type: The repository type to use to configure nox. This will use the |
| 201 | + default configuration in [`frequenz.repo.config.nox.default`][] for that |
| 202 | + type of repository. |
| 203 | + import_default_sessions: Whether to import the default sessions or not. |
| 204 | + This is only necessary if you want to avoid using the default provided |
| 205 | + sessions and use your own. |
| 206 | + """ |
| 207 | + |
| 208 | + |
| 209 | +def configure( |
| 210 | + conf: Config | RepositoryType, /, *, import_default_sessions: bool = True |
| 211 | +) -> None: |
| 212 | + """Configure nox using the provided configuration or repository type. |
| 213 | +
|
| 214 | + Args: |
| 215 | + conf: The configuration to use to configure nox, or the repository type to use |
| 216 | + to configure nox. The later will use the default configuration in |
| 217 | + [`frequenz.repo.config.nox.default`][] for that type of repository. |
| 218 | + import_default_sessions: Whether to import the default sessions or not. |
| 219 | + This is only necessary if you want to avoid using the default provided |
| 220 | + sessions and use your own. |
185 | 221 | """ |
186 | 222 | global _config # pylint: disable=global-statement |
187 | | - _config = conf |
| 223 | + |
| 224 | + # We need to make sure sessions are imported, otherwise they won't be visible to nox. |
| 225 | + if import_default_sessions: |
| 226 | + # pylint: disable=import-outside-toplevel,cyclic-import |
| 227 | + from . import session as _ |
| 228 | + |
| 229 | + match conf: |
| 230 | + case Config(): |
| 231 | + _config = conf |
| 232 | + case RepositoryType() as repo_type: |
| 233 | + # pylint: disable=import-outside-toplevel,cyclic-import |
| 234 | + from . import default |
| 235 | + |
| 236 | + match repo_type: |
| 237 | + case RepositoryType.ACTOR: |
| 238 | + _config = default.actor_config |
| 239 | + case RepositoryType.API: |
| 240 | + _config = default.api_config |
| 241 | + case RepositoryType.APP: |
| 242 | + _config = default.app_config |
| 243 | + case RepositoryType.LIB: |
| 244 | + _config = default.lib_config |
| 245 | + case RepositoryType.MODEL: |
| 246 | + _config = default.model_config |
| 247 | + case _ as unhandled: |
| 248 | + assert_never(unhandled) |
| 249 | + |
188 | 250 | _nox.options.sessions = _config.sessions |
0 commit comments