14

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

Brant
  • 5,721
  • 4
  • 36
  • 39

3 Answers3

16

Depending on your operating system, you could use:

find project_name -name urls.py | xargs pylint
Jasmijn
  • 9,370
  • 2
  • 29
  • 43
  • 4
    This seems to do exactly what I need it to... it looks like it's running them all as a single pylint execution – Brant Jun 06 '11 at 20:37
  • As a side note, it is important not to strip any `__init__.py` file from the paths returned by find (so as to get the module parsed instead) with this solution, or you may get `duplicate-code` warnings should you have other files in your modules. – 7heo.tk May 24 '16 at 14:03
4

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 '{}' +
beatgammit
  • 19,817
  • 19
  • 86
  • 129
Cédric Julien
  • 78,516
  • 15
  • 127
  • 132
  • 1
    This worked great but it ran them one at a time... not something I mentioned in my post but I need them all to run as a single pylint. I'll update the question. Still +1-ing you – Brant Jun 06 '11 at 20:36
  • @Brant - You can do this with find. I've edited the answer with an example. – beatgammit May 16 '14 at 01:32
3
  • 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~

Christophe Roussy
  • 16,299
  • 4
  • 85
  • 85