To get flycheck working for Python, I had reached a satisfactory .emacs
, which turned out to require no more than:
(require 'flycheck)
(add-hook 'after-init-hook #'global-flycheck-mode)
Now after a bit of looking forward at what Python 3.6 will be like, even a two-liner
class Foo():
pass
gets a whole slew of warnings:
Too few public methods (0/2) [too-few-public-methods]
Class has no __init__ method [no-init]
Old-style class defined. [old-style-class]
Missing class docstring [missing-docstring]
Missing module docstring [missing-docstring]
despite that I'm now firmly back in 2.7 (sudo port select --set python python27
).
Emacs gets us used to being context-agnostic. It usually doesn't matter what is on the system; one gets the same behavior if one starts from an unchanged .emacs
. What else might have changed in my system to trigger a sudden increase in flycheck warnings?
OK, I found the answer.
flycheck chooses (silently?) flake8, and if that is not found, it falls back on pylint (and subsequently on pycompile).
The problem was that the symlink flake8
had vanished. Here is why/how.
After selecting python36 and back
~/ > sudo port select --set python python36
~/ > sudo port select --set python python27
and after selecting pip36 and back
~/ > sudo port select --set pip pip36
~/ > sudo port select --set pip pip27
the symlink /opt/local/bin/flake8
disappears. Only flake8-2.7 is left.
> ls -l /opt/local/bin/flake8*
lrwxr-xr-x 1 root admin 70 20 Mar 16:35 /opt/local/bin/flake8-2.7 -> /opt/local/Library/Frameworks/Python.framework/Versions/2.7/bin/flake8
What happens, presumably, is that flake8
points to nothing (port select
is updated, and the symlink is removed) when you update to Python 3.6 but do not have flake8-36. The symlink cannot be reinstated when you downgrade to Python 2.7 (one of these, perhaps the former, merits a warning—maybe as a minor bug in MacPorts).
~/ > sudo port select --list flake8
Available versions for flake8:
flake8-27
none (active)
The solution is to explicitly point flake8
to flake8-27
when you downgrade.
~/ > sudo port select --set flake8 flake8-27
Selecting 'flake8-27' for 'flake8' succeeded. 'flake8-27' is now active.
And the link comes back and flycheck chooses flake8
over pylint
.
> ls -l /opt/local/bin/flake8*
lrwxr-xr-x 1 root admin 25 7 Sep 09:01 /opt/local/bin/flake8 -> /opt/local/bin/flake8-2.7
lrwxr-xr-x 1 root admin 70 20 Mar 16:35 /opt/local/bin/flake8-2.7 -> /opt/local/Library/Frameworks/Python.framework/Versions/2.7/bin/flake8