mypy icon indicating copy to clipboard operation
mypy copied to clipboard

Setting python_executable in $XDG_CONFIG_HOME/mypy/config does not work

Open doolio opened this issue 1 year ago • 0 comments

Bug Report

I have mypy installed as a dependency of pylsp-mypy a plugin for the python-lsp-server. I install python-lsp-server with pipx and then (pipx) injected pylsp-mypy into the venv created by pipx for the python-lsp-server. Whether I expose the mypy app globally (i.e. outside the python-lsp-server pipx venv) or not mypy reports an "Invalid python executable" error when working in a projects venv. This is the case whether the project venv uses the same base python that was used to install pipx, python-lsp-server and pylsp-mypy or not.

Installing mypy directly with pipx results in the same error.

Setting python_executable = "${VIRTUAL_ENV}/bin/python" in $XDG_CONFIG_HOME/mypy/config does not work as I would expect. I did not test the other possible global config files.

However, setting it that way in the projects pyproject.toml does. I would like to set it globally for all projects.

To Reproduce

$ echo -e '[mypy]\npython_executable = "${VIRTUAL_ENV}/bin/python"' > ${XDG_CONFIG_HOME}/mypy/config
$ python3 -m pipx install mypy
$ cd <some-python-project>
$ python3 -m venv .venv
$ source .venv/bin/activate
$ mypy <foo.py>

Expected Behavior

I would have expected python_executable set in a global config file such as $XDG_CONFIG_HOME/mypy/config to work.

Actual Behavior

mypy: Invalid python executable '"/home/doolio/projects/demo-project/.venv/bin/python"': No such file or directory

Your Environment

  • Mypy version used: v1.10.0
  • Mypy command-line flags: None
  • Mypy configuration options from mypy.ini (and other config files): $XDG_CONFIG_HOME/mypy/config with contents:
[mypy]
python_executable = "${VIRTUAL_ENV}/bin/python"
  • Python version used:

Tested with both python 3.9.2 (system) and 3.12.0.

doolio avatar May 01 '24 21:05 doolio