Skip to content
Open
Changes from 1 commit
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
ceeaa3b
initial file
rickeylev Jun 27, 2025
d0a9289
add some core content
rickeylev Jun 28, 2025
41d2ea8
rename to motivation
rickeylev Jun 28, 2025
65a415c
note it enables more advanced optimizations
rickeylev Jun 28, 2025
4175b20
add foot notes, relocatable term section, links
rickeylev Jun 29, 2025
bbc85b7
update discussion, sponsor headers to pending
rickeylev Jun 29, 2025
a0c2529
rst fixups
rickeylev Jun 29, 2025
8e6e21e
fixup italics
rickeylev Jun 29, 2025
37202ca
rename to relative-venv
rickeylev Jun 29, 2025
b81c50f
clarify advanced deployment options, reflow some text
rickeylev Jun 30, 2025
55a5e28
add specification, rationale section; doc why env vars arent an option
rickeylev Jun 30, 2025
e09b00d
also mention curdir syntax handling
rickeylev Jun 30, 2025
c7a6a9b
update some todo text
rickeylev Jun 30, 2025
bc1ffbd
update codeowners
rickeylev Jun 30, 2025
2301d2a
add initial discussion footnote link
rickeylev Jun 30, 2025
e14b01f
add fr footnote
rickeylev Jun 30, 2025
175f378
revert codeowners change
rickeylev Jun 30, 2025
31cb756
remove packaging-related specs
rickeylev Jul 2, 2025
cd46f4d
fix lint errors with headers
rickeylev Jul 2, 2025
b532f5c
set sponsor
rickeylev Jul 2, 2025
99434fc
set sponsor as codeowner
rickeylev Jul 2, 2025
862142a
clarify title to focus on core pyvenv.cfg home behavior
rickeylev Jul 2, 2025
1c8fb2d
fix typo; remove host-relocatable mention; remove non-germane copying…
rickeylev Jul 2, 2025
c542890
fix typos, grammar
rickeylev Jul 2, 2025
3240227
Apply suggestions from code review
rickeylev Jul 2, 2025
557cb71
fix up markdown and text width
rickeylev Jul 2, 2025
0579623
fix title underlines
rickeylev Jul 2, 2025
c9388b3
link to relative venv reference implementation
rickeylev Jul 2, 2025
b959f24
Apply suggestions from code review
rickeylev Jul 6, 2025
5b259cc
Apply suggestions from code review
rickeylev Aug 17, 2025
560dadb
Merge branch 'main' of https://github.com/python/peps into relative.v…
rickeylev Aug 17, 2025
f41ed51
Merge branch 'relative.venvs' of https://github.com/rickeylev/peps in…
rickeylev Aug 17, 2025
5cbc9f5
better answer why/how relvenvs help; wrap some long lines
rickeylev Aug 17, 2025
0af0eea
Apply AA-Turner suggestions
rickeylev Aug 21, 2025
68dd5e0
add refs, remove CWD acronym, fix grammar
rickeylev Aug 21, 2025
b50a80c
address review comments: better split and organize rationale/motivation
rickeylev Aug 24, 2025
af8f880
Merge branch 'main' into relative.venvs
AA-Turner Sep 29, 2025
ae5a67f
Apply markup and simple grammar fixes from code review
ncoghlan Oct 7, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Apply AA-Turner suggestions
Co-authored-by: Alyssa Coghlan <[email protected]>
Co-authored-by: Adam Turner <[email protected]>
Co-authored-by: Stan Ulbrych <[email protected]>
  • Loading branch information
4 people authored Aug 21, 2025
commit 0af0eea240eee6b190c8b24aeec90849d262fdeb
38 changes: 21 additions & 17 deletions peps/pep-0796.rst
Original file line number Diff line number Diff line change
@@ -1,22 +1,25 @@
PEP: 796
Title: Relative Virtual Environment Home
Title: Relative Home Path in Virtual Environments
Author: Richard Levasseur <[email protected]>
Sponsor: Alyssa Coghlan <[email protected]>
Discussions-To: Pending
Status: Draft
Type: Standards Track
Created: 26-Jun-2025
Created: 02-Jul-2025
Python-Version: 3.15


Abstract
========

This PEP describes how a relative path for ``home`` in a Python virtual
environment's ``pyvenv.cfg`` is understood by the Python startup process.
Specifically, how it is canonicalized into an absolute path later used
by the runtime. This small detail is a fundamental building block for
virtual environments to be more portable.
This PEP formally specifies the use of a relative path for ``home``
in a Python virtual environment's :file:`pyvenv.cfg` file.

Specifically, we will discuss how such relative paths are understood
by the Python startup process, including their conversion to absolute
paths for use by the runtime.
This is a fundamental building block for virtual environments to
become more portable.

Motivation
==========
Expand Down Expand Up @@ -87,17 +90,19 @@ Specification
=============

The ``home`` value in ``pyvenv.cfg`` is permitted to use a relative path value.
These may contain up-references outside of the virtual environment root
directory. Examples:
These may contain parent-directory references outside of the virtual environment root
directory.
For example:

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

Relative paths are relative to the directory containing ``pyvenv.cfg``. During
interpreter startup (i.e. ``getpath.py``), the relative path is joined to the
directory to form an absolute path. Up-references (``../``) and current
Relative paths are relative to the directory containing :file:`pyvenv.cfg`.
During interpreter startup (i.e. :file:`getpath.py`), the relative path is joined to the
directory containing ``pyvenv.cfg`` to form an absolute path.
Parent-directory references (``../``) and current
directory references (``./``) are resolved syntactically (i.e. not resolving
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
directory references (``./``) are resolved syntactically (i.e. not resolving
directory references (``./``) are resolved lexically (i.e. not resolving

(I don't mind if this isn't accepted, I've just always referred to this style of resolution as lexical rather than as syntactic: python/cpython#124825

symlinks). Symlinks are *not* resolved prior to construction of the absolute
path to ensure semantics between a relative path and absolute path remain the
Expand All @@ -110,7 +115,7 @@ i.e. it's equivalent to using that value verbatim in ``pyvenv.cfg``.


CPython Runtime Changes
=======================
-----------------------

The CPython runtime itself *almost* already supports relative paths. The
primitives are there, so the only change needed is to define how it resolves
Expand All @@ -133,16 +138,15 @@ This change is only a couple of lines in the startup code. Specifically, when
parsing the ``pyvenv.cfg`` file and finding the ``home`` value, it just needs
to be checked if it's already absolute. If not, then join it to the directory
name of the ``pyvenv.cfg`` file. The code already knows the directory and has
helpers already present for checking if a path is absolute and joining two
helpers already exist for checking if a path is absolute and joining two
paths.

A proof-of-concept of this is implemented in
A proof-of-concept of this is implemented in the author's branch,
`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>`__.

Please could you also wrap some of the other long lines to 79 chars?

https://peps.python.org/pep-0012/#general


Backwards Compatibility
=======================


Tools that work around the absolute ``home`` key limitation the way Bazel
and venvstacks currently do (omitting the ``home`` key, or editing it after
moving the environment) will be unaffected.
Expand Down Expand Up @@ -202,7 +206,7 @@ References
* `gh-136051: relative pyvenv.cfg home <https://github.com/python/cpython/issues/136051>`__

Rejected Ideas
=====================
==============

Relative to virtual env root
----------------------------
Expand Down
Loading