Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python packages installed via config.packages leak into Python VIRTUAL_ENV #1717

Open
vlaci opened this issue Feb 11, 2025 · 0 comments
Open
Labels
bug Something isn't working

Comments

@vlaci
Copy link
Contributor

vlaci commented Feb 11, 2025

Describe the bug

I don't know the reason why we add devenv.profile to PYTHONPATH, but we do:

export PYTHONPATH="$DEVENV_PROFILE/${package.sitePackages}''${PYTHONPATH:+:$PYTHONPATH}"

I don't know if it is a bug, edge-case or by-design.

I came to this rabbit hole as one environment we are using devenv for specifies a dependency in config.packages and also in pyproject.toml and I was surprised that the former overrides the latter.

Is there a reason for setting PYTHONPATH? It may make sense in cases where venv.enable = false, so it can be used as an ad-hoc environment, but I think it should not be set in the venv.enable = true case. Maybe a .pth file could be injected to the virtual env, pointing to the profile, so it would behave as a fallback for packages not already present in the virtual environment.

To reproduce

$ <<EOF > devenv.nix 
{ pkgs, ... }:

{
  languages.python = {
    enable = true;
    venv.enable = true;
    venv.requirements = ''
      jefferson
    '';
  };
  packages = [ pkgs.jefferson ];
}
EOF
$ devenv shell
(devenv) $ python
Python 3.12.7 (main, Oct  1 2024, 02:05:46) [GCC 13.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import jefferson
>>> jefferson
<module 'jefferson' from '/nix/store/y0y42rimg0l6rpygxq4ww3hy9d01jbx2-devenv-profile/lib/python3.12/site-packages/jefferson/__init__.py'>

Version

devenv 1.3.1 (x86_64-linux)


P.S.

PYTHONPATH is also adjusted by the individual package's setup-hooks, so it may not be a devenv-only issue. It may be a good idea if devenv would be able to clear PYTHONPATH altogether when venv.enable is set 🤔. This could wreak havoc if languages.python.package is different from the default pkgs.python package, as those could contain extensions compiled for a different version.

@vlaci vlaci added the bug Something isn't working label Feb 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant