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

Fix venv creation in Python environments #297628

Merged
merged 2 commits into from
Mar 22, 2024
Merged

Commits on Mar 22, 2024

  1. Fix venv creation in Python environments

    The way we build python environments is subtly broken. A python
    environment should be semantically identical to a vanilla Python
    installation in, say, /usr/local. The current implementation, however,
    differs in two important ways. The first is that it's impossible to use
    python packages from the environment in python virtual environments. The
    second is that the nix-generated environment appears to be a venv, but
    it's not.
    
    This commit changes the way python environments are built:
    
      * When generating wrappers for python executables, we inherit argv[0]
        from the wrapper. This causes python to initialize its configuration
        in the environment with all the correct paths.
      * We remove the sitecustomize.py file from the base python package.
        This file was used tweak the python configuration after it was
        incorrectly initialized. That's no longer necessary.
    
    The end result is that python environments no longer appear to be venvs,
    and behave more like a vanilla python installation. In addition it's
    possible to create a venv using an environment and use packages from
    both the environment and the venv.
    cwp committed Mar 22, 2024
    1 Configuration menu
    Copy the full SHA
    234bb31 View commit details
    Browse the repository at this point in the history
  2. Unwrap python scripts when building an environment

    When building a python environment's bin directory, we now detect
    wrapped python scripts from installed packages, and generate unwrapped
    copies with the environment's python executable as the interpreter.
    cwp committed Mar 22, 2024
    Configuration menu
    Copy the full SHA
    9611885 View commit details
    Browse the repository at this point in the history