Pylint 递归地获取给定的文件名

发布于 2024-11-14 07:13:07 字数 353 浏览 4 评论 0原文

我有一个 Django 项目,我正在通过它进行 Pylinting。

我有几种情况,我希望能够递归地查找具有给定名称的所有文件,并以不同的方式对它们进行 pylint(使用不同的选项)。例如,我想为 urls.py 和 admin.py 设置不同的选项

以下内容适用于 1 个目录..

pylint ./project_name/*/urls.py

但我想让该 * 递归...这样它深入到子目录。

有办法实现吗?


更新 我还希望它们全部作为单个 pylint 输出运行,而不是按顺序运行

I have a Django project and I'm working on Pylinting my way through it.

I have a couple situations where I'd like to be able to recursively find all files with a given name and pylint them differently (using different options). For example, I'd like to set different options for pylinting urls.py and admin.py

The following works for 1 directory..

pylint ./project_name/*/urls.py

But I'd like to make that * recursive... so that it drills into sub directories.

Any way to achieve that?


Update
I'd also like them all to run as a single pylint output, not sequentially

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

半世晨晓 2024-11-21 07:13:07

根据您的操作系统,您可以使用:

find project_name -name urls.py | xargs pylint

Depending on your operating system, you could use:

find project_name -name urls.py | xargs pylint
小瓶盖 2024-11-21 07:13:07

尝试使用 find:

find ./project_name/ -name "urls.py" -exec pylint '{}' \;

如果您想在一次调用 pylint 中运行多个文件:

find ./project_name/ -name "urls.py" -exec pylint '{}' +

Try with find:

find ./project_name/ -name "urls.py" -exec pylint '{}' \;

If you want to run multiple files in a single call to pylint:

find ./project_name/ -name "urls.py" -exec pylint '{}' +
一杯敬自由 2024-11-21 07:13:07
  • 获取所有 python 文件(递归)
  • 将它们一次性全部传递给 pylint (来自 Robin 的回答)
  • 在控制台中显示输出并将其放入文件

find 中。 -名称“*.py”-print0 | xargs -0 pylint 2>&1 | xargs -0 pylint 2>&1 | err_pylint.rst~

  • Get all python files (recursive)
  • Pass them all at once to pylint (from answer by Robin)
  • Show output in console and put it in a file

find . -name "*.py" -print0 | xargs -0 pylint 2>&1 | tee err_pylint.rst~

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文