I'm using vanilla Emacs and I installed lsp-mode as follows:
(use-package lsp-mode
:init
(setq lsp-keymap-prefix "C-c l")
:commands (lsp lsp-deferred)
:config (defun lsp-go-install-save-hooks ()
(add-hook 'before-save-hook #'lsp-format-buffer t t)
(add-hook 'before-save-hook #'lsp-organize-imports t t))
:hook (
(lsp-mode . lsp-enable-which-key-integration)
(go-mode . lsp-deferred)
(go-mode . lsp-go-install-save-hooks)
(typescript-mode . lsp-deferred)
(python-mode . lsp-deferred)
)
)
For Python I installed this. Everything seems to be working fine, but the problem is that I'm not able to override the default pycodestyle settings. For example, it complains about long lines > 79 so I tried adding in the root of the project the following setup.cfg:
[pycodestyle]
max-line-length=99
But it's not taken into account, am I missing something? I saw that there's the possibility to change the setting globally, but I'd like to have it on a per-project basis.
UPDATE
If pycodestyle is ran from the terminal it works as expected: it complains with the default line-length limit and it doesn't if I increase it to a value that is greater to the longest line that I have in the code.
The *lsp-log* buffer doesn't seem to provide any meaningful information:
Command "pyls" is not present on the path.
Command "pylsp" is present on the path.
Command "pyls" is not present on the path.
Command "pylsp" is present on the path.
Found the following clients for /<some path>/sample-app/sample_app/__init__.py: (server-id pylsp, priority -1)
The following clients were selected based on priority: (server-id pylsp, priority -1)
If I exec the flycheck-describe-checker command this is the output:
lsp is a Flycheck syntax checker.
This syntax checker checks syntax in the major mode(s)
`python-mode', `lsp-placeholder-mode', and uses a custom predicate.
Documentation:
A syntax checker using the Language Server Protocol (LSP)
provided by lsp-mode.
See https://github.com/emacs-lsp/lsp-mode.
If I disable flycheck by executing the command flycheck-disable-checker indeed the warnings go away, but it stops all the checks. So it seems like flycheck is the responsible for not honoring the setup.cfg.
I was able to understand what it seems to be happening. It seems that under the hood flycheck is using flake8 instead of pycodestyle. Indeed after I change setup.cfg into this:
[flake8]
max-line-length=99
Everything started working as expected.
The problem is that according to the documentation of python-lsp-server by default it should use pycodestyle. Moreover, checking through flake8 seems to be requiring 3rd party plugins according to the doc that I didn't install.
Not everything works as expected yet, as for example I have some complaints related to D100 and D104 that if I put them as ignore in the configuration their not honored yet.
Related
I use VS Code Version 1.19.3 with Python 2.7 on Windows.
Recently pylint (code analyzer) shown an error message
"E1601:print statement used"
But I don't know why! Can someone help me?
The print statement is correct as per my knowledge!
Is it a bug or a feature is missing?
Greetings niesel
The warning originates from Pylint, which is a very helpful tool for a dynamic language with loose syntax like Python. Since you are programming in Python 2.x where print is perfectly valid, I suggest you put a file in the root of your repo named .pylintrc and use it to configure Pylint.
To disable the print warning and leave everything else to the default, enter these two lines in your .pylintrc file:
[MESSAGES CONTROL]
disable=print-statement
You will also need to tell Visual Studio Code to use your configuration file by opening your workspace or user settings and add this:
{
"python.linting.enabled": true,
"python.linting.pylintEnabled": true,
"python.linting.pylintArgs": [
"--rcfile=/path/to/.pylintrc"
]
}
More options
To get a good idea of available configuration options open a terminal/prompt and run this command to generate a sample configuration file:
pylint --generate-rcfile > sample_pylintrc
The problem is, that changing from print statement to print function doesn't help much. So it seems, that it is some bug in VS Code Python module (2018.1 (01 Feb 2018)), as after this update I've found the same problem in my VS Code within my old projects
I've found reffered bug on their github
PS: vscode-python has changed pylint options since 2018.1. In order to return old behavior you may disable python.linting.pylintUseMinimalCheckers option for the workspace or for the userspace.
it's not an error per-se, it's just PyLint complaining about those legacy statements. PyLint will also complain about missing spaces before commas, those kind of style errors.
PyLint is there to warn you about possible problems. Your code will break when running python 3, so it warns you before it happens.
Note that print is a statement in python 2.x (which explains the message), and became a function in python 3.x.
Fix it by changing to:
print("test")
Since it's not a tuple, it works fine and does exactly the same for all versions of python, and PyLint will stop complaining.
you can also get rid of PyLint altogether: Windows 10 - Visual Studio Code - removing pylint (not sure if it's a good idea)
I use Tox to run unit tests, with a flake8 command that checks for code formatting errors. Each time I code in PyCharm, I run tox then realise I have a bunch of annoying formatting errors I have to back and manually fix. I would like PyCharm to automatically format the code (according to flake8 google for me each time it auto-saves after I stop typing.
my tox testenv looks like this:
[testenv:flake8]
commands=flake8 <my_code_directory>
deps =
flake8==2.4.1
flake8-import-order==0.11
pep8-naming==0.4.1
[flake8]
max-line-length = 120
import-order-style = google
Is this possible? Do I have to download a specific plugin somewhere? If not with flake8, what about just PEP-8?
Flake8 and import ordering are not auto-fixable in a way that complies with what you're seeing. You can auto-fix pep8 with autopep8.
There are discussions here about implementing this for Flake8 though.
For automatically sorting import statements use isort. Consider using black to auto-format your Python code.
Edit: ruff can replace flake8 and isort and is also much faster because it's based on Rust. It also supports LSP, so PyCharm you should be able to use it from within PyCharm.
The tool you want is probably autopep8. This is especially because the warning codes it uses correspond to the flake8 ones.
For example, if you want to autofix all instances of E701 multiple statements on a single line warning, run the following
for f in `find . -name "*.py"`; do autopep8 --in-place --select=E701 $f; done
I want SublimeLinter to ignore PEP-8 E402 error messages. I have changed the package user settings to
"pep8_ignore": [
"E402"
]
and have closed and reopened Sublime Text. SublimeLinter still displays an E402 error code. Why?
I am using ST3 with these packages: BufferScrool, LaTeXing, PackageControl, PackageResourceViewer, R-Box, Side Bar, Anaconda, and SublimeLinter.
So first, I'd note that Anaconda performs its own version of PEP-8 linting, so you've got some functional duplication happening...
Second, I'd note that you don't seem to have SublimeLinter-pep8 installed, which means (since SublimeLinter installed by Package Control on ST3 is going to be SublimeLinter3, which requires linting plugins to do anything) that its not SublimeLinter. Things to consider: (1) are the linting errors you see coming from Anaconda rather than SublimeLinter? If so you need to set "pep8_ignore" in the Anaconda user settings rather than SublimeLinter. (2) Are you (somehow) using the old, unsupported version of SublimeLinter on ST3? In that case, either (a) switch to using Anaconda and ignore SublimeLinter for the purposes of linting python files or (b) upgrade SublimeLinter to SublimeLinter3, install SublimeLinter-pep8 and see below.
Assuming you are actually trying to use the SublimeLinter-pep8 plugin on SublimeLinter3: SublimeLinter3, which uses an entirely different settings structure from the previous version of SublimeLinter. As a result, the "pep8_ignore" setting is no longer honoured. This is the expected behaviour.
In order to accomplish what you want you need these settings set in the settings file:
{
"user": {
"linters": {
"pep8": {
"ignore": "E402"
}
}
}
}
But have a careful read of the SublimeLinter settings docs as there are a lot of different ways to configure your settings, and have a look at the docs for the pep-8 plugin
As ig0774 mentioned, Anaconda has its own built-in linters (pylint, pep8, pep257, and pyflakes), which are producing the error message you'd like to ignore, not SublimeLinter. If for some reason you want to shut off linting with Anaconda and perform it with one or more SublimeLinter plugins, you'll need to install and configure those plugins. Search Package Control for more information.
To configure Anaconda, first open Preferences -> Package Settings -> Anaconda -> Settings-Default, then Settings-User in the same sub-menu. Copy the entire contents of Default to User, then close Default, as you can't edit it anyway. I highly recommend reading through the entire file, as it is well-commented. The setting you are looking for is also called "pep8_ignore", which in the current version of Anaconda is on line 318. This file seems to change rather often, so this position may change over time. Just search for the name.
If you want to turn off Anaconda's linting capabilities completely, set "anaconda_linting" to false.
I just installed jedi-vim with vundle
My vim version is 7.3.429.
I installed jedi vi pip
every time I hit . or <C-Space> I get this error.
Omni completion (^O^N^P) Pattern not found
when I searched here for this pattern I found a solution to use vim-jedi instead. But unfortunatelly this occours with jedi-vim.
Here is some output of some registers:
:set omnifunc
omnifunc=jedi#complete
:messages
Messages maintainer: Bram Moolenaar <Bram#vim.org>
"models.py" 31L, 1052C
<emptyline>
Because this line was in my .vimrc:
autocmd FileType python setlocal omnifunc=pythoncomplete#Complete
I could not use jedi for a long time. When removed it, it's OK.
:set omnifunc
omnifunc=jedi#completions
IIRC, jedi-vim was publicly released one or two weeks ago. I doubt you will get much help outside of its issue tracker.
Anyway, the plugin seems to be using Vim's omni completion under the hood, specifically the <C-x><C-o> shortcut which, in your case, doesn't seem to return anything because it can't recognize the keyword before the ..
Either jedi-vim doesn't work or your code is wrong or the plugin is badly installed.
http://michaeljaylissner.com/blog/using-pylint-in-geany#comments
This blog says to set build command as
pylint -r no "%f"
and set a custom error regex
(W|E|F):([0-9]+):(.*)
The commenter suggests that with command
PYTHONPATH=${PYTHONPATH}:$(dirname %d) pylint --output-format=parseable --reports=n "%f"
that it is possible to click on a line number in log and be brought there by geany. I tried this and it has not worked for me.
In my project file, I have added
[build_settings]
error_regex=^(W|E|F):([0-9]+):(.*)
After reloading the file, same result. Am I setting the error_regex correctly? Why doesnt this work?
I'm the commenter on the blog post you cite.
I'm using a Debian-based system at the moment (Linux Mint Debian, to be precise), and using Geany 0.20. What I have is a file named filetypes.python in ~/.config/geany/filedefs which contains this:
[build-menu]
FT_00_LB=pep8
FT_00_CM=pep8 --repeat --count "%f"
FT_00_WD=
FT_01_LB=PyLint (basic)
FT_01_CM=PYTHONPATH=${PYTHONPATH}:"%d" pylint --output-format=parseable --reports=n --errors-only "%f"
FT_01_WD=
FT_02_LB=PyLint (full)
FT_02_CM=PYTHONPATH=${PYTHONPATH}:"%d" pylint --output-format=parseable "%f"
FT_02_WD=
error_regex=^([^:]+?):([0-9]+):.+
Note that the key difference between my setup and the blog post is that i'm using --output-format=pareseable, and my error_regex is a little less pylint-specific, so that it will work for pep8 too.
The PYTHONPATH=${PYTHONPATH}:"%d" bit is to add the current working directory to my custom python path, and I guess, off the top of my head, it won't work like that on Windows, so if you're on Windows you'll certainly need to modify (or drop) that bit. In fact, if you're on Windows, please indicate that, as there might be a few bits that need changing.
I have written a plugin which checks your code with pep8 pylint and pyflakes the code is available on launchpad and is packaged for ubuntu in a ppa.
https://code.launchpad.net/~oly/geany-python-code-checker/trunk
https://launchpad.net/~oly/+archive/geany
maybe useful for some one, you can toggle some options on and off as well like checking of line length.