Open Cerebus opened 2 years ago
To clarify the use case: I put things like language servers in site packages because they're used with every project. Project dependencies go in the virtualenv; this isolates the developer's environment from the project environment.
Yes, the workaround is just install developer's dependencies into the venv, but that duplicates things and (depending on the dependency manager) can pollute the environment of collaborators with things they don't need. It's cleaner this way, and with proper pinning/locking, overlaps between site-packages and venv packages aren't a problem.
To further clarify: I see a distinction between developer dependencies and development dependencies. A developer dependency is something a developer uses to be productive and consistent across all projects, but where toolchain may vary from developer to developer. Language servers, linters, and code analysis tools are good examples of these.
In contrast, a development dependency is something required by a project but is not part of the release. Build and test frameworks are the typical examples.
So when I say "developer dependency" above, that's what I mean. I don't want to install a language server as a development dependency, because (a) it's not needed to build, test, or run the code; and (b) you might use a different one.
Virtualenvs with system-site-packages allows this to work, but pyenv is giving me fits. This actually is working on my personal Linux workstation, but poking around in there I see that there's something wonky on that install; pyenv which
is giving me the scripts in $HOME/.local
rather than the parent venv. I think this may have to do with how I migrated that environment to pyenv, whereas this macOS box was a cleanroom install. Once I figure out what's going on, it may suggest a workaround or a fix.
That works for imports, not for console scripts.
When a pyenv virtualenv is created with system-site-packages enabled, console scripts installed in the parent pyenv version are invoked using the parent's environment, not the current virtual environment, and cannot load packages installed in the virtualenv.
Reproduction:
Create a venv from a parent version that has packages with console scripts. Here, package
pyright
has a console script.We pip install a package into the venv.
When invoked, pyright parses code and imports, but can't find the package in the venv.
When the console script is invoked as a module entry point, the import is resolved because python is executed in the venv.
Prerequisite
There are a couple of close issues, but nothing really seemed to match.
Description
All.
N/A
https://gist.github.com/Cerebus/bf0a32edd99d6d8c00a29401628771f8