-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
PR: Refactor Spyder configuration system to use an observer pattern #14852
Conversation
Thanks on tackling this area because I found the old API hard to work with. Where is the new design explained? I am lazy and don't want to search through 100+ commits and files changed. 😄 |
@jitseniesen Basically the idea is to register any object that requires updates on a configuration option of a section via This PR also introduces a decorator from spyder.config.manager import CONF
from spyder.api.decorators import on_conf_change
class ConfObserver:
def __init__(self):
# Register class to listen for changes in all the registered options
for section in self._configuration_listeners:
observed_options = self._configuration_listeners[section]
for option in observed_options:
CONF.observe_configuration(self, section, option)
def on_configuration_change(self, option, section, value):
section_recievers = self._configuration_listeners.get(section, {})
option_recievers = section_recievers.get(option, [])
for receiver in option_recievers:
method = getattr(self, receiver)
method(value)
@on_conf_change(section='editor')
def section_change_reciever(self, section):
# section contains the new values of the editor section
...
@on_conf_change(section='main_interpreter', option='custom_interpreter')
def on_interpreter_change(self, interpreter):
# interpreter contains the value of main_interpreter
... Furthermore, to simplify things, this PR adds a new class mixin from spyder.api.mixins import SpyderConfigurationObserver
class ConfObserver(SpyderConfigurationObserver):
@on_conf_change
def this_section_change(self, value):
# Listen for all changes in the widget `CONF_SECTION`
# value contains the section options as a dictionary.
...
@on_conf_change(section='editor')
def section_change_reciever(self, section):
# section contains the new values of the editor section
...
@on_conf_change(option='opt')
def on_opt_change(self, value):
# value contains the new value of `opt` in the widget `CONF_SECTION`.
...
@on_conf_change(option=['opt1', 'opt2', 'opt3'])
def on_opts_change(self, option, value):
# Receive multiple option change. Option will contain the option name and value, its corresponding value.
...
@on_conf_change(section='section', option=['opt2', 'opt3', 'opt4', ('opt', 'nested_dict', 'value')])
def on_section_multiple_option_change(self, option, value):
# Recieve multiple option change from section `section`.
...
@on_conf_change(section='main_interpreter', option='custom_interpreter')
def on_interpreter_change(self, interpreter):
# interpreter contains the value of main_interpreter
... By default, FInally, all new actions created using I hope this explanation is clear enough, otherwise, feel free to ask any question |
23eac45
to
7a05263
Compare
Hello @andfoy! Thanks for updating this PR. We checked the lines you've touched for PEP 8 issues, and found:
Comment last updated at 2021-03-16 00:19:43 UTC |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @andfoy! I left an initial review for you.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@andfoy, this is a more in-depth review for you.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks a lot @andfoy! Fantastic job with this refactoring!!
Description of Changes
This PR enables the Spyder configuration system to use an observer pattern in order to propagate changes across all the application actions/options/etc. This PR will supersede the current API configuration propagation logic
Issue(s) Resolved
Fixes #
Affirmation
By submitting this Pull Request or typing my (user)name below,
I affirm the Developer Certificate of Origin
with respect to all commits and content included in this PR,
and understand I am releasing the same under Spyder's MIT (Expat) license.
I certify the above statement is true and correct: @andfoy