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
Look for DOIT_CONFIG in config so it can be set in conf.py #1716
Conversation
if 'DOIT_CONFIG' in config: | ||
DOIT_CONFIG = config['DOIT_CONFIG'] | ||
else: | ||
DOIT_CONFIG = {} |
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.
It's easier to just do DOIT_CONFIG = config.get('DOIT_CONFIG', {})
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.
Indeed it is. I have this habit of writing all of my code like I'm preparing to show it in my CS1 course.
@@ -62,6 +62,7 @@ | |||
|
|||
|
|||
def main(args=None): | |||
|
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.
Don’t put empty lines at the beginnings of functions.
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.
Removed. I guess I didn't clean up properly after removing some debug prints.
'reporter': ExecutedOnlyReporter, | ||
'outfile': sys.stderr, | ||
} | ||
DOIT_CONFIG['reporter'] = ExecutedOnlyReporter |
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.
Wouldn’t it be nicer to let users’ DOIT_CONFIG
override this? Some people might want to override our opinionated reporter choice.
if self.quiet:
DOIT_CONFIG = {…} # from original code
else:
DOIT_CONFIG = {…}
DOIT_CONFIG.update(config.get('DOIT_CONFIG', {}))
We also need to pop DOIT_CONFIG
out of the config dict in nikola.py
(we don’t need to save it anywhere though) so self.configured
works correctly.
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.
updating the dictionary as you suggest makes sense to me. I hadn't thought that you guys would want anyone to override what you had coded in there.
Since DOIT_CONFIG
may or may not be in config. Why don't I just check and pop it out of config in the load_tasks
function?
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.
So, it seems like going back to the original and adding this one line:
DOIT_CONFIG.update(config.pop('DOIT_CONFIG', {}))
would do what you want.
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.
load_tasks
is called after configuration is passed to the site object. We can’t do that.
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.
So then we can't just pop it out and throw it away in __init__
It has to stay somewhere so that load_tasks
can get to it.
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.
Then pop it out in Nikola.__init__
and use nikola._doit_config
here. (besides, where does config
come from in this code?)
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.
config is declared as a global on line 58 of __main__
and then populated on line 114 in main
after loading conf.py
config = conf.__dict__
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.
ah, a global. That’s evil.
Still, you can just get it from self.nikola
if you pop it out there.
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 tried:
AttributeError: 'Nikola' object has no attribute '_doit_config'
I'm guessing you were suggesting I create _doit_config
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, that’s what I was suggesting. Add after nikola.py
line 287:
self._doit_config = config.pop('DOIT_CONFIG', {})
I guess normal Nikola users might not know about doit at all. So maybe better expose it as a different name than |
“Normal Nikola users” should not know about this setting. |
why not? This allow users to change default from command line options. |
configuring a value for a command line option certainly felt to me like a thing "normal" users may want to do. |
Is DOIT_CONFIG even documented by doit itself? |
I found it here: http://pydoit.org/cmd_run.html I don't spend my whole day looking through source :-) |
@@ -241,14 +241,15 @@ def load_tasks(self, cmd, opt_values, pos_args): | |||
if self.quiet: | |||
DOIT_CONFIG = { | |||
'verbosity': 0, | |||
'reporter': 'zero', | |||
'reporter': 'zero' |
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.
No need to change it, but I tend to leave the last commas in this sort of things because it makes the diff better the next time something is added :-)
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.
(It also lets the next person just type in their changes without having to care about adding a comma.)
It looks good enough for me. Add yourself to AUTHORS? |
@Kwpolska it is documented here: http://pydoit.org/configuration.html#configuration-at-dodo-py @bnmnetp every command line option can be configured (and also some options that are not available through the command line) |
Look for DOIT_CONFIG in config so it can be set in conf.py (Fix #1715)
Addresses feature request in #1715