spyder.api.config.mixins#

Spyder API helper mixins.

Classes

SpyderConfigurationAccessor()

Mixin used to access options stored in the Spyder configuration system.

SpyderConfigurationObserver()

Concrete implementation of the protocol spyder.config.types.ConfigurationObserver.

class spyder.api.config.mixins.SpyderConfigurationAccessor[source]#

Bases: object

Mixin used to access options stored in the Spyder configuration system.

get_conf(option: str | ~typing.Tuple[str, ...], default: ~spyder.config.user.NoDefault | bool | int | str | tuple | list | dict = <class 'spyder.config.user.NoDefault'>, section: str | None = None, secure: bool | None = False)[source]#

Get an option from the Spyder configuration system.

Parameters:
  • option (ConfigurationKey) – Name/Tuple path of the option to get its value from.

  • default (Union[NoDefault, BasicTypes]) – Fallback value to return if the option is not found on the configuration system.

  • section (str) – Section in the configuration system, e.g. shortcuts. If None, then the value of CONF_SECTION is used.

  • secure (bool) – If True, the option will be retrieved securely using the keyring Python package.

Returns:

value – Value of the option in the configuration section.

Return type:

BasicTypes

Raises:

configparser.NoOptionError – If the section does not exist in the configuration.

get_conf_options(section: str | None = None)[source]#

Get all options from the given section.

Parameters:

section (Optional[str]) – Section in the configuration system, e.g. shortcuts. If None, then the value of CONF_SECTION is used.

Returns:

values – Values of the option in the configuration section.

Return type:

BasicTypes

Raises:

configparser.NoOptionError – If the section does not exist in the configuration.

set_conf(option: str | Tuple[str, ...], value: bool | int | str | tuple | list | dict, section: str | None = None, recursive_notification: bool = True, secure: bool | None = False)[source]#

Set an option in the Spyder configuration system.

Parameters:
  • option (ConfigurationKey) – Name/Tuple path of the option to set its value.

  • value (BasicTypes) – Value to set on the configuration system.

  • section (Optional[str]) – Section in the configuration system, e.g. shortcuts. If None, then the value of CONF_SECTION is used.

  • recursive_notification (bool) – If True, all objects that observe all changes on the configuration section and objects that observe partial tuple paths are notified. For example if the option opt of section sec changes, then the observers for section sec are notified. Likewise, if the option (a, b, c) changes, then observers for (a, b, c), (a, b) and a are notified as well.

  • secure (bool) – If True, the option will be saved securely using the keyring Python package.

remove_conf(option: str | Tuple[str, ...], section: str | None = None, secure: str | None = False)[source]#

Remove an option in the Spyder configuration system.

Parameters:
  • option (ConfigurationKey) – Name/Tuple path of the option to remove its value.

  • section (Optional[str]) – Section in the configuration system, e.g. shortcuts. If None, then the value of CONF_SECTION is used.

  • secure (bool) – If True, the option will be removed securely using the keyring Python package.

get_conf_default(option: str | Tuple[str, ...], section: str | None = None)[source]#

Get an option default value in the Spyder configuration system.

Parameters:
  • option (ConfigurationKey) – Name/Tuple path of the option to remove its value.

  • section (Optional[str]) – Section in the configuration system, e.g. shortcuts. If None, then the value of CONF_SECTION is used.

property spyder_conf_version#

Get current version for the Spyder configuration system.

property old_spyder_conf_version#

Get old version for the Spyder configuration system.

class spyder.api.config.mixins.SpyderConfigurationObserver[source]#

Bases: SpyderConfigurationAccessor

Concrete implementation of the protocol spyder.config.types.ConfigurationObserver.

This mixin enables a class to receive configuration updates seamlessly, by registering methods using the spyder.api.config.decorators.on_conf_change() decorator, which receives 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 value.

on_configuration_change(option: str | Tuple[str, ...], section: str, value: Any)[source]#

Handle configuration updates for the option option on the section section, whose new value corresponds to value.

Parameters:
  • option (ConfigurationKey) – Configuration option that did change.

  • section (str) – Name of the section where option is contained.

  • value (Any) – New value of the configuration option that produced the event.

add_configuration_observer(func: Callable, option: str, section: str | None = None)[source]#

Add a callable to observe the option option on section section.

Parameters:
  • func (Callable) – Function that will be called when option changes.

  • option (ConfigurationKey) – Configuration option to observe.

  • section (str) – Name of the section where option is contained.

Notes