Fedora ponders the Python 2 end game
Fedora ponders the Python 2 end game
Posted Aug 1, 2017 23:39 UTC (Tue) by flussence (guest, #85566)In reply to: Fedora ponders the Python 2 end game by liw
Parent article: Fedora ponders the Python 2 end game
The package manager is /usr/bin/emerge. That's a wrapper script (written in python, invoked by a C binary that chases symlinks to figure out which version of python to call it with) that chases symlinks to figure out where the real program is (which is also a python script, but can be installed for one or more of python2/3.x/pypy simultaneously).
Now and again there's support requests from users who mess up their system by manually installing python packages as root outside the OS's control, and have ended up with something in the dependency chain installing a /usr/local/bin/emerge (also a python script) that does something completely different, but is higher priority in $PATH, and gives vague errors that don't make it immediately obvious that the wrong thing's being run.
Posted Aug 2, 2017 3:38 UTC (Wed)
by wahern (subscriber, #37304)
[Link] (1 responses)
POSIX created the getconf(1) utility just so you could do PATH="$(getconf PATH)" to get the default system provided PATH guaranteed to provide the POSIX utilities. It's one of the rare instances where they didn't just codify existing practice. Perhaps for that reason it's an underused and virtually unknown command. Theoretically Linux distributions could extend it so that something like getconf PYTHON2 prints the default python2 interpreter (if available). That doesn't by itself solve the problem of a simple shebang line, but I think it's the least distributions could do to meet developers half-way.[1]
For Lua scripts I often abuse a coincidence of shell and Lua syntax so I can do
where _=[[ begins a multiline string in Lua but is a harmless assignment in shell. Because the semantics of shell syntax effectively require parsing the file line-by-line, the shell code never reaches the terminating ]] or subsequent Lua code as long as you invoke exec or exit before reaching ]]. I'm not familiar with Python syntax but perhaps something similar can be done.
[1] Distributions could standardize on the "python2" command name, but you still run into the problem of a bad PATH variable. Ideally you'd be able to do something like #!/usr/bin/env command -p python2, where the -p switch to the command utility only searches the default PATH from getconf PATH. And where env(1) locates command(1), as command(1) is usually a built-in and even when it's available as an independent utility I don't know if you can expect it to be in /bin or /usr/bin--not in the same way that env(1) is reliably at the absolute path /usr/bin/env. But Linux is one of the few Unix systems that concatenate all the shebang command argument words before invoking the interpreter, so the above will work on macOS and some other kernels, but not on Linux.
Posted Aug 2, 2017 8:26 UTC (Wed)
by itvirta (guest, #49997)
[Link]
> Ideally you'd be able to do something like
Except that you can't do that in Linux, the kernel only passes one argument from the hashbang line.
I.e. the line above would run "
Fedora ponders the Python 2 end game
#!/bin/sh
_=[[
# shell script code to locate a Lua interpreter
]]
-- Lua code
Fedora ponders the Python 2 end game
#!/usr/bin/env command -p python2
/usr/bin/env" with "command -p python2" as one argument
(plus the name of the script as the second argument).
Or well, you could, if this "env" would split the argument to pieces itself.
