neoclide / coc-python

Python extension for coc.nvim, fork of vscode-python
574 stars 51 forks source link

python.sortImports.path is parsed incorrectly #71

Open namliz opened 5 years ago

namliz commented 5 years ago

coc-settings.json:


{
"python.sortImports.path": "~/.local/bin/isort",
"python.formatting.blackPath": "~/.local/bin/black",
}

Vim command:


:CocCommand => python.sortImports Sort Imports

[coc.nvim] spawn ~/.local/bin/isort ENOENT

Replacing ~/.local/bin/isort with /Users/Name/.local/bin/isort works perfectly however. Black on the other hand works fine with the tilda expansion.

DanCardin commented 5 years ago

"python.sortImports.path": "isort" appears to work; which at least for me seems to be fine as I'm already used to my editor being run from inside a venv that's got isort, for it to work.

What's sort of annoying is that in order for it to pick up settings, I need to "python.sortImports.args": ["-sp", "/Users/user/.isort.cfg"],, ~/.isort.cfg does not work.

But even worse, isort no config option (by default) uses isort's own config finding mechanism to find its config, which means the above wont work for projects that have their own isort config specified in the repo, for example. Ideally internally the plugin would just defer to isort for it's config location.

im-n1 commented 5 years ago

Well... isort doesn't work for me at all. I have to use vim-isort and run :Isort manually.

DanCardin commented 5 years ago

The relevant parts of my config look like:

{
  "coc.preferences.rootPatterns": [".git", "pyproject.toml", "setup.py", ".env"],
  "python.sortImports.path": "${workspaceFolder}/.venv/bin/isort",
  "python.sortImports.args": ["-sp", "/Users/user/.isort.cfg"],
   "coc.preferences.formatOnSaveFiletypes": ["python"],
}

the rootPatterns bit makes workspaceFolder work; which allows me to target the right versions of my linters.

It just so happens that all the projects i work on have basically the same config, so I'm skating by with a global isort config (but as i said above, this is pretty poor. it should just let isort find the config).

And finally the formatOnSaveFiletypes makes it call isort on save. Those

zhyu commented 4 years ago

I also got the ENOENT error.

Instead of replacing ~ with the absolute path to $HOME, using ${env.HOME} works for me as well. Accessing the environment variable is more stable when you want to share the config file across platforms.

rbhanot4739 commented 4 years ago

For me python.sortImports command does not work correctly even if I specify the isort path in coc-settings.json. For example if I have a simple script test.py with just bunch of import statements

import glob
import sys
import argparse
import collections
import dis

Running python.sortImports produces this output which is expected

import argparse
import collections
import dis
import glob
import sys

However if I run the same command again, it produces the below output which is weird and removes some of the import statements and duplicates others.

import dis
import glob
import sys
import glob
import sys