7

I am using elpy for my Python development, but I would like to set the per-line character limit to 120 instead of the default 80 used by PEP8. Any suggestions on how I can do this? Even better, it would be great if I can customize this setting on a per-project basis.

I have tried the following:

  • M-x customize-group elpy
  • M-x customize-mode elpy-mode
  • M-x customize-mode python-mode

but I can't seem to find the option that customizes the line character limit.

modulitos
  • 2,432
  • 1
  • 18
  • 36
  • I suspect you want fill-column. – Dan Jun 13 '16 at 01:13
  • @Dan can you elaborate a bit? I tried setting fill-column (`M-x set-fill-column` and via `M-x customize-variable fill-column`), but elpy still shows an error for lines longer than 79 characters, with the message `E501 line too long (81 > 79 characters)`. I tried refreshing the buffer too, but no luck. Any suggestions? – modulitos Jun 13 '16 at 03:41
  • This seems like something that needs to be set through the `flake8` config file or through the `autopep8` config file depending on what you want. Take a look at the configuration page https://flake8.readthedocs.io/en/latest/config.html – Jules Jun 13 '16 at 14:36

1 Answers1

9

If you want to customize per project basis, you can create a setup.cfg with custom config like this

[flake8]
max-line-length = 160

If you want to change this globally, you can change flake8 config as mentioned here https://flake8.pycqa.org/en/latest/user/configuration.html#user-configuration

Chillar Anand
  • 4,042
  • 1
  • 23
  • 52
  • Thank you very much! It's exactly what I needed, and now I see that I can use the flake8 config for my elpy-mode. It makes sense, because I believe elpy uses flake8 as the default syntax checker under the hood. – modulitos Jun 13 '16 at 19:48
  • 5
    That link is dead - this seems like the current version: [https://flake8.readthedocs.io/en/latest/user/configuration.html#user-configuration](https://flake8.readthedocs.io/en/latest/user/configuration.html#user-configuration) – n1k31t4 Feb 09 '18 at 16:16
  • Would someone please tell me how this file is supposed to be created if it doesn't exist? And what's the path? – Qohelet Mar 24 '21 at 17:59
  • @Qohelet You can manually create the file and add the required sections to it. By default, it should be in your project root directory. https://docs.python.org/3/distutils/configfile.html – Chillar Anand Mar 25 '21 at 03:47
  • @n1k31t4 Thanks for the new link. Update it. – Chillar Anand Mar 25 '21 at 03:49
  • 1
    @ChillarAnand - tried it and it doesn't work, that's how I came here. Emacs still complains – Qohelet Mar 25 '21 at 19:46
  • If you're on Linux/Mac, the config should be in `~/.config/flake8` (**not** `~/.config/.flake8`) – eric.mitchell Aug 25 '21 at 04:39