Skip to content

Index

frequenz.repo.config.nox ¤

Utilities to build noxfiles.

The main entry point is the configure() function, which will configure all nox sessions according to some configuration.

To use the default options, you should call configure() using one of the repository types. For example:

from frequenz.repo.config import RepositoryType, nox

nox.configure(RepositoryType.LIB)

Again, make sure to pick the correct project typedefault configuration based on the type of your project (actor_config, api_config, app_config, lib_config, model_config).

If you need to use some custom configuration, you can start from the default settings in the frequenz.repo.config.nox.default module, copying it and changing whatever you need to customize. For example:

from frequenz.repo.config import nox
from frequenz.repo.config.nox import default

config = default.lib_config.copy()
config.opts.black.append("--diff")
nox.configure(config)

If you need further customization or to define new sessions, you can use the following modules:

  • frequenz.repo.config.nox.config: Low-level utilities to configure nox sessions. It defines the Config and CommandsOptionsclasses and the actual implementation of theconfigure()function. It also defines theget()` function, which can be used to get the currently used configuration object.

  • frequenz.repo.config.nox.session: Predefined nox sessions. These are the sessions that are used by default.

  • frequenz.repo.config.nox.util: General purpose utility functions.

Functions¤

frequenz.repo.config.nox.configure ¤

configure(
    conf: Config | RepositoryType,
    /,
    *,
    import_default_sessions: bool = True,
) -> None

Configure nox using the provided configuration or repository type.

PARAMETER DESCRIPTION
conf

The configuration to use to configure nox, or the repository type to use to configure nox. The later will use the default configuration in frequenz.repo.config.nox.default for that type of repository.

TYPE: Config | RepositoryType

import_default_sessions

Whether to import the default sessions or not. This is only necessary if you want to avoid using the default provided sessions and use your own.

TYPE: bool DEFAULT: True

Source code in frequenz/repo/config/nox/config.py
def configure(
    conf: Config | RepositoryType, /, *, import_default_sessions: bool = True
) -> None:
    """Configure nox using the provided configuration or repository type.

    Args:
        conf: The configuration to use to configure nox, or the repository type to use
            to configure nox.  The later will use the default configuration in
            [`frequenz.repo.config.nox.default`][] for that type of repository.
        import_default_sessions: Whether to import the default sessions or not.
            This is only necessary if you want to avoid using the default provided
            sessions and use your own.
    """
    global _config  # pylint: disable=global-statement

    # We need to make sure sessions are imported, otherwise they won't be visible to nox.
    if import_default_sessions:
        # pylint: disable=import-outside-toplevel,cyclic-import
        from . import session as _  # noqa: F401

    match conf:
        case Config():
            _config = conf
        case RepositoryType() as repo_type:
            # pylint: disable=import-outside-toplevel,cyclic-import
            from . import default

            match repo_type:
                case RepositoryType.ACTOR:
                    _config = default.actor_config
                case RepositoryType.API:
                    _config = default.api_config
                case RepositoryType.APP:
                    _config = default.app_config
                case RepositoryType.LIB:
                    _config = default.lib_config
                case RepositoryType.MODEL:
                    _config = default.model_config
                case _ as unhandled:
                    assert_never(unhandled)

    _nox.options.sessions = _config.sessions