Skip to content

PEP 796: relative virtual environments, initial draft #4476

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

Open
wants to merge 29 commits into
base: main
Choose a base branch
from

Conversation

rickeylev
Copy link

@rickeylev rickeylev commented Jun 30, 2025

Basic requirements (all PEP Types)

  • Read and followed PEP 1 & PEP 12
  • File created from the latest PEP template
  • PEP has next available number, & set in filename (pep-NNNN.rst), PR title (PEP 123: <Title of PEP>) and PEP header
  • Title clearly, accurately and concisely describes the content in 79 characters or less
  • Core dev/PEP editor listed as Author or Sponsor, and formally confirmed their approval
  • Author, Status (Draft), Type and Created headers filled out correctly
  • PEP-Delegate, Topic, Requires and Replaces headers completed if appropriate
  • Required sections included
    • Abstract (first section)
    • Copyright (last section; exact wording from template required)
  • Code is well-formatted (PEP 7/PEP 8) and is in code blocks, with the right lexer names if non-Python
  • PEP builds with no warnings, pre-commit checks pass and content displays as intended in the rendered HTML
  • Authors/sponsor added to .github/CODEOWNERS for the PEP

Standards Track requirements

  • PEP topic discussed in a suitable venue with general agreement that a PEP is appropriate
  • Suggested sections included (unless not applicable)
    • Motivation
    • Rationale
    • Specification
    • Backwards Compatibility
    • (n/a) Security Implications
    • How to Teach This
    • Reference Implementation
    • Rejected Ideas
    • Open Issues
  • Python-Version set to valid (pre-beta) future Python version, if relevant
  • Any project stated in the PEP as supporting/endorsing/benefiting from the PEP formally confirmed such
  • Right before or after initial merging, PEP discussion thread created and linked to in Discussions-To and Post-History

Work towards python/cpython#136051


📚 Documentation preview 📚: https://pep-previews--4476.org.readthedocs.build/

@hugovk
Copy link
Member

hugovk commented Jun 30, 2025

Hello, before we go any further with this PR, has the idea been discussed on Discourse?

And after that we'll need a sponsor before assigning the PEP number, do you have one yet? Let's unassign 796 for now.

Please see:

@hugovk hugovk changed the title PEP 796: relative virtual environments, initial draft PEP xxx: relative virtual environments, initial draft Jun 30, 2025
@rickeylev
Copy link
Author

Thanks @hugovk and @StanFromIreland for the early review. I used a draft PR to see the CI results to further clean it up -- my apologies for wasting some of your time, but thank you regardless.

discussed on Discourse?

Yes: https://discuss.python.org/t/making-venvs-relocatable-friendly/96177

The criteria of "discussed enough with enough support" is vague, but what gave me enough confidence to begin a PEP and start a (draft) PR at this point was:

Sponsor needed to assign number

Thanks for clarifying that part! Yes, finding a sponsor is my next big step.

@hugovk
Copy link
Member

hugovk commented Jun 30, 2025

I used a draft PR to see the CI results to further clean it up

Tip: you can enable GitHub Actions at https://github.com/rickeylev/peps/actions and run the CI on your fork.

Yes, finding a sponsor is my next big step.

Good luck!

@rickeylev
Copy link
Author

Brief update:

I have a sponsor: @ncoghlan has offered to sponsor this PEP. I've updated the PEP text accordingly.

So, IIUC, next steps are:

  • Sponsor formally confirms they're a sponsor
  • Sponsor approves this PR

I'm not entirely sure on process, so I'll just leave this PR in draft state until those are done / imminent.

@ncoghlan
Copy link
Contributor

ncoghlan commented Jul 2, 2025

Confirming my sponsorship (the parts of the proposal I felt were at best premature, and potentially entirely infeasible, have been removed).

Completing a pre-publication review now.

Copy link
Contributor

@ncoghlan ncoghlan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generally looks good to me. Thanks for writing this up!

Assorted more detailed comments inline.

@hugovk hugovk changed the title PEP xxx: relative virtual environments, initial draft PEP 796: relative virtual environments, initial draft Jul 2, 2025
@rickeylev rickeylev marked this pull request as ready for review July 2, 2025 17:54
@rickeylev rickeylev requested a review from a team as a code owner July 2, 2025 17:54
@hugovk
Copy link
Member

hugovk commented Jul 2, 2025

Thanks @ncoghlan for sponsoring and approving! Let's continue with PEP number 796.

Next steps: a PEP editor to review, then merge, and then the PEP discussion can be opened for this proposal.


Second, such relative paths are a building block to enable portable virtual
environments, i.e. copying a virtual environment as-is between hosts of
compatible platforms. Portable venvs are appealing because virtual environments
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wouldn't abbreviate here if you aren't elsewhere

Suggested change
compatible platforms. Portable venvs are appealing because virtual environments
compatible platforms. Portable virtual environments are appealing because virtual environments

benefits:

* The closer the development environment is to the non-development environment,
the more reliable software can be achieved, and the easier it is to reproduce
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you may want to rephrase "the more reliable software can be achieved", I find the meaning a bit confusing and it's used both here and in the next bullet?

still retain predictable and reliable behavior. Thus, the absolute path
requirement should be relaxed and relative path behavior allowed and defined.

Second, such relative paths are a building block to enable portable virtual
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It'd be nice to hear more about why and how a relative path makes the virtual environment more portable. A Python installation will still need to exist in a specific location on the new host, right? Is the pitch for a relative path that you'd copy a virtual environment and the Python installation together?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, that's the use case, although even the "copying" may be virtual - while an app embedding a single Python runtime and basing multiple virtual environments on it getting installed to different locations is one possibility, other potential scenarios would be a mounted parent folder in a container, or a mounted network drive on a host.

The key is that the position of the venv and its base runtime relative to each other is consistent, but the path prefix leading to their common parent folder may vary across systems.

Comment on lines +11 to +12
.. highlight:: rst

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's remove this, it's the syntax highlighter used for code blocks (default Python) and there aren't any code blocks here.

Suggested change
.. highlight:: rst

When the virtual environment doesn't require modifications to be usable, it
also allows more advanced deployment mechanisms, e.g. remote mounting and
caching of artifacts. While this PEP on its own isn't sufficient to enable
that, it allows tools like ``bazel`` or ``venvstacks`` to more easily prepare
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
that, it allows tools like ``bazel`` or ``venvstacks`` to more easily prepare
that, it allows tools like Bazel or venvstacks to more easily prepare

Comment on lines +78 to +81
(``bazel``, omitting the ``home`` key entirely to trigger an implementation
dependent fallback to resolving via a symlinked interpreter binary on
non-Windows systems) or by requiring a post-installation script to be executed
after the environment is placed in its target location (``venvstacks``).
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
(``bazel``, omitting the ``home`` key entirely to trigger an implementation
dependent fallback to resolving via a symlinked interpreter binary on
non-Windows systems) or by requiring a post-installation script to be executed
after the environment is placed in its target location (``venvstacks``).
(Bazel, omitting the ``home`` key entirely to trigger an implementation
dependent fallback to resolving via a symlinked interpreter binary on
non-Windows systems) or by requiring a post-installation script to be executed
after the environment is placed in its target location (venvstacks).

Comment on lines +90 to +93
* ``subdir/whatever/bin`` (a directory within the virtual environment).
* ``./subdir/whatever/bin`` (same as above)
* ``../../../../../elsewhere/runtime/bin`` (a directory outside the virtual
environment).
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* ``subdir/whatever/bin`` (a directory within the virtual environment).
* ``./subdir/whatever/bin`` (same as above)
* ``../../../../../elsewhere/runtime/bin`` (a directory outside the virtual
environment).
* ``subdir/whatever/bin`` (a directory within the virtual environment)
* ``./subdir/whatever/bin`` (same as above)
* ``../../../../../elsewhere/runtime/bin`` (a directory outside the virtual
environment)

Comment on lines +143 to +144
Tools that work around the absolute ``home`` key limitation the way ``bazel``
and ``venvstacks`` currently do (omitting the ``home`` key, or editing it after
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Tools that work around the absolute ``home`` key limitation the way ``bazel``
and ``venvstacks`` currently do (omitting the ``home`` key, or editing it after
Tools that work around the absolute ``home`` key limitation the way Bazel
and venvstacks currently do (omitting the ``home`` key, or editing it after

paths.

A proof-of-concept of this is implemented in
`rickeylev/feat.relative.pyvenv.home <https://github.com/python/cpython/compare/main...rickeylev:cpython:feat.relative.pyvenv.home>`__
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
`rickeylev/feat.relative.pyvenv.home <https://github.com/python/cpython/compare/main...rickeylev:cpython:feat.relative.pyvenv.home>`__
`rickeylev/feat.relative.pyvenv.home <https://github.com/python/cpython/compare/main...rickeylev:cpython:feat.relative.pyvenv.home>`__.

host-relocatable virtual environments.
* `rules_py <https://github.com/aspect-build/rules_py>`__: implements
host-relocatable virtual environments.
* `python-build-standalone <https://github.com/astral-sh/python-build-standalone>`__:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Put something after the colon? Or delete the colon?

Suggested change
* `python-build-standalone <https://github.com/astral-sh/python-build-standalone>`__:
* `python-build-standalone <https://github.com/astral-sh/python-build-standalone>`__

A relocatable Python runtime.
* `PoC for relative home in Python startup <https://github.com/python/cpython/compare/main...rickeylev:cpython:feat.relative.pyvenv.home>`__
* `Python Ideas "Making venvs relocatable friendly" discussion <https://discuss.python.org/t/making-venvs-relocatable-friendly/96177>`__
* `GH-136051: relative pyvenv.cfg home <https://github.com/python/cpython/issues/136051>`__
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Convention is lowercase for issue, uppercase for PR:

Suggested change
* `GH-136051: relative pyvenv.cfg home <https://github.com/python/cpython/issues/136051>`__
* `gh-136051: relative pyvenv.cfg home <https://github.com/python/cpython/issues/136051>`__

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants