在我正在处理的python项目的tox.ini文件中,我有一个格式化步骤,如下所示:
[testenv:formatting]
deps =
isort
black
flake8
flake8-quotes
pep8-naming
commands =
# Check source code
isort {toxinidir}/project --check-only --recursive
black {toxinidir}/project --check --diff --py36
flake8 {toxinidir}/project
# Check tests
isort {toxinidir}/tests --check-only --recursive
black {toxinidir}/tests --check --diff --py36
flake8 {toxinidir}/tests
# Check setup.py
isort {toxinidir}/setup.py --check-only --recursive
black {toxinidir}/setup.py --check --diff --py36
flake8 {toxinidir}/setup.py
# Check docs/conf.py
isort {toxinidir}/docs/conf.py --check-only --recursive
black {toxinidir}/docs/conf.py --check --diff --py36
flake8 {toxinidir}/docs/conf.py
是否有某种方法可以消除冗长的信息,并在文件列表中运行这3条命令(isort
,black
和flake8
)?
类似的东西:
commands =
isort {toxinidir}/{list_of_files} --check-only --recursive
black {toxinidir}/{list_of_files} --check --diff --py36
flake8 {toxinidir}/{list_of_files}
{list_of_files}
与["project", "tests", "setup.py", "docs/conf.py"]
类似吗?
我已经尝试过进行Shell for循环操作,但是在命令中似乎不起作用。
这是我想念的东西吗?还是不可能?
答案 0 :(得分:1)
我从没使用过isort
和black
,但是我希望所有这三个命令可以一次接受多个参数,因此您应该能够编写:
isort {toxinidir}/project {toxinidir}/tests {toxinidir}/setup.py {toxinidir}/docs/conf.py --check-only --recursive
black {toxinidir}/project {toxinidir}/tests {toxinidir}/setup.py {toxinidir}/docs/conf.py --check --diff --py36
flake8 {toxinidir}/project {toxinidir}/tests {toxinidir}/setup.py {toxinidir}/docs/conf.py
PS:默认情况下,tox
以{toxinidir}
作为当前目录运行命令,因此为了简洁起见,您可以省略该部分:
isort project tests setup.py docs/conf.py --check-only --recursive
# etc.