pkgcore.config.basics module

configuration subsystem primitives

all callables can/may throw a pkgcore.config.errors.ConfigurationError

class pkgcore.config.basics.ConfigSection[source]

Bases: object

Single Config section, returning typed values from a key.

Not much of an object this, if we were using zope.interface it’d be an Interface.

keys() list[str][source]

Return a list of keys.

render_value(central, name: str, arg_type)[source]

Return a setting, converted to the requested type.

class pkgcore.config.basics.ConfigType(func_obj: Callable)[source]

Bases: object

A configurable type.

Variables:
  • name – string specifying the protocol the instantiated object conforms to.

  • callable – callable used to instantiate this type.

  • types – dict mapping key names to type strings.

  • positional – container holding positional arguments.

  • required – container holding required arguments.

  • allow_unknowns – controls whether unknown settings should error.

allow_unknowns: bool
callable: Callable
positional: tuple[str]
required: tuple[str]
types: dict[str, str]
class pkgcore.config.basics.DictConfigSection(conversion_func: Callable, source_dict: dict[str, Any])[source]

Bases: ConfigSection

Turns a dict and a conversion function into a ConfigSection.

dict: dict[str, Any]
func: Callable
keys() list[str][source]

Return a list of keys.

render_value(central, name: str, arg_type: str) Any | tuple[str, Any][source]

Return a setting, converted to the requested type.

class pkgcore.config.basics.LazyNamedSectionRef(central, typename: str, name: str)[source]

Bases: LazySectionRef

name: str
class pkgcore.config.basics.LazySectionRef(central, typename: str)[source]

Bases: object

Abstract base class for lazy-loaded section references.

collapse()[source]
Returns:

pkgcore.config.central.CollapsedConfig.

instantiate() Any[source]

Convenience method returning the instantiated section.

typename: str
pkgcore.config.basics.convert_asis(central, value, arg_type: str)[source]

“Conversion” func assuming the types are already correct.

pkgcore.config.basics.convert_hybrid(central, value, arg_type: str)[source]

Automagically switch between convert_string and convert_asis.

convert_asis is used for arg_type str and if value is not a string. convert_string is used for the rest.

Be careful about handing in escaped strings: they are not unescaped (for arg_type str).

pkgcore.config.basics.convert_string(central, value, arg_type: str)[source]

Conversion func for a string-based DictConfigSection.

pkgcore.config.basics.parse_config_file(path: str, parser)[source]
pkgcore.config.basics.section_alias(target, typename: str) -> functools.partial(<class 'pkgcore.config.basics.DictConfigSection'>, <function convert_hybrid at 0x7f857d563ec0>)[source]

Build a ConfigSection that instantiates a named reference.

Because of central’s caching our instantiated value will be identical to our target’s.

pkgcore.config.basics.str_to_bool(string: str) bool[source]

Convert a string to a boolean.

pkgcore.config.basics.str_to_int(string: str) int[source]

Convert a string to a integer.

pkgcore.config.basics.str_to_list(string: str) list[str][source]

Split on whitespace honoring quoting for new tokens.

pkgcore.config.basics.str_to_str(string: str) str[source]

Yank leading/trailing whitespace and quotation, along with newlines.