Elpy: Relaxing highlighting of warnings/errors (excluding codes)

Created on 2 Sep 2014  路  11Comments  路  Source: jorgenschaefer/elpy

Hi,

I have been using Elpy for some time now, and I love it. I hope to be able to contribute to the repository at some in the near future. In the mean time, thanks again for this great package.

One problem I am having is the warning/error highlighting on my files seem a bit too strict (I get lots of errors for E111 indentation is not a multiple of four, E501 line too long etc.). I guess my coding style isn't good (good to know though!), but almost every line in my file has an exclamation point and is underlined in red.

Is there any way to relax the rules for underlines/exclamation points? Perhaps there is a way of letting the user provide a list of codes to exclude from the warnings? In my case for example, excluding E111 would probably be enough.

On this note, is there any way within Elpy to automatically fix the indentation of a file to make it compliant with E111?

Question

Most helpful comment

$ echo "print('This is a very long line that flake8 should complain about if I do not tell it to shut up')" > foo.py
$ flake8 foo.py 
foo.py:1:80: E501 line too long (98 > 79 characters)
$ (echo '[flake8]' ; echo 'ignore = E501') > setup.cfg
$ flake8 foo.py 

This seems to work for me.

ignore = E226,E302,E41, E111, W191

Make sure not to add spaces after commas. It seems flake8 does not like those.

All 11 comments

Thank you for the kind words! :-)

Is there any way to relax the rules for underlines/exclamation points?

By default, Elpy uses the flake8 tool to find coding style problems. This tool can be configured in, for example, the setup.cfg file. You can ignore specific errors there.

See the flake8 documentation for details: http://flake8.readthedocs.org/en/latest/config.html

On this note, is there any way within Elpy to automatically fix the indentation

I'm afraid that's not possible right now. There is a package called autopep8 that I hope to be providing a simple interface to at some point, but in the meantime, you can run it yourself:

https://pypi.python.org/pypi/autopep8/

Thanks @jorgenschaefer Where can I find setup.cfg??

I searched find . -name "setup.cfg" and nothing came up (except on a Python package that seems to have a file with the same name).

setup.cfg is part of the standard Python package layout, usually placed at the project root next to setup.py.

Did this work for you?

Any update on this?

No updates, so I assume the problem is solved. Closing this. Please do not hesitate to open a new issue if there are any further problems.

Thanks @jorgenschaefer. Sorry I didn't get back to you on this earlier. I have tried several things on this without luck:

I have a script my_script.py in one folder, and I have added:

1) a file called setup.cfg to the same folder. The script includes:

[flake8]
ignore = E226,E302,E41, E111, W191
max-line-length = 160
exclude = tests/*
max-complexity = 10

2) The same contents to a file under my home directory called ~/.config/flake8.

However, when I do M-x elpy-check on the file, I still see W191 warnings (as well as many others) highlighted on my file. Do you know what could be wrong?

$ echo "print('This is a very long line that flake8 should complain about if I do not tell it to shut up')" > foo.py
$ flake8 foo.py 
foo.py:1:80: E501 line too long (98 > 79 characters)
$ (echo '[flake8]' ; echo 'ignore = E501') > setup.cfg
$ flake8 foo.py 

This seems to work for me.

ignore = E226,E302,E41, E111, W191

Make sure not to add spaces after commas. It seems flake8 does not like those.

Thanks a lot @jorgenschaefer . I will keep investigating. Hopefully the spaces were the problem!

Thanks a lot for this discussion. It helped me. I eventually found this - http://flake8.readthedocs.org/en/latest/config.html
It's better to create user-level settings if you want it to be for all projects.

Thanks a lot for this discussion. It helped me. I eventually found this - http://flake8.readthedocs.org/en/latest/config.html
It's better to create user-level settings if you want it to be for all projects.

@zeeshansayyed That's a very useful point!
Here's an updated URL to what you linked: http://flake8.pycqa.org/en/latest/user/configuration.html

Was this page helpful?
0 / 5 - 0 ratings

Related issues

rakanalh picture rakanalh  路  5Comments

rthompsonj picture rthompsonj  路  6Comments

kirk86 picture kirk86  路  5Comments

twangnh picture twangnh  路  6Comments

kapilsh picture kapilsh  路  3Comments