I'm struggling to get line length correctly setup under Elpy.

I found How to customize the line character length in elpy? and have in the past found flycheck cannot find module for pylint.

My configuration looks like (I've tried both autopep8 and yapf)...

(add-hook 'python-mode-hook
      (lambda ()
        (setq flycheck-python-pylint-executable "~/.virtualenvs/default/bin/pylint")
        (setq flycheck-pylintrc "~/.emacs.d/settings/.pylintrc")))
;; enable autopep8 formatting on save
(require 'py-autopep8)
(add-hook 'elpy-mode-hook 'py-autopep8-enable-on-save)
;; (require 'py-yapf)
;; (add-hook 'python-mode-hook 'py-yapf-enable-on-save)

I have as per the suggestions in autopep8 · PyPI created ~/.config/pycodestyle which contains...

max_line_length = 120
ignore = E501

...and yet on saving a file it doesn't apply the 120 character rule in so much as lines that are > 120 characters are not auto-formatted and still reports in *Messages*...

line too long (124 > 79 characters) [E501] [2 times]

I've also set the following configuration option

(setq-default fill-column 120)

...which I'm unsure whether it will be interfering with things.

Any ideas or suggestions on how to configure autopep8 to automatically split lines at 120 characters would be very gratefully received as I feel like I've been going round in circles, despite seemingly trying the suggested solutions (I admit I may have misunderstood how to do this though or just cocked things up!).

  • An alternative solution is to use black, which will handle all formatting for you and integrates with elpy. – al0 May 1 at 14:01

I am using configuration per project. The configuration filesetup.cfg is needed at root folder of your project.

Below is my setting in setup.cfg.

max-line-length = 120
max_line_length = 120
column_limit = 120
| improve this answer | |
  • 1
    Thanks, I'll give a go at putting in the options to my global configuration (would rather avoid having things set on a per project basis). – slackline Dec 3 '19 at 10:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.