@add_short_name("pf") deftask_preflight(): """Run pre commit for all files. Returns: dict: doit config. """ command = ["poetry", "run", "pre-commit", "run", "-a"] return {"actions": [command], "verbosity": 2}
这样运行 doit 会识别到两个 task ,可以分别通过 doit pf 或者 doit preflight 触发指令
1 2 3
>doit list pf Run pre commit for all files. preflight Run pre commit for all files.
但是默认排序是按命名来的,如果命令很多就会混在一起
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
>doit list b Run black format all python files. black Run black format all python files. d Run mkdocs serve. dd Run mike to deploy docs. docs Run mkdocs serve. docs_deploy Run mike to deploy docs. f Run `black` `isort`. format Run `black` `isort`. i Run isort format all python files. isort Run isort format all python files. l Run flakehell lint for all python files. lint Run flakehell lint for all python files. m Run mike serve. mike Run mike serve. pf Run pre commit for all files. preflight Run pre commit for all files. pt Run pytest. pytest Run pytest.
可以使用 doit list –sort=definition 的方式让排序变成创建顺序。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
>doit list --sort=definition f Run `black` `isort`. format Run `black` `isort`. pf Run pre commit for all files. preflight Run pre commit for all files. b Run black format all python files. black Run black format all python files. i Run isort format all python files. isort Run isort format all python files. l Run flakehell lint for all python files. lint Run flakehell lint for all python files. pt Run pytest. pytest Run pytest. d Run mkdocs serve. docs Run mkdocs serve. m Run mike serve. mike Run mike serve. dd Run mike to deploy docs. docs_deploy Run mike to deploy docs.