How to build Python virtualenv with packages provided by 'python3.withPackages'?

Thank you, what a wonderful summary, It would be best to remove the need to do the sed at all.

I’ve reviewed Revert "Unwrap python scripts when building an environment" by SuperSandro2000 · Pull Request #302385 · NixOS/nixpkgs · GitHub and I’m going go try to identify and fix the actually impacted packages.

2 Likes

Thank you very much for this great summary. I very much suggest to copy this information to GitHub PR as well.

1 Like

Hi folks,

Sorry for the long absence. I’ve been distracted and unfortunately neglected some things.

I’d like to try again with this change, but it’s obviously trickier than I originally thought. There are packages that depend on the current behaviour. :-/

The idea @ruro mentions above is fairly simple: instead of prefixing scripts with code to manipulate sys.path, we just rewrite the shebang to point to a symlink to the interpreter. Essentially, each package comes with a mini env for running its scripts. When packages depend on other packages, the envs get composed as usual. It’s simple, but invasive, so it’d take careful work to integrate it without a lot of breakage.

Then after that, the withPackages fix should be easier.

3 Likes

I’d like this to be fixed, since devenv-nixpkgs is stuck due to this being reverted.

Shall we work together @cwp @chrism to get a set of tests and experiment on fixing it?

1 Like

Yeah, I’m down.

What sort of test do you have in mind? Ideally we’d have a test that runs all the scripts that are included with a python package, but I don’t know how “runs correctly” would be defined for such a large and diverse set of scripts.

-cwp

@cwp I cherry-picked your commits on top of master as of 35a90c3f3dea9ae07f3cc70691f04fb4c9beb98c in GitHub - mcdonc/nixpkgs at python-env-venv and me and @domenkozar I think are going to try to figure out how to get reports from hydra runs before and after, to see what the actual breakage is, and then maybe we’ll have a better idea about what needs to be done. I think this is a reasonable step, anyway :slight_smile:

1 Like

Fix Python venv creation by mcdonc · Pull Request #326094 · NixOS/nixpkgs · GitHub and https://hydra.nixos.org/jobset/nixpkgs/python-env-venv