On Sat, Sep 3, 2016 at 2:32 PM, Nick Coghlan <ncoghlan@gmail.com> wrote:

* Tier 0: "the default Python" is determined at the distribution
level. For the majority of current distributions, that means Python 2,
but on a select few it means Python 3.

* Tier 1: "the default Python" is configurable on a per-system level.
Distros pursuing this option (e.g. by moving /usr/bin/python under
'alternatives') are still advised to keep the out-of-the-box default
as Python 2. This will be sufficient for at least some environments to
start managed migrations from Python-2-as-default to
Python-3-as-default, and further establishes the precedent that
"/usr/bin/python will always be Python 2" is an incorrect assumption.

* Tier 2: "the default Python" is configurable on a per-user level.
Sufficiently determined sysadmins can actually configure this today,
so it would mainly be a matter of looking at what's involved in doing
that, and making it simpler for people to set up.

* Tier 3 (highly experimental): "the default Python" is configurable
on a per-script level, using something like pythonmux.

 I think that is a great approach!

For Teir 2:

Today, a user can alias python for direct execution. For scripts that use /use/bin/env, they can manipulate their $PATH (and create symlinks). Some of that could be automated.

For Teir 3:

Ideally this would be something that evaluated a list of preferred interpreters given on the shebang, but defaulted to the user/system default. It should also work across multiple python interpreters like pypy or jython and not just versions of Cpython.

This could be a non-Python-specific solution. What if there was a utility, like env, that searched python in $PATH, but could take multiple commands? Then you might have a shebang like:

    #! /usr/bin/envmux pypy3 pypy python3.5 python3 python2.7 python

It would probably also need a way to pass options to specific interpreters, so maybe syntax like this?

    #! /usr/bin/envmux python3 "[-b]" python2 python

It could even handle user and system defaults by allowing a keypair file in the user's home directory and in etc. Something like:

    ~/.envmux
    ---------------
    python : /usr/bin/python3.5

    /etc/envmux
    ------------------
    python : /usr/bin/python2.7

In this example the system default would be Python2.7, but the user default would be Python 3.5. To handle the python command, python could be aliased to "/usr/bin/envmux python".

I think a solution like this is more flexible than pythonmux and would also be valuable to non-Python implementations.

The downside is you can't directly say a script required Python 2.6+ or 3.3+, you would have to list out all the versions, but the solutions today don't handle that either, and that is probably better handled within the script to give more information to the user.

Avram