Exclude .env directory from flake8 tests?
Asked Answered
N

5

35

Problem

I'm getting thousands of flake8 errors stemming from my local .env. An example of some of the error messages:

./env/lib/python3.7/site-packages/pip/_vendor/pyparsing.py:3848:80: E501 line too long (85 > 79 characters)
./env/lib/python3.7/site-packages/pip/_vendor/pyparsing.py:3848:84: E202 whitespace before ')'
./env/lib/python3.7/site-packages/pip/_vendor/pyparsing.py:3855:51: E201 whitespace after '('
./env/lib/python3.7/site-packages/pip/_vendor/pyparsing.py:3855:65: E202 whitespace before ')'
./env/lib/python3.7/site-packages/pip/_vendor/pyparsing.py:3858:50: E201 whitespace after '('
./env/lib/python3.7/site-packages/pip/_vendor/pyparsing.py:3858:78: E202 whitespace before ')'
./env/lib/python3.7/site-packages/pip/_vendor/pyparsing.py:3861:31: E231 missing whitespace after ','
./env/lib/python3.7/site-packages/pip/_vendor/pyparsing.py:3865:1: W293 blank line contains whitespace
./env/lib/python3.7/site-packages/pip/_vendor/pyparsing.py:3866:1: E302 expected 2 blank lines, found 1

My directory looks like this:

enter image description here

My flake8 file looks like this:

[flake8]
exclude =
    migrations,
    __pycache__,
    manage.py,
    settings.py,

Question

How can I add my env file contents to the exclude list in flake8?

What I've tried

I've tried adding:

  env,
./env,

I've tried taking off commas and adding:

[flake8]
exclude =
    migrations
    __pycache__
    manage.py
    settings.py
    env
    .env
    ./env
    env/
    .env/

Running flake8 --exclude migrations,pycache,manage.py,settings.py,env returns:

./app/core/models.py:7:80: E501 line too long (93 > 79 characters)
./app/core/models.py:13:66: E225 missing whitespace around operator
./app/core/models.py:13:80: E501 line too long (103 > 79 characters)
./app/core/admin.py:10:1: W293 blank line contains whitespace
./app/core/admin.py:11:1: W293 blank line contains whitespace
./app/core/admin.py:13:1: W293 blank line contains whitespace
./app/core/tests/test_commands.py:23:47: W292 no newline at end of file
./app/core/management/commands/wait_for_db.py:21:69: W292 no newline at end of file
./app/project/urls.py:23:2: W292 no newline at end of file
./app/inventory/serializers.py:4:1: E302 expected 2 blank lines, found 1
./app/inventory/serializers.py:8:1: W391 blank line at end of file
./app/inventory/urls.py:5:70: W291 trailing whitespace
./app/inventory/urls.py:7:26: W292 no newline at end of file
./app/inventory/views.py:1:1: F401 'rest_framework.response.Response' imported but unused
./app/inventory/views.py:7:1: E302 expected 2 blank lines, found 1
./app/inventory/views.py:11:1: W293 blank line contains whitespace
./app/inventory/views.py:12:5: E303 too many blank lines (2)
./app/inventory/views.py:36:43: W292 no newline at end of file
./app/inventory/tests/test_api.py:2:1: F401 'django.urls.reverse' imported but unused
./app/inventory/tests/test_api.py:7:1: W293 blank line contains whitespace
./app/inventory/tests/test_api.py:9:8: E111 indentation is not a multiple of four
./app/inventory/tests/test_api.py:10:8: E111 indentation is not a multiple of four
./app/inventory/tests/test_api.py:10:40: W291 trailing whitespace
./app/inventory/tests/test_api.py:11:1: W293 blank line contains whitespace
./app/inventory/tests/test_api.py:12:8: E111 indentation is not a multiple of four
./app/inventory/tests/test_api.py:13:8: E111 indentation is not a multiple of four
./app/inventory/tests/test_api.py:18:41: W291 trailing whitespace
./app/inventory/tests/test_api.py:19:1: W293 blank line contains whitespace
./app/inventory/tests/test_api.py:25:37: W291 trailing whitespace
./app/inventory/tests/test_api.py:26:41: W291 trailing whitespace
./app/inventory/tests/test_api.py:27:1: W293 blank line contains whitespace
./app/inventory/tests/test_api.py:31:1: W391 blank line at end of file
./app/inventory/tests/test_api.py:31:1: W293 blank line contains whitespace
Nashner answered 26/3, 2020 at 11:10 Comment(8)
Have you tried using env? Is the result the same?Stampede
Thanks Lucus but I have. I will update the question to include thisNashner
or rather .env/ ?Thermophone
I have tried this just now too. I'll add that to the things tried.Nashner
Can you try providing the exclude patterns on the command line? flake8 --exclude migrations,__pycache__,manage.py,settings.py,envStampede
Hi Lucus, I've just done that and updated the questionNashner
It looks like it works with the command line then?Stampede
@TomMac Now that you've updated your question, you can see flake8 is only complaining about problems in app... isn't that what you want?Breeching
A
12

I notice your .flake8 file is inside app folder. I presume you are starting flake8 from outside the app folder, in other words from the project root.

Move .flake8 to the project root, and everything's gonna work:

mv app/.flake8 .
Ashleeashleigh answered 26/3, 2020 at 11:32 Comment(0)
B
35

Remove the commas. Lists in these .ini files are simply multi-line lists:

[flake8]
exclude =
    migrations
    __pycache__
    manage.py
    settings.py
    env
    .env
Breeching answered 26/3, 2020 at 11:22 Comment(4)
Thanks AKX but it doesn't seem to change anything, I'm still getting the errorsNashner
Your directory is also called env, not .env :)Breeching
Haha I'm trying with env .env ./env env/ .env/ !Nashner
the documentation for flake8 uses commas flake8.pycqa.org/en/latest/user/configuration.htmlRora
A
12

I notice your .flake8 file is inside app folder. I presume you are starting flake8 from outside the app folder, in other words from the project root.

Move .flake8 to the project root, and everything's gonna work:

mv app/.flake8 .
Ashleeashleigh answered 26/3, 2020 at 11:32 Comment(0)
S
8

It's also possible to exclude via --exclude flag of the cli.

 --exclude patterns    Comma-separated list of files or directories to
                    exclude. (Default: ['.svn', 'CVS', '.bzr', '.hg',
                    '.git', '__pycache__', '.tox', '.eggs', '*.egg'])

note that here it is a comma-separated list, unlike in the flake8 config file

Susette answered 4/12, 2020 at 12:47 Comment(0)
G
1
flake8 --exclude venv --ignore=E501,F401

example exclude folder venv and ignore errors

Greybeard answered 11/10, 2023 at 11:51 Comment(0)
P
1

I found this much more intuitive to ignore certain folders from linting:

flake8 --extend-exclude .venv,dist

See documentation with flake8 --help

  --exclude patterns    Comma-separated list of files or directories to
                        exclude. (Default: ['.svn', 'CVS', '.bzr', '.hg',
                        '.git', '__pycache__', '.tox', '.eggs', '*.egg'])
  --extend-exclude patterns
                        Comma-separated list of files or directories to add to
                        the list of excluded ones.
Porush answered 27/5 at 9:11 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.