-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Add proper config module #128
Conversation
Just wanted to add that I rewrote 'populate.py' to use the new module and tidied it up while I was at it. It did not change any other modules because I'm not sure this get's accepted because of the ConfigParser pull request, in which you stated that you did not want to break compatability with third party plugins (if I recall that correctly). Although this is the case here, too, I hope you see the advantages of this approach. So if you're willing to accept this PR, I will update all other modules to use |
So....What do you think? |
I like the idea of moving away from passing |
Well, any plugin module that needs its own config value (
|
Yeah, that makes sense. (Although in the I'm fine with merging this in after code review and testing, but the docs would need some major updates. (At this point, it also makes sense to start discussing some sort of Jasper v2 (CC @shbhrsaha). We can continue discussion offline.) |
|
||
class AbstractConfig(object): | ||
""" | ||
Base class which acts as an interface for custom Config classes. |
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.
Can you remove these indentations in the docstrings? Don't think we do that elsewhere.
Pending these changes, I don't think we're too far off here (although the modules need to be modified, of course). |
plugin_path = self.sanitize_path(path) | ||
path = ["plugins", plugin] | ||
path.extend(plugin_path) | ||
return self.set(path, value=value) |
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.
The logic to create the plugin path is the same in plugin_get and plugin_set, can this be abstracted?
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.
I guess.
I'm not completely sure if they'll useful anyway (probably they should be left out and then made methods of the plugin base class (config_set()
and config_get
).
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.
I think the plugin's config_get
should call the config's plugin_get
, same thing for set.
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.
They could just call config.set(['plugins', self.SLUG, 'foo'], value='bar')
?
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.
Yes... but I like the idea of just saying config_set('foo', 'bar')
. Simple, less duplication, less errors.
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.
Yes, my comment referred to the inner workings of a method that belongs to the base plugin class (i.e. the class that all Plugins inherit from). Therefore, every Plugin will be able to do self.config_set(foo, bar)
by default.
I'd like to suggest that I remove the This way, we can simplify the core jasper code and use it right now. Modules get the |
What do you think? |
I think it's a good idea to allow v1 modules to be compatible. This sounds quite reasonable. We should also check whether the method requires the parameter, and if not then not send it (that will allow modules to stop receiving the parameter and start using the new interface). |
3bcd0db
to
95e3fc6
Compare
I removed |
95e3fc6
to
9ff4d39
Compare
Also, a config file named profile_defaults.yml containing the default values has been added to the static/ folder.
9ff4d39
to
3245550
Compare
Rationale
Jasper really needs a proper config module.
I saw multiple errors caused by modules/classes/functions trying to access the yaml-configuration looking for values that were not set (e.g.
gmail_address
). This means that we'll end up writing checking functions all over the place or using a generaltry: ... except: ...
-block wrapped aroundConversation.handleForever()
(which currently prevents us from killing Jasper with CRTL-C by the way).So the obvious solution is to create a new module (named
jasperconf
in this case), that does this kind of stuff for us. It offers us a config singleton, which relieves us from the obligation to pass around theprofile
-variable or open the config file every time we need a value.It also adds proper separation between main and plugin namespace in the config file (all plugins access the config via
plugin_get
/plugin_set
methods, which retrieves and sets value inplugins
→plugin_name
→ x.If that namespace should ever be changed - no problem, just change the jasperconf module and probably add a conversion for old config files.
Last (and probably least), it also decouples the access to config values from the actual backend (YAML) and thus makes a transition - if neccessary - (e.g. to ConfigParser) a lot easier.
Usage
Main program
Plugins (in client/modules)