What to record in pyvenv.cfg

I mentioned on bpo a while ago that it’d be very helpful if a venv can record its own information somewhere (pyvenv.cfg). Any Python interpreter already knows how to introspect a prefix with sysconfig.paths(); a venv only needs to provide its scheme and Python version (for lib/pythonX.Y).

It is definitely not unreasonable to search for bin/python and Scripts\python.exe, but that still feels very hackish and ad-hoc to me, with much ambiguity caused by different schemes. An established way to do this would be immensely helpful IMO.

I just spent half of my work week proving this wrong… it can introspect itself, but it’s going to struggle pretty hard for any other environment.

What other information do you want that isn’t already in pyvenv.cfg?

This seems to me to be getting off-topic. I have an interest in the question of getting sysconfig-like information, but I don’t see how it relates to naming of virtual envionments. I’d suggest splitting this off into a different topic - and for clarity, I think that if we do that, we should look at what the use cases are for introspecting environments to get sysconfig-like information. Personally, my interest is in the various paths, which I suspect is what @uranusjr wants too - whereas I think @steve.dower is interested in config vars as well. I’m also interested in language-agnostic solutions, which don’t require running the target Python interpreter to get the data. But more details on a dedicated topic :slightly_smiling_face:

There are definitely more needed for this to work, although I wouldn’t say it’d struggle hard. It needs scheme (either nt or posix_prefix AFAICT, but others are possible as long as they are supported), and variables to expand results from sysconfig.get_paths(expand=False):

  • base, platbase, installed_base, installed_platbase: These all point to the virtual environment root (the directory containing pyvenv.cfg), so we already have them convered.
  • py_version_short: Needed to expand lib locations.
  • abiflags: Needed to expand include locations.

So from what I can tell, supplying the Python version (the tool can format py_version_short on its oen easily enough) and ABI would be enough to get everything working.

I definitely agree. Both config var and naming are worthwhile topics I am interested in discussing; it would be a shame if either one is clogged by the other.