Skip to content

config

ColorConfig dataclass

Configures Colors for the application

Source code in /home/runner/work/arc/arc/arc/config.py
@dataclass
class ColorConfig:
    """Configures Colors for the application"""

    error: str = fg.RED
    highlight: str = fg.YELLOW
    accent: str = fg.ARC_BLUE
    subtle: str = fg.GREY

Config dataclass

arc's Config object. A single global instance of this class is created, then used where it is needed

Source code in /home/runner/work/arc/arc/arc/config.py
@dataclass
class Config:
    """arc's Config object. A single global instance
    of this class is created, then used where it is needed"""

    environment: at.Env = "production"
    transform_snake_case: bool = True
    env_prefix: str = ""
    config_env_prefix: str = "ARC_"
    load_env: bool = True
    version: str | SemVer | None = None
    autocomplete: bool = False
    allow_unrecognized_args: bool = False
    debug: bool = False
    prompt: Prompt = field(default_factory=Prompt)
    suggest: SuggestionConfig = field(default_factory=SuggestionConfig)
    links: LinksConfig = field(default_factory=LinksConfig)
    present: PresentConfig = field(default_factory=PresentConfig)
    plugins: PluginConfig = field(default_factory=PluginConfig)
    extra: dict[str, t.Any] = field(default_factory=dict)

    def __post_init__(self) -> None:
        if self.load_env:
            self._load_from_env()

    @classmethod
    def load(cls) -> "Config":
        """Access the Global `Config` instance"""
        global _config

        if not _config:
            _config = cls()

        return _config

    def update(self, **kwargs: t.Any) -> None:
        for key, value in kwargs.items():
            if value is not None:
                setattr(self, key, value)

    def _load_from_env(self) -> None:
        env = os.environ.get(f"{self.config_env_prefix}ENVIRONMENT", "").lower()

        if env in ("production", "development", "test"):
            self.environment = t.cast(at.Env, env)

        if os.environ.get(f"{self.config_env_prefix}DEBUG", "").lower() == "true":
            self.debug = True

    @classmethod
    def __depends__(cls, ctx: Context) -> Config:
        return ctx.config

load() classmethod

Access the Global Config instance

Source code in /home/runner/work/arc/arc/arc/config.py
@classmethod
def load(cls) -> "Config":
    """Access the Global `Config` instance"""
    global _config

    if not _config:
        _config = cls()

    return _config

LinksConfig dataclass

Configures Links for the application

Source code in /home/runner/work/arc/arc/arc/config.py
@dataclass
class LinksConfig:
    """Configures Links for the application"""

    bug: str | None = None

PluginConfig dataclass

Configures Plugins locations for the application

Source code in /home/runner/work/arc/arc/arc/config.py
@dataclass
class PluginConfig:
    """Configures Plugins locations for the application"""

    paths: list[str] = field(default_factory=list)
    """List of paths to search for plugins. These paths will be searched
    for python  modules that contain a `plugin` function. If the file does
    not exist, or the function is not found, it will be ignored

    The paths provided can be to a specific file, or a directory. If a directory
    is provided, all files in that directory will be searched for plugins.
    """

    groups: list[str] = field(default_factory=lambda: ["arc.plugins"])
    """List of entrypoint groups to search for plugins. The entrypoint's value must be
    a callable that accepts a single argument, the `Context` object.

    Defaults to using the `arc.plugins` entrypoint group
    """

    entrypoints: list[str] = field(default_factory=list)
    """List of explicit entrypoints to search for plugins. The entrypoint's value must be
    a callable that accepts a single argument, the `Context` object.
    """

entrypoints: list[str] = field(default_factory=list) class-attribute instance-attribute

List of explicit entrypoints to search for plugins. The entrypoint's value must be a callable that accepts a single argument, the Context object.

groups: list[str] = field(default_factory=lambda : ['arc.plugins']) class-attribute instance-attribute

List of entrypoint groups to search for plugins. The entrypoint's value must be a callable that accepts a single argument, the Context object.

Defaults to using the arc.plugins entrypoint group

paths: list[str] = field(default_factory=list) class-attribute instance-attribute

List of paths to search for plugins. These paths will be searched for python modules that contain a plugin function. If the file does not exist, or the function is not found, it will be ignored

The paths provided can be to a specific file, or a directory. If a directory is provided, all files in that directory will be searched for plugins.

PresentConfig dataclass

Configures the presentation of the application

Source code in /home/runner/work/arc/arc/arc/config.py
@dataclass
class PresentConfig:
    """Configures the presentation of the application"""

    indent: str = " " * 4
    """The indent to use for each level of indentation"""
    width: int = 80
    """The default width to present content at. This is used
    for wrapping text. Will be ignored if the terminal width is smaller"""
    color: ColorConfig = field(default_factory=ColorConfig)
    """The color configuration for the application"""
    formatter: type[HelpFormatter] = DefaultHelpFormatter
    """Class to use when formatting help messages"""

color: ColorConfig = field(default_factory=ColorConfig) class-attribute instance-attribute

The color configuration for the application

formatter: type[HelpFormatter] = DefaultHelpFormatter class-attribute instance-attribute

Class to use when formatting help messages

indent: str = ' ' * 4 class-attribute instance-attribute

The indent to use for each level of indentation

width: int = 80 class-attribute instance-attribute

The default width to present content at. This is used for wrapping text. Will be ignored if the terminal width is smaller

SuggestionConfig dataclass

Configures Suggestiosn for the application

Source code in /home/runner/work/arc/arc/arc/config.py
@dataclass
class SuggestionConfig:
    """Configures Suggestiosn for the application"""

    commands: bool = True
    params: bool = True
    distance: int = 2

configure(*, version=None, environment=None, transform_snake_case=None, suggest=None, env_prefix=None, config_env_prefix=None, load_env=None, prompt=None, autocomplete=None, allow_unrecognized_args=None, debug=None, links=None, present=None, plugins=None, **kwargs)

Function for updating global arc configuration

Parameters:

Name Type Description Default
version str | SemVer

Version string to display with --version

None
environment str

The current environment, either production or development. Defaults to production. When in development mode, the arc logger is set to level logging.INFO

None
transform_snake_case bool

Transform snake_case to kebab-case. Defaults to True.

None
env_prefix str

A prefix to use when selecting values for parameters from enviroment variables. Will be combined with the name specified by parameter.

None
config_env_prefix str

A prefix to use when selecting values from enviroment for the configuration.

None
load_env bool

Enable / disable loading config values from environment variables. Currently, arc can only load environment and debug from environment variables.

None
prompt Prompt

A prompt object will be used when prompting for parameter values. Is also made available via Context.prompt.

None
autocomplete bool

Enable / disable command line completions for this app. Currently the default is False

None
allow_unrecognized_args bool

arc will not error when there are arguments provided that arc does not recognize. Their values will be stored in the context under the key arc.parse.extra. Defaults to False

None
debug bool

enable / disable arc debug logs.

None
present PresentConfig

set the presentation configuration for arc

None
suggest SuggestConfig

configure the settings for suggesting replacements when arc does not recognize a command / parameter

None
links LinksConfig

configure the links that arc may use in some output

None
Source code in /home/runner/work/arc/arc/arc/config.py
def configure(
    *,
    version: str | None = None,
    environment: at.Env | None = None,
    transform_snake_case: bool | None = None,
    suggest: SuggestionConfig | None = None,
    env_prefix: str | None = None,
    config_env_prefix: str | None = None,
    load_env: bool | None = None,
    prompt: Prompt | None = None,
    autocomplete: bool | None = None,
    allow_unrecognized_args: bool | None = None,
    debug: bool | None = None,
    links: LinksConfig | None = None,
    present: PresentConfig | None = None,
    plugins: PluginConfig | None = None,
    **kwargs: t.Any,
) -> None:
    """Function for updating global `arc` configuration

    Args:
        version (str | SemVer, optional): Version string to display with `--version`

        environment (str, optional): The current environment, either `production` or `development`.
            Defaults to `production`. When in `development` mode, the arc logger is set
            to level `logging.INFO`

        transform_snake_case (bool, optional):  Transform `snake_case` to `kebab-case`.
            Defaults to `True`.

        env_prefix (str, optional): A prefix to use when selecting values for parameters
            from enviroment variables. Will be combined with the name specified by parameter.

        config_env_prefix (str, optional): A prefix to use when selecting values from enviroment
            for the configuration.

        load_env (bool, optional): Enable / disable loading config values from environment variables.
            Currently, arc can only load `environment` and `debug` from environment variables.

        prompt (Prompt, optional): A prompt object will be used when prompting
            for parameter values. Is also made available via `Context.prompt`.

        autocomplete (bool, optional): Enable / disable command line completions for this app. Currently
            the default is `False`

        allow_unrecognized_args (bool, optional): arc will not error when there are arguments provided
            that arc does not recognize. Their values will be stored in the context under the
            key `arc.parse.extra`. Defaults to `False`

        debug (bool, optional): enable / disable arc debug logs.

        present (PresentConfig, optional): set the presentation configuration for arc

        suggest (SuggestConfig, optional): configure the settings for suggesting replacements when
            arc does not recognize a command / parameter

        links (LinksConfig, optional): configure the links that arc may use in some output
    """
    data: dict[str, t.Any] = {
        "version": version,
        "environment": environment,
        "transform_snake_case": transform_snake_case,
        "suggestions": suggest,
        "env_prefix": env_prefix,
        "config_env_prefix": config_env_prefix,
        "load_env": load_env,
        "prompt": prompt,
        "autocomplete": autocomplete,
        "allow_unrecognized_args": allow_unrecognized_args,
        "debug": debug,
        "links": links,
        "present": present,
        "plugins": plugins,
        "extra": kwargs or None,
    }

    config = Config.load()
    config.update(**data)