[Python-ideas] Make py.exe default to Python 3

eryk sun eryksun at gmail.com
Wed Mar 9 07:49:19 EST 2016


On Wed, Mar 9, 2016 at 3:47 AM, Paul Moore <p.f.moore at gmail.com> wrote:
> I don't disagree with limiting the change to not affect unversioned
> shebang lines, but I'm not sure how much effort I'd personally be
> willing to put into special-casing that. We can see on that one when I
> start to look at the actual code, I guess...

I agree with Nick that Python 2 compatibility should be maintained for
virtual paths in shebangs. I think a straight-forward solution is for
locate_python() to gain a "virtual_mode" BOOL parameter, which is TRUE
only when processing a virtual shebang, i.e. when called from
maybe_handle_shebang(). For example, when wanted_ver is empty,
locate_python would search the following sequence:

        configured_value = get_configured_value(config_key);
        if (configured_value)
            result = find_python_by_version(configured_value);
        if (result == NULL)
            result = find_python_by_version(virtual_mode ? L"2" : L"3");
        if (result == NULL)
            result = find_python_by_version(virtual_mode ? L"3" : L"2");

This change works for me with various combinations of enabled
PythonCore registry keys, PY_PYTHON values, and shebang lines. Note
that the behavior of the plain "#!python" virtual shebang gets lumped
in with virtual Unix paths, but I don't know why anyone would add this
shebang without a target version.


More information about the Python-ideas mailing list