fannheyward / coc-pyright

Pyright extension for coc.nvim
MIT License
1.27k stars 45 forks source link

Pyright doesn't use python.pythonPath when there is no virtual environment #603

Closed avnotaklu closed 2 years ago

avnotaklu commented 2 years ago

CocCommand pyright.version : 1.1.164 Platform : Ubuntu 20.04.2

Pyright doesn't use python.pythonPath when no virtual env is available instead it uses python from some other environment (Which doesn't even exist now, i deleted it a while ago ). Using pyrightconfig.json i can specify virtual env but default python path doesn't work( Pyright doesn't find modules and says [Pyright reportMissingModuleSource] [W] Import "requests" could not be resolved from source), It also jumps to fallbackStubs when i jump to definition( even modules like os ) which i guess is expected as the directory it says it finds python in doesn't even exist.

CocCommand workspace.showOutput Pyright

Workspace: /home/ssp/python/imageDownload/pexels
Using python from /home/ssp/python/django/CHANNELS_BACKUP/chat/env/bin/python

[Info  - 9:11:34 am] Pyright language server 1.1.163 starting
[Info  - 9:11:34 am] Server root directory: /home/ssp/.config/coc/extensions/node_modules/coc-pyright/node_modules/pyright/dist/
[Info  - 9:11:34 am] No configuration file found.
[Info  - 9:11:34 am] No pyproject.toml file found.
[Info  - 9:11:34 am] Setting pythonPath for service "pexels": "/home/ssp/python/django/CHANNELS_BACKUP/chat/env/bin/python"
[Warn  - 9:11:34 am] stubPath /home/ssp/python/imageDownload/pexels/typings is not a valid directory.
[Info  - 9:11:34 am] Unable to get Python version from interpreter
[Info  - 9:11:34 am] Assuming Python platform Linux
[Info  - 9:11:34 am] Searching for source files
[Info  - 9:11:34 am] Found 1 source file

Also even though virtual environments work (I think so because Pyright detects modules jumps to definition etc) when i don't run from root of the project; CocCommand workspace.showOuput says that Pyright uses python from another environment. Probably there is some bug in workspace.showOutput CocCommand, I that case is there any other way to know what python path pyright is using.

showOutput gives correct output when running vim from project root . showOuput using virtual env and when i don't run from root.

Workspace: /home/ssp/python/imageDownload/pexels
Using python from /home/ssp/python/django/CHANNELS_BACKUP/chat/env/bin/python

[Info  - 9:35:40 am] Pyright language server 1.1.163 starting
[Info  - 9:35:40 am] Server root directory: /home/ssp/.config/coc/extensions/node_modules/coc-pyright/node_modules/pyright/dist/
[Info  - 9:35:41 am] Setting pythonPath for service "pexels": "/home/ssp/python/django/CHANNELS_BACKUP/chat/env/bin/python"
[Info  - 9:35:41 am] Loading configuration file at /home/ssp/python/imageDownload/pexels/pyrightconfig.json
[Info  - 9:35:41 am] No include entries specified; assuming /home/ssp/python/imageDownload/pexels
[Info  - 9:35:41 am] Auto-excluding **/node_modules
[Info  - 9:35:41 am] Auto-excluding **/__pycache__
[Info  - 9:35:41 am] Auto-excluding .git
[Warn  - 9:35:41 am] stubPath /home/ssp/python/imageDownload/pexels/typings is not a valid directory.
[Warn  - 9:35:41 am] Exception received when installing file system watcher: TypeError [ERR_FEATURE_UNAVAILABLE_ON_PLATFORM]: The feature watch recursively is unavailable on the current platform, which is being used to run Node.js
[Warn  - 9:35:41 am] Exception received when installing file system watcher: TypeError [ERR_FEATURE_UNAVAILABLE_ON_PLATFORM]: The feature watch recursively is unavailable on the current platform, which is being used to run Node.js
[Info  - 9:35:41 am] Searching for source files
[Info  - 9:35:41 am] Found 1 source file

CocConfig

{
    "languageserver": {
        "ccls": {
            "command": "ccls",
            "filetypes": [
                "c",
                "cpp",
                "objc",
                "objcpp"
            ],
            "rootPatterns": [
                ".ccls",
                "compile_commands.json",
                ".vim/",
                ".git/",
                ".hg/"
            ],
            "initializationOptions": {
                "cache": {
                    "directory": "/tmp/ccls"
                },
                "highlight": { "lsRanges" : true }
            }
        }
    },
    "python.pythonPath" : "/usr/bin/python",
    "python.linting.enabled" : true,
    "python.linting.pylintEnabled": true
}
avnotaklu commented 2 years ago

just tried running :CocLocalConfig and specifying python path in local coc-settings.json it worked. However pythonPath in global coc-settings.json still doesn't work.

fannheyward commented 2 years ago

Workspace: /home/ssp/python/imageDownload/pexels Using python from /home/ssp/python/django/CHANNELS_BACKUP/chat/env/bin/python

coc-pyright will try to detect the Python bin from your project root, here is /home/ssp/python/imageDownload/pexels, do you have anything like in your root:

  1. .python-version file
  2. Pipfile file
  3. poetry.lock
  4. any venv folder that contains pyvenv.cfg file
avnotaklu commented 2 years ago

coc-pyright will try to detect the Python bin from your project root, here is /home/ssp/python/imageDownload/pexels, do you have anything like in your root:

  1. .python-version file

  2. Pipfile file

  3. poetry.lock

  4. any venv folder that contains pyvenv.cfg file

No, these files don't exist in this folder Pyright gives this behavior for every file inside /home/ssp/python and its every subdirectory except the ones that have virtual env, None of those directories have any of these files and the only folders that contain pyvenv.cfg are inside ~/python/django

For directories other than ~/python it uses same path as that of which python. Is this intended behavior because pyright still doesn't respect python.pythonPath setting?

avnotaklu commented 2 years ago

I just looked and there was local coc config with that python path in ~/python. It was causing all the trouble. It's using correct path now after i deleted that config.

Thanks for the help.