Module vpe.config¶
Support for managing configuration information.
Configuration values are held as config.Option
instances, which carry
additional meta-data such default values, valid ranges and descriptions.
Options prevent assignment of invalid values.
The Config
class groups a set options together. It supports storage of option
values in an INI style configuration file and makes option values available as
(pseudo) instance attributes.
Bool¶
- class vpe.config.Bool(name, default_value=False, description='')¶
A boolean
config.Option
.Its value is always forced to be
True
orFalse
.Methods
- set(value: Union[int, str, bool]) str ¶
Try to set this option’s value.
Return value
A string describing why the attempt failed.
Choice¶
- class vpe.config.Choice(name, choices=(), default_value=None, description='')¶
A
config.Option
that can take one of a set of values.Parameters
- description
A description for the value, used for help generation.
- name
The name of the value.
- default_value
A default value for the option.
- choices
The set of allowed values.
Methods
Config¶
- class vpe.config.Config(name: str)¶
A collection of options forming a configuration.
Each option’s value is accessible as a pseudo attribute. All the methods of this class end with an underscore in order to prevent name clashes with options values.
Parameters
- name
The name of this configuration. By convention, for a plug-in, this is typically the plug-in’s name.
Attributes
- name¶
The name of this configuration. By convention, for a plug-in, this is typically the plug-in’s name.
Methods
- add_(option)¶
Add an option to this configuration.
Parameters
- option
The
config.Option
to add.
- get_(name)¶
Get the option with a given name.
Exceptions raised
- KeyError
if the option does not exist.
- ini_path_() pathlib.Path ¶
Get the INI file path.
- load_()¶
Load options from an INI file.
If, for example,
name
is ‘omega’ then (on Linux) the file ~/.vim/config.d/omega.ini will be loaded. Any existing option values not found in the file are left unchanged. Any value in the file that does not match a defined otion is simply ignored.
- options_() Dict[str, vpe.config.Option] ¶
Get the dictionary of options.
Int¶
- class vpe.config.Int(...)¶
Int( name, default_value=0, minval=None, maxval=None,
A
config.Option
that can take an integer value.Parameters
- description
A description for the value, used for help generation.
- name
The name of the value.
- default_value
A default value for the option.
- minval
The minimum permitted value;
None
means unconstrained.- maxval
The maximum permitted value;
None
means unconstrained.
Methods
- set(value: Union[int, str, bool]) str ¶
Try to set this option’s value.
Return value
A string describing why the attempt failed.
Option¶
- class vpe.config.Option(name, default_value, description='')¶
Details about a given option value.
Parameters
- name
The name of the value.
- default_value
A default value for the option.
- description
A description for the value, used for help generation.
Attributes
Properties
- property store_repr¶
“The representation of the
store_value
.
- property store_value¶
“The value for this option that will be store in the config file.
- property value¶
“The current value for this option.
Methods
- copy_to_store()¶
Copy this value to the persistent layer.
- set(_value: Union[int, str, bool]) str ¶
Try to set this option’s value.
This needs to be over-ridden in subclasses.
Return value
A string describing why the attempt failed.
- simple_field_args() Dict[str, Any] ¶
Generate keyword arguments for a simple UI field.
This may be extended in subclasses.
- values() List[Any] ¶
Get the list of choices.
This supports the protocol required for Tab completion support.