williamboman / mason.nvim

Portable package manager for Neovim that runs everywhere Neovim runs. Easily install and manage LSP servers, DAP servers, linters, and formatters.
Apache License 2.0
7.24k stars 258 forks source link

Python resolution order does not respect PATH #1748

Open VRehnberg opened 4 days ago

VRehnberg commented 4 days ago

I've searched open issues for similar requests

I've manually reviewed logs to find potential errors

I've recently downloaded the latest plugin version of mason.nvim

Problem description

From a conda environment with Python 3.9.17 (picked up by :checkhealth mason) pypi installer picks up and uses system python version 3.10. Output from MasonLog:

[INFO  ons  3 jul 2024 11:11:01] ...e/nvim/lazy/mason.nvim/lua/mason-core/installer/init.lua:184: Executing installer for Package(name=ruff-lsp) {}
[ERROR ons  3 jul 2024 11:11:01] ...e/nvim/lazy/mason.nvim/lua/mason-core/installer/init.lua:249: Installation failed for Package(name=ruff-lsp) error=spawn: python3.10 failed with exit code 1 and signal 0. 

Expected behavior

PATH should be respected. It looks like the culprit is [resolve_python3](https://github.com/williamboman/mason.nvim/blob/main/lua/mason-core/installer/managers/pypi.lua#L20-L33)() and probably the call for versioned candidates at https://github.com/williamboman/mason.nvim/blob/main/lua/mason-core/installer/managers/pypi.lua#L91

Instead of taking the python resolved by PATH it picks the latest python version that is supported.

Steps to reproduce

  1. Create a conda virtual environment with a supported Python version older than the system one
  2. Set PATH="append" (or "skip"):
    {
    "williamboman/mason.nvim",
    config = function()
      require('mason').setup({
        PATH = "append",
      })
    end
    }
  3. Open python file with Neovim (might need some python lsp neovim package as well, not sure what is telling mason to install ruff-lsp)

Affected packages

ruff-lsp

Neovim version (>= 0.7)

NVIM v0.10.0 Build type: RelWithDebInfo LuaJIT 2.1.1713484068

Operating system/version

Linux c3se-TP6 6.5.0-41-generic #41~22.04.2-Ubuntu SMP PREEMPT_DYNAMIC Mon Jun 3 11:32:55 UTC 2 x86_64 x86_64 x86_64 GNU/Linux

Healthcheck

==============================================================================
mason: require("mason.health").check()

mason.nvim ~
- OK mason.nvim version v1.10.0
- OK PATH: append
- OK Providers: 
    mason.providers.registry-api
    mason.providers.client
- OK neovim version >= 0.7.0

mason.nvim [Registries] ~
- OK Registry `github.com/mason-org/mason-registry version: 2024-07-02-cyan-tub` is installed.

mason.nvim [Core utils] ~
- OK unzip: `UnZip 6.00 of 20 April 2009, by Debian. Original by Info-ZIP.`
- OK wget: `GNU Wget 1.21.2 built on linux-gnu.`
- OK curl: `curl 7.81.0 (x86_64-pc-linux-gnu) libcurl/7.81.0 OpenSSL/3.0.2 zlib/1.2.11 brotli/1.0.9 zstd/1.4.8 libidn2/2.3.2 libpsl/0.21.0 (+libidn2/2.3.2) libssh/0.9.6/openssl/zlib nghttp2/1.43.0 librtmp/2.3 OpenLDAP/2.5.17`
- OK gzip: `gzip 1.10`
- OK tar: `tar (GNU tar) 1.34`
- OK bash: `GNU bash, version 5.1.16(1)-release (x86_64-pc-linux-gnu)`
- OK sh: `Ok`

mason.nvim [Languages] ~
- WARNING Go: not available
  - ADVICE:
    - spawn: go failed with exit code - and signal -. go is not executable
- WARNING cargo: not available
  - ADVICE:
    - spawn: cargo failed with exit code - and signal -. cargo is not executable
- WARNING luarocks: not available
  - ADVICE:
    - spawn: luarocks failed with exit code - and signal -. luarocks is not executable
- WARNING Ruby: not available
  - ADVICE:
    - spawn: ruby failed with exit code - and signal -. ruby is not executable
- WARNING RubyGem: not available
  - ADVICE:
    - spawn: gem failed with exit code - and signal -. gem is not executable
- WARNING Composer: not available
  - ADVICE:
    - spawn: composer failed with exit code - and signal -. composer is not executable
- WARNING PHP: not available
  - ADVICE:
    - spawn: php failed with exit code - and signal -. php is not executable
- WARNING javac: not available
  - ADVICE:
    - spawn: javac failed with exit code - and signal -. javac is not executable
- WARNING java: not available
  - ADVICE:
    - spawn: java failed with exit code - and signal -. java is not executable
- WARNING julia: not available
  - ADVICE:
    - spawn: julia failed with exit code - and signal -. julia is not executable
- OK python: `Python 3.9.17`
- OK node: `v18.16.0`
- OK pip: `pip 24.0 from /home/vikren/miniconda3/envs/ds/lib/python3.9/site-packages/pip (python 3.9)`
- OK python venv: `Ok`
- OK npm: `9.5.1`

mason.nvim [GitHub] ~
- OK GitHub API rate limit. Used: 0. Remaining: 60. Limit: 60. Reset: ons  3 jul 2024 12:49:17.
  Install and authenticate via gh-cli to increase rate limit.

Screenshots or recordings

No response

VRehnberg commented 4 days ago

A quick fix for me was to modify https://github.com/williamboman/mason.nvim/blob/main/lua/mason-core/installer/managers/pypi.lua#L91:

-    local target = resolve_python3(versioned_candidates) or stock_target
+    local target = stock_target
VRehnberg commented 4 days ago

My suggested solution would be to just use stock_target and check if it is compatible. If isn't, throw an error and exit rather than trying to use a non-default python. (But, that could be a breaking change for those that rely on the old behaviour).