Expose `libpath` from `venv.EnvBuilder.ensure_directories`

Currently, venv does not expose the library path in any way.

Since this value is not exposed, the API users of venv (ahem… like pip) need to recompute this information, coupling strongly to the implementation details of the venv module. I noticed this as part of working on pip’s test suite and build isolation logic – which I’m trying to change to use venv directly, replacing the somewhat quirky solutions we have from back when Python 2 was non-EOL.

Exposing this information in the API would make it possible to eventually eliminate the logic duplication on pip’s end, since it would be able to reuse the logic as-is.

1 Like

I’ve eagerly filed an issue for this at:

Strong +1. As a general principle, I’d support exposing as much information as possible for a venv. A lot of information (but not the libpath) is available in the “context” object, but that’s not documented.

Adding libpath to the context and documenting the context would be a big improvement.

I’ve also noticed that PyPy has their own fork of venv, which handles the path for the site-packages differently:

Exposing this attribute would allow for this sort of inconsistency would also get covered as well.

A fix for this is now merged and will be in Python 3.12. When PyPy pick up the changes to venv they should automatically expose their variant consistently with cPython.

1 Like