"default_tasks" config option not passed to forget
except through DOIT_CONFIG
#469
Description
PLEASE DO NOT USE ISSUE TRACKER TO ASK QUESTIONS: see contributing
Describe the bug
Consider the following python script that imports doit
:
#!/usr/bin/env python3
import sys
from doit.cmd_base import ModuleTaskLoader
from doit.doit_cmd import DoitMain
from pathlib import Path
# DOIT_CONFIG = {
# "action_string_formatting": "new",
# "verbosity": 2,
# "default_tasks": ["init_dataset"],
# }
def task_init_dataset():
return {
"actions": []
}
def main():
sys.exit(DoitMain(ModuleTaskLoader(globals()), extra_config={
"GLOBAL": {
"action_string_formatting": "new",
"verbosity": 2,
"default_tasks": ["init_dataset"],
# "forget_all": True
}
}).run(sys.argv[1:]))
if __name__ == "__main__":
main()
If, for example, I name the above script min.py
, do chmod 755 min.py
, and then run ./min.py forget
, I get divergent behavior when DOIT_CONFIG
is commented out or not. If DOIT_CONFIG
is commented out, I get:
william@xubuntu-dtrain:~/Projects/life-hacks/crzsnap$ ./min.py forget
Traceback (most recent call last):
File "/home/william/.local/lib/python3.10/site-packages/doit/doit_cmd.py", line 294, in run
return command.parse_execute(args)
File "/home/william/.local/lib/python3.10/site-packages/doit/cmd_base.py", line 150, in parse_execute
return self.execute(params, args)
File "/home/william/.local/lib/python3.10/site-packages/doit/cmd_base.py", line 570, in execute
return self._execute(**exec_params)
File "/home/william/.local/lib/python3.10/site-packages/doit/cmd_forget.py", line 62, in _execute
for name in forget_list:
TypeError: 'NoneType' object is not iterable
If I do not have DOIT_CONFIG
commented, I get a successful run:
william@xubuntu-dtrain:~/Projects/life-hacks/crzsnap$ ./min.py forget
forgetting init_dataset
Is this intentional or a bug? I'm guessing it is a bug, but am unsure.
Additional Context
This is mostly for future-me when he inevitably forgets.
For the purpose of finalizing a Command
to execute
, all config sources (including DOIT_CONFIG
, config INI/TOML files, and command-line params) are collected into the params
argument. The default tasks to execute are retrieved from params
.
Config values parsed from an INI/TOML file only override command-line arguments if the Command
subclass indicates that it supports the option via its cmd_options
attribute or similar. The forget command does not support default_tasks
as a command-line argument. OTOH, config loaded from DOIT_CONFIG
bypasses the command-line/config file arg checks and directly modifies params.
Should arguments provided from config INI/TOML files/extra_config
also bypass the command-line argument checks?
Environment
- OS:
william@xubuntu-dtrain:~/conf/backup$ uname -a Linux xubuntu-dtrain 5.15.0-112-generic #122-Ubuntu SMP Thu May 23 07:48:21 UTC 2024 x86_64 x86_64 x86_64 GNU/Linux
- python version:
william@xubuntu-dtrain:~/conf/backup$ python3 -V Python 3.10.12
- doit version:
william@xubuntu-dtrain:~/conf/backup$ doit --version 0.36.0 lib @ /home/william/.local/lib/python3.10/site-packages/doit
Upvote & Fund
- We're using Polar.sh so you can upvote and help fund this issue.
- We receive the funding once the issue is completed & confirmed by you.
- Thank you in advance for helping prioritize & fund our backlog.