[Python-ideas] Draft PEP for virtualenv in the stdlib

Carl Meyer carl at oddbird.net
Wed Oct 26 04:14:11 CEST 2011


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 10/25/2011 08:05 PM, Nick Coghlan wrote:
> On Wed, Oct 26, 2011 at 11:51 AM, Barry Warsaw <barry at python.org> wrote:
>> On Oct 26, 2011, at 01:15 AM, Vinay Sajip wrote:
>>> Nick Coghlan <ncoghlan at ...> writes:
>>>> I'd actually prefer that we use the explicit "sys.prefix" and
>>>> "sys.venv_prefix" naming (with the latter set to None when not in a
>>>> virtual env) and possibly offer a convenience API somewhere that hides
>>>> the "sys.prefix if sys.venv_prefix is None else sys.venv_prefix"
>>>> dance.
>>>
>>> But why is that better than a site.venv_prefix which points to a venv if
>>> you're in one, and == sys.prefix if you're not?
>>
>> I'm not sure why either <wink>, but I prefer the original suggestion, as Vinay
>> restates it here.
> 
> Yeah, having venv_prefix == prefix in the "not in a virtual env case"
> is fine by me as well. I think Carl's right that it reads a little
> oddly sometimes, but it's a better option than:
> - further overloading "site" (when more than site-package may be
> located using the venv prefix)
> - requiring people to fall back to sys.prefix explicitly

What about "sys.local_prefix"? Doesn't overload site, but also doesn't
imply that it always points to a venv. I think "local" carries the right
connotation here - this is the prefix for the user's local environment
(as possibly opposed to the "global" system environment). Seems like
this might make code using the attribute unconditionally read a bit less
oddly?

> The "am I in a virtual env?" check can then just be "if sys.prefix ==
> sys.venv_prefix".

Right; though in general the goal is that by simply switching to use the
new prefix in the right places in sysconfig, such an explicit "am in a
venv" check should never be necessary, even in the stdlib. I think the
reference implementation largely achieves this goal, I'd have to check
again to see if that's entirely true.

Carl
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAk6nbPMACgkQ8W4rlRKtE2dbrQCg3iwUkXZUBHerzyBFq+jOWS91
pgkAn2hYy7pREwdFBQQayR2OLP9x62e9
=tx9A
-----END PGP SIGNATURE-----



More information about the Python-ideas mailing list