-
Notifications
You must be signed in to change notification settings - Fork 214
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
Problems with defaults
and constants
#13
Comments
Basically, the problem is how to do this as easy as possible. The beauty of the constants module approach was really simple: just define everything that needs to remain constant in a single file, and then import that file. Of course I do see the problem that occurs with the keyword arguments. Bloody object oriented programmers redefining all sorts of crap at runtime... ;) I've been thinking about a almost the exact approach as you propose for a while. Basically, the idea is to keep a dict (lets call it
I suppose that if |
Yes, a I would suggest to put the settings object (be it a custom class or a
Btw, I removed all the other redirect imports from |
I noticed they went missing, and figured this was the reason. My preference I agree on keeping the init as clean as possible; this seems like a On Thu, Jan 9, 2014 at 9:32 AM, Sebastiaan Mathot
|
- As suggested in esdalmaijer#13
The problem
Right now, configuration options are stored in the module
defaults
and overwritten by values from the moduleconstants
if available. This works fine when you indeed use aconstants.py
file to set options. But if you try to change options at runtime things get rough.Basically, what happens is that all modules start like this:
What this does is copy the values into the module itself. This means that changing an option in defaults, like so ....
... only works when no modules have been loaded yet. If a module has already been loaded, it needs to explicitly reloaded in order for the option to take effect. For the plug-ins, this required a hack, which is implemented in
pygaze_init.reload_pygaze()
.Another problem is that you can specify many options through keywords as well as the config system. When you actually start using the keywords, things easily get messy and confusing.
A solution
In general terms, there should be a config system in which all options are stored in a single place, without any copying of config options. (Copying now happens implicitly due to the import structure shown above.)
There are many ways to do this, but one way would be to mimick the config system of OpenSesame.
Basically, there is a single instance of the
config
class, calledcfg
(a singleton design pattern), and this can be accessed from anywhere in the code, like so:Perhaps the
constants.py
file could be read and then used to set options through this config system on start-up.I would also do away with all the keyword arguments, such as
disptype
, that should really be set through the config system.What do you think?
The text was updated successfully, but these errors were encountered: