13

I'm using pep8 to check for coding guidelines. I am getting results only for the current directory. And not all directory or sub directory inside it. How to do that?

When running it from the level of container/project, I don't get pyc files' errors. When I run it from container/project/app, I get the pyc files' errors. Following is the tree structure:

container
      project
            app
                  __init__.py
                  admin.py
                  models.py
                  views.py
                  tests.py
                  file1.py

            project
                  __init__.py
                  urls.py
                  wsgi.py
                  settings.py

            templates
                  __init__.py
                  home.html
                  page1.html

            manage.py
            pylintrc
            setup.cfg

      README

And following is the content of setup.cfg:

[pep8]
ignore=E122,E123,E128
exclude=pylintrc,setup.cfg
max-line-length=80
Charles
  • 50,943
  • 13
  • 104
  • 142
user3432110
  • 217
  • 1
  • 5
  • 11
  • You mean you are using the [`pep8` command line tool](http://pep8.readthedocs.org/en/latest/)? It will scan subdirectories if the argument is a directory name, unless you excluded them with the `--exclude` option. How are you calling it? – Martijn Pieters Mar 19 '14 at 10:46
  • I've edited the question including details. I run from command line `pep8 *` – user3432110 Mar 19 '14 at 11:44
  • 1
    Why not use `pep8 .` instead? – Martijn Pieters Mar 19 '14 at 11:45
  • I just did that after removing the ignore and exclude sections from the setup.cfg file. But it gives errors related to settings.py, urls.py and file1.py. No pylintrc, no setup.cfg, no pyc related errors. – user3432110 Mar 19 '14 at 11:48
  • `pep8` will by default only scan for `.py` files in directories, it *will* traverse subdirectories. What makes you think it is skipping subdirectories for you? – Martijn Pieters Mar 19 '14 at 11:50
  • In fact, `settings.py` and `urls.py` and `file1.py` are in two different subdirectories, so the command *works*. What did you expect to happen instead? – Martijn Pieters Mar 19 '14 at 11:51
  • I have got this part. It is working for the --filename parameter that defaults to *.py files. I was expecting the same. And yes it does scan all non-py files in the current directory. But not in the subsequent child directories. So, I got just curious, why doesn't it scan non-py files in the child directories, since they are also present in the `*` wild card and am neither excluding them as well. – user3432110 Mar 19 '14 at 12:06
  • That's not how it works, it is your *shell or console* that expands the wildcard. `pep8` is handed a list of names, not `*`. If you wanted `pep8` to scan all subdirectories using the `*` wildcard, you need to tell it to so with `--filename='*'`. – Martijn Pieters Mar 19 '14 at 12:08
  • Thanks. Also, can you help me understand, what is the root or root path of the project? It should be `container/project` . But am confused since it doesn't have an __init__.py file. I face frequent problems related to python paths. SO it would help me understand it. – user3432110 Mar 19 '14 at 12:10
  • Your `container/python` root contains packages, it is not *itself* a package. You don't use `from python.app import admin`, you use `from app import admin`. – Martijn Pieters Mar 19 '14 at 12:11
  • So, `container/project` is the root and it should be present in the python path? – user3432110 Mar 19 '14 at 12:13
  • This looks like a Django project to me; `container/project` would be part of the Python path, yes. – Martijn Pieters Mar 19 '14 at 12:13
  • Yes. Thanks. Hope to hear from you on my future questions as well. :-) – user3432110 Mar 19 '14 at 12:16

1 Answers1

27

The pep8 command does scan subdirectories automatically. It'll look for any file matching the patterns named in the --filename option (the default is *.py).

Scan your project with pep8 . or pep8 directoryname.

If you run pep8 * in a directory, then your shell expands the * into all files in the current directory, so pep8 will scan all those files even if they don't match the --filename file patterns. That could include files like setup.cfg, which is not a file you'd want to scan.

Any subdirectories of the current directory would still be scanned too (as they are named in the list of names the shell produces when you use the * wildcard), but then pep8 will only look for files matching the --filename option again.

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343