On 08/02/2017 04:29 PM, Nick Coghlan wrote:
On 2 August 2017 at 23:57, Nick Coghlan <ncogh...@gmail.com> wrote:
Another variant of that idea would be to have the default handler be
something like Geoffrey Thomas's pythonmux project
(https://github.com/geofft/pythonmux), and then patch
sys.excepthandler to report the Python version executed when
"sys.executable" isn't qualified as either Python 2 or Python 3 for
easier debugging of otherwise potentially cryptic error messages.

If we did do that, then I'd skip the "pyversions" comment idea, and
instead have the logic just be:

- if only /usr/bin/python2 is present, use it
- if only /usr/bin/python3 is present, use it
- if both are present, use /usr/bin/python2

While I'm happy I at least brought it up, I still can't convince
myself to actually *like* this idea relative to the "compile it and
report on the results" approach combined with the ability to opt-in to
replacing that default script with a symlink to the desired version.


Just compiling won't work -- consider `import pathlib` for example.

This is UX, but for sysadmins (and other command-line users). Rather than trying to do what they mean, we should aim to synchronize their expectations and the reality. I'd rather have /usr/bin/python failing hard with a good error message than trying non-obvious heuristics. Avoid the temptation to guess.


This is due to what happens in a situation like Fedora's with various
mux behaviours:

= Approach 1: impllcitly try Py3 =

All the same problems as a plain symlink. If we were to patch
sys.excepthandler() to report the version when sys.executable ==
'/usr/bin/python', then that UX tweak would apply just as well to the
symlink switching approach (maybe I should propose that as an
*upstream* change, and check for '/usr/local/bin/python' as well?).

= Approach 2: default to Py2, complain if it is missing =

Same effective consequence as defaulting to a custom script that
checks for Py3 syntax compatibility, just with a different more
implicit remedy ("Install Py2" vs "Install Py2 & make it the default
Python"). Also has the downside that you can't opt-in to making Py3
the default instead.

= Approach 3: add a magic script comment to opt-in to trying Py3 =

This whole problem just doesn't feel like a per-script setting to me -
it feels like a system administrator setting, where they say either
"Yes, I am confident in my ability to debug errors arising from myself
and others trying to run Python 2 scripts on Python 3", or "I want to
preserve compatibility with older Py2 only systems for now, even if
that means running parallel Python stacks on my newer systems".
_______________________________________________
Linux-sig mailing list
Linux-sig@python.org
https://mail.python.org/mailman/listinfo/linux-sig

Reply via email to