euporie.core.config
Define a configuration class for euporie.core.
Functions
|
Add a command to the centralized command system. |
|
Register a new config item. |
|
Cast a value to a type. |
|
Get a command from the centralized command system by name. |
|
Evaluate an expression node or a string containing only a Python expression. |
|
Accept both booleans and Filters as input and turn it into a Filter. |
|
Classes
|
Special type indicating an unconstrained type. |
|
An argument parser which lexes and formats the help message before printing it. |
|
Action for boolean flags. |
|
|
|
Turn any callable into a Filter. |
|
A configuration store. |
|
A namespace that creates default values for undefined attributes using a factory function. |
|
Simple event to which event handlers can be attached. For instance::. |
|
JSON encode class which encodes paths as strings. |
|
PurePath subclass that can make system calls. |
|
A single configuration item. |
|
A simple attribute-based namespace. |
|
Typed version of the return of open() in text mode. |
|
|
|
|
|
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:
ArgumentParserAn 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:
ActionAction for boolean flags.
Included because argparse.BooleanOptionalAction is not present in python<=3.9.
- class euporie.core.config.Config(_help: str = '', **kwargs: Any)
Bases:
objectA configuration store.
- 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:
SimpleNamespaceA 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:
JSONEncoderJSON 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:
objectA single configuration item.
Return a menu item for the setting.