spyder.api.config.mixins#
Spyder API configuration helper mixins.
Module Attributes
Type alias for the set of basic Python types supported as config values. |
Classes
Mixin to access options stored in the Spyder configuration system. |
|
Methods to receive and respond to changes in Spyder's configuration. |
- spyder.api.config.mixins.BasicTypes#
Type alias for the set of basic Python types supported as config values.
- class spyder.api.config.mixins.SpyderConfigurationAccessor[source]#
Bases:
objectMixin to access options stored in the Spyder configuration system.
- CONF_SECTION: str | None = None#
Name of the default configuration section to use for this object.
Will be used to record its permanent data in Spyder’s config system.
- get_conf(option: ConfigurationKey, default: NoDefault | BasicTypes = <class 'spyder.config.user.NoDefault'>, section: str | None = None, secure: bool = False) BasicTypes[source]#
Retrieve an option’s value from the Spyder configuration system.
- Parameters:
option (spyder.config.types.ConfigurationKey) – Name/tuple path of the configuration option value to get.
default (spyder.config.user.NoDefault | BasicTypes, optional) – Fallback value to return if the option is not found on the configuration system. No default value if not passed.
section (str | None, optional) – Name of the configuration section to use, e.g.
"shortcuts". IfNone, then the value ofCONF_SECTIONis used.secure (bool, optional) – If
True, the option will be retrieved from secure storage using thekeyringPython package. Otherwise, will be retrieved from Spyder’s normal configuration (the default).
- Returns:
value – Value of
optionin the configurationsection.- Return type:
BasicTypes
- Raises:
configparser.NoOptionError – If the
sectiondoes not exist in Spyder’s configuration.
- get_conf_options(section: str | None = None) list[str][source]#
Get all option names from the given section.
- Parameters:
section (str | None, optional) – Name of the configuration section to use, e.g.
"shortcuts". IfNone, then the value ofCONF_SECTIONis used.- Returns:
values – List of option names (keys) in the configuration
section.- Return type:
- Raises:
configparser.NoOptionError – If
sectiondoes not exist in the configuration.
- set_conf(option: spyder.config.types.ConfigurationKey, value: spyder.api.config.mixins.BasicTypes, section: str | None = None, recursive_notification: bool = True, secure: bool = False) None[source]#
Set an option’s value in the Spyder configuration system.
- Parameters:
option (spyder.config.types.ConfigurationKey) – Name/tuple path of the configuration option to set.
value (BasicTypes) – Value to set for the given configuration option.
section (str | None, optional) – Name of the configuration section to use, e.g.
"shortcuts". IfNone, then the value ofCONF_SECTIONis used.recursive_notification (bool, optional) – If
True, all objects that observe all changes on the configurationsectionas well as objects that observe partial tuple paths are notified. For example, if theoption"opt"ofsection"sec"changes, then all observers for sectionsecare notified. Likewise, if the option("a", "b", "c")changes, then observers for("a", "b", "c"),("a", "b")and"a"are all notified.secure (bool, optional) – If
True, the option will be saved in secure storage using thekeyringPython package. Otherwise, will be saved in Spyder’s normal configuration (the default).
- Return type:
None
- remove_conf(option: spyder.config.types.ConfigurationKey, section: str | None = None, secure: bool = False) None[source]#
Remove an option from the Spyder configuration system.
- Parameters:
option (spyder.config.types.ConfigurationKey) – Name/tuple path of the configuration option to remove.
section (str | None, optional) – Name of the configuration section to use, e.g.
"shortcuts". IfNone, then the value ofCONF_SECTIONis used.secure (bool, optional) – If
True, the option will be removed from secure storage using thekeyringPython package. Otherwise, will be removed from Spyder’s normal configuration (the default).
- Return type:
None
- get_conf_default(option: spyder.config.types.ConfigurationKey, section: str | None = None) NoDefault | spyder.api.config.mixins.BasicTypes[source]#
Get an option’s default value from the Spyder configuration system.
- Parameters:
option (spyder.config.types.ConfigurationKey) – Name/tuple path of the config option to get the default value of.
section (str | None, optional) – Name of the configuration section to use, e.g.
"shortcuts". IfNone, then the value ofCONF_SECTIONis used.
- Returns:
The
option’s default value, orspyder.config.user.NoDefaultif one is not set.- Return type:
spyder.config.user.NoDefault | BasicTypes
- class spyder.api.config.mixins.SpyderConfigurationObserver[source]#
Bases:
SpyderConfigurationAccessorMethods to receive and respond to changes in Spyder’s configuration.
This mixin enables a class to receive configuration updates seamlessly, by registering methods using the
on_conf_change()decorator, which takes a configuration section and option to observe.When a change occurs on any of the registered configuration options, the corresponding registered method is called with the new config value.
- __init__() None[source]#
Create a new
SpyderConfigurationObserver.Important
Classes or their parents implementing this mixin must define a
CONF_SECTIONclass attribute with the name of their default configuration section.- Return type:
None
- on_configuration_change(option: spyder.config.types.ConfigurationKey, section: str, value: spyder.api.config.mixins.BasicTypes) None[source]#
Handle configuration value updates for a config option.
- Parameters:
option (spyder.config.types.ConfigurationKey) – Name/tuple path of the configuration option that changed.
section (str) – Name of the section containing
option, e.g."shortcuts".value (BasicTypes) – New value of the configuration option that produced the event.
- Return type:
None
- add_configuration_observer(func: Callable, option: spyder.config.types.ConfigurationKey, section: str | None = None) None[source]#
Add a callable to observe changes to a specific configuration option.
- Parameters:
func (Callable) – Function/method that will be called when
optionchanges.option (spyder.config.types.ConfigurationKey) – Name/tuple path of the configuration option to observe.
section (str | None, optional) – Name of the section containing
option, e.g."shortcuts". IfNone, then the value ofCONF_SECTIONis used.
- Return type:
None
Notes
This is only necessary if you need to add a callable that is not a class method to observe an option. Otherwise, you only need to decorate your method with
on_conf_change().