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

Using pre-commit.hooks with a python project causes PYTHONPATH to have default site-packages #1644

Open
wkral-netlync opened this issue Dec 19, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@wkral-netlync
Copy link

Describe the bug
When one or more of the pre-commit.hooks are enabled while languages.python.enable = true; and languages.python.version is set to something different than the default version of python in nixpkgs the resulting shell will have a $PYTHONPATH with site-packages from the specific version created in the venv, and site-packages from the default version of python plus additional packages from other python libraries used by pre-commit.hooks.

The resulting shell can have multiple libraries conflicting with each other for me this manifests as cffi library:
Exception: Version mismatch: this is the 'cffi' package version 1.17.1, located in '/nix/store/bw9h2axgbrd7fs9zbz00dx5a9404xqqn-python3.12-cffi-1.17.1/lib/python3.12/site-packages/cffi/api.py'. When we import the top-level '_cffi_backend' extension module, we get version 1.15.1, located in '<redactect>/.venv/lib/python3.11/site-packages/_cffi_backend.cpython-311-x86_64-linux-gnu.so'. The two versions should be equal; check your installation.

To reproduce
Please provide an Short, Self Contained, Correct (Compilable), Example by creating a gist using devenv.nix, devenv.yaml, and optionally devenv.lock.

Make sure to include full logs and what you expected to happen.

devenv.nix

{ ... }:
{
  languages.python = {
    enable = true;
    version = "3.11.9";  # Default version: 3.12.7
  };
  pre-commit.hooks.isort.enable = true;
}

devenv.yaml

inputs:
  nixpkgs:
    url: github:cachix/devenv-nixpkgs/rolling
  nixpkgs-python:
    url: github:cachix/nixpkgs-python
    inputs:
      nixpkgs:
        follows: nixpkgs
$ echo $PYTHONPATH
/nix/store/pn115q790hg1z6a0g3q84zy084ls2w07-devenv-profile/lib/python3.11/site-packages:/nix/store/3nxyxd2p2d5kvmznsdgi0j2z6as3hbdw-pre-commit-4.0.1/lib/python3.12/site-packages:/nix/store/d7wly0zny9cwmqyx70jysyihd3zvw9ml-python3.12-cfgv-3.4.0/lib/python3.12/site-packages:/nix/store/zv1kaq7f1q20x62kbjv6pfjygw5jmwl6-python3-3.12.7/lib/python3.12/site-packages:/nix/store/zsj4l3sqq35fysmhhysj1xmi01bs1wqa-python3.12-identify-2.6.2/lib/python3.12/site-packages:/nix/store/bxaxs52882h8l5impq97sfndw3zaqqxm-python3.12-editdistance-s-1.0.0/lib/python3.12/site-packages:/nix/store/bw9h2axgbrd7fs9zbz00dx5a9404xqqn-python3.12-cffi-1.17.1/lib/python3.12/site-packages:/nix/store/4drm9zi486w2jcpsml70zkmsd8136ipm-python3.12-pycparser-2.22/lib/python3.12/site-packages:/nix/store/ziygfgrrfki93xcr567isy6j2431qp7i-python3.12-pytest-8.3.3/lib/python3.12/site-packages:/nix/store/px86rl62fxcvbm7hpciyizq0yq3bzhac-python3.12-iniconfig-2.0.0/lib/python3.12/site-packages:/nix/store/qnfndbdg0k5s7zb47l5q9h7cszi56gpf-python3.12-packaging-24.1/lib/python3.12/site-packages:/nix/store/cdg583c1xq8njwxjky1zj3qmix3hpl08-python3.12-pluggy-1.5.0/lib/python3.12/site-packages:/nix/store/gmkkyg2l4iq23vdbara7krnr2j08fy8m-python3.12-ukkonen-1.0.1/lib/python3.12/site-packages:/nix/store/nipgxfzw0wdk03h88dcbnwnw8wwkh8f7-python3.12-nodeenv-1.9.1/lib/python3.12/site-packages:/nix/store/j7q50pmxnawpif7kfimy51mjhjdjldns-python3.12-pyyaml-6.0.2/lib/python3.12/site-packages:/nix/store/d1r4w7mhq6v7vvr0r8cf3wi4jhmyrdik-python3.12-toml-0.10.2/lib/python3.12/site-packages:/nix/store/8xbcm89jwys1dzarwpbm37n0nwrsq1i7-python3.12-virtualenv-20.26.6/lib/python3.12/site-packages:/nix/store/d1q63libwiaylpjgs6cdi851myz42n6y-python3.12-distlib-0.3.8/lib/python3.12/site-packages:/nix/store/imyrdiwdg86f20sf4k5p7qp6cqch854i-python3.12-filelock-3.16.1/lib/python3.12/site-packages:/nix/store/1hci0iw7l2b54xgal7hk02a6va1b9sbm-python3.12-platformdirs-4.3.6/lib/python3.12/site-packages:/nix/store/fyfidwrpq0d5sz92x3vzly1249bkhsys-python3.12-isort-5.13.2/lib/python3.12/site-packages

Note that it doesn't have to be a python based hook, any will cause the issue from my testing.

devenv.nix

{ ... }:
{
  languages.python = {
    enable = true;
    version = "3.11.9";  # Default version: 3.12.7
  };
  #pre-commit.hooks.isort.enable = true;
}
$ echo $PYTHONPATH
/nix/store/k0499g0yp243rylwa12vrc8ysdjxbhlc-devenv-profile/lib/python3.11/site-packages

I expect with the pre-commit hook enabled that $PYTHONPATH would be the same as without it enabled and whatever dependencies are needed to run the hook would be isolated from the devshell.

Version

Paste the output of $ devenv version here or tell us if you're using flakes.

$ devenv version
devenv 1.3.1 (x86_64-linux)
@wkral-netlync wkral-netlync added the bug Something isn't working label Dec 19, 2024
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