euporie.core.config

Define a configuration class for euporie.core.

Functions

add_cmd(**kwargs)

Add a command to the centralized command system.

add_setting(name, *args, **kwargs)

Register a new config item.

cast(typ, val)

Cast a value to a type.

get_cmd(name)

Get a command from the centralized command system by name.

literal_eval(node_or_string)

Evaluate an expression node or a string containing only a Python expression.

to_filter(bool_or_filter)

Accept both booleans and Filters as input and turn it into a Filter.

user_config_dir([appname, appauthor, ...])

Classes

Any(*args, **kwargs)

Special type indicating an unconstrained type.

ArgumentParser(*args, config, **kwargs)

An argument parser which lexes and formats the help message before printing it.

BooleanOptionalAction(option_strings, *args, ...)

Action for boolean flags.

Callable()

Condition(func)

Turn any callable into a Filter.

Config([_help])

A configuration store.

DefaultNamespace([default_factory, ...])

A namespace that creates default values for undefined attributes using a factory function.

Event(sender[, handler])

Simple event to which event handlers can be attached. For instance::.

JSONEncoderPlus(*[, skipkeys, ensure_ascii, ...])

JSON encode class which encodes paths as strings.

Path(*args, **kwargs)

PurePath subclass that can make system calls.

Setting(name, group[, default, help_, ...])

A single configuration item.

SimpleNamespace([mapping_or_iterable])

A simple attribute-based namespace.

TextIO()

Typed version of the return of open() in text mode.

UPath(*args[, protocol])

cached_property(func)

partial(func, /, *args, **keywords)

Create a new function with partial application of the given arguments and keywords.

class euporie.core.config.ArgumentParser(*args: Any, config: Config, **kwargs: Any)

Bases: ArgumentParser

An argument parser which lexes and formats the help message before printing it.

add_argument(dest, ..., name=value, ...)
add_argument(option_string, option_string, ..., name=value, ...) None
add_argument_group(*args, **kwargs)
add_mutually_exclusive_group(**kwargs)
add_subparsers(**kwargs)
convert_arg_line_to_args(arg_line)
error(message: string)

Prints a usage message incorporating the message to stderr and exits.

If you override this in a subclass, it should not return – it should either exit or raise an exception.

exit(status=0, message=None)
format_help()
format_usage()
get_default(dest)
parse_args(args=None, namespace=None)
parse_intermixed_args(args=None, namespace=None)
parse_known_args(args=None, namespace=None)
parse_known_intermixed_args(args=None, namespace=None)
print_help(file=None)
print_usage(file=None)
register(registry_name, value, object)
set_defaults(**kwargs)
class euporie.core.config.BooleanOptionalAction(option_strings: list[str], *args: Any, **kwargs: Any)

Bases: Action

Action for boolean flags.

Included because argparse.BooleanOptionalAction is not present in python<=3.9.

format_usage() str

Format the action string.

Returns:

The formatted string.

class euporie.core.config.Config(_help: str = '', **kwargs: Any)

Bases: object

A configuration store.

classmethod add_setting(name: str, *args: Any, **kwargs: Any) None

Register a new config item.

load() None

Load the configuration options from non-local sources.

property settings: dict[str, Setting]

Return the currently active settings.

toggle(name: str) None

Toggle the setting’s value.

class euporie.core.config.DefaultNamespace(default_factory: Callable[[str], Any] | None = None, mapping_or_iterable: Mapping | Iterable[tuple[str, Any]] | None = None, /, **kwargs: Any)

Bases: SimpleNamespace

A namespace that creates default values for undefined attributes using a factory function.

This class extends SimpleNamespace to provide automatic creation of default values when accessing undefined attributes, similar to collections.defaultdict but for object attributes.

_factory

A callable that generates default values for undefined attributes. If None, AttributeError will be raised for undefined attributes.

Examples

>>> # Create namespace with list factory
>>> ns = DefaultNamespace(default_factory=list)
>>> ns.numbers.append(1)  # Creates new list automatically
>>> ns.numbers
[1]
>>> # Create with initial values
>>> ns = DefaultNamespace(default_factory=int, x=1, y=2)
>>> ns.x
1
>>> ns.z  # Creates new int (0) automatically
0
class euporie.core.config.JSONEncoderPlus(*, skipkeys=False, ensure_ascii=True, check_circular=True, allow_nan=True, sort_keys=False, indent=None, separators=None, default=None)

Bases: JSONEncoder

JSON encode class which encodes paths as strings.

default(o: Any) bool | int | float | str | None

Encode an object to JSON.

Parameters:

o – The object to encode

Returns:

The encoded object

encode(o)

Return a JSON string representation of a Python data structure.

>>> from json.encoder import JSONEncoder
>>> JSONEncoder().encode({"foo": ["bar", "baz"]})
'{"foo": ["bar", "baz"]}'
item_separator = ', '
iterencode(o, _one_shot=False)

Encode the given object and yield each string representation as available.

For example:

for chunk in JSONEncoder().iterencode(bigobject):
    mysocket.write(chunk)
key_separator = ': '
class euporie.core.config.Setting(name: str, group: str | Sequence[str], default: Any = None, help_: str = '', description: str = '', type_: Callable[[Any], Any] | None = None, title: str | None = None, choices: list[Any] | Callable[[], list[Any]] | None = None, action: argparse.Action | str | None = None, flags: list[str] | None = None, schema: dict[str, Any] | None = None, nargs: str | int | None = None, hidden: FilterOrBool = False, hooks: list[Callable[[Setting], None]] | None = None, cmd_filter: FilterOrBool = True, **kwargs: Any)

Bases: object

A single configuration item.

property choices: list[Any] | None

Compute the setting’s available options.

property menu: MenuItem

Return a menu item for the setting.

property parser_args: tuple[list[str], dict[str, Any]]

Return arguments for construction of an argparse.ArgumentParser.

property schema: dict[str, Any]

Return a json schema property for the config item.

euporie.core.config.add_setting(name: str, *args: Any, **kwargs: Any) None

Register a new config item.