Honor --python for the Python shebang
waf configure
has a stock option --python
which controls which Python interpret to use (the "target interpreter"). If unset, the target interpreter is whatever interpreter waf configure
runs under.
waf configure
uses the target interpreter to determine:
- the default
PYTHONDIR
/--pythondir
andPYTHONARCHDIR
/--pythonarchdir
- whether argparse is present
- whether the gps module is present
- whether the ncurses module is present
- the cflags/libs/ldflags for compiling the
ntp
module (though this will be mooted by !1171 (merged))
The shebang substitutions only honor --pyshebang
but not --python
. If the user wants to use a non-default Python and sets --python
, they can (and usually will) end up with a broken install.
For example, on a Debian or RedHat system with python
being Python 2 and python3
being Python 3, if the user runs ./waf configure --python=python3
, they are expecting Python 3, but the shebangs will be the default of /usr/bin/env python
. This will result in the scripts running under Python 2. That is not what the user expected, nor will it work (because it will fail to find the modules).
If the user makes an explicit request with --python
, we should honor that. We can and should allow --pyshebang
to override that. This MR implements that behavior.
The Python shebang is detected with the following priority (first match wins):
- If the user explicitly specifies
--pyshebang
, use that. - If the user explicitly specifies
PYTHON
or--python
, use that. If it is not an absolute path, run under/usr/bin/env
. - Use
/usr/bin/env python
as before.
Examples:
These use /usr/bin/env python
:
./waf configure
./waf configure --python=python
PYTHON=python ./waf configure
These use /usr/bin/env python3
:
PYTHON=python3 ./waf configure
./waf configure --python=python3
PYTHON="/usr/bin/env python3" ./waf configure
These use /usr/bin/python3
:
PYTHON=/usr/bin/python3 ./waf configure
./waf configure --python=/usr/bin/python3
If we change the default to Python 3 (/usr/bin/env python3
), as in !1173, we have the same problem in reverse if the user wants to use Python 2. That is, the user would run ./waf configure --python=python
or ./waf configure --python=python2
. They are expecting Python 2, but the shebangs will be the default of /usr/bin/env python3
. This will result in the scripts running under Python 3. That is not what the user expected, nor will it work (because it will fail to find the modules.)