[OE-core] [RFC 1/2] scripts: use python2 explicitly in shebangs

Martin Hundebøll martin at hundeboll.net
Wed Oct 29 13:18:47 UTC 2014


Hi Paul,

On 2014-10-29 14:05, Paul Barker wrote:
> On 29 October 2014 11:18, Martin Hundebøll <martin at hundeboll.net> wrote:
>> As distributions start moving to python3, scripts should explicity
>> request python2 in the shebang. This patch changes all occurences of
>>      #!/usr/bin/python and #!/usr/bin/env python
>> to
>>      #!/usr/bin/env python2
>>
>
> <snip lots>
>
>> diff --git a/scripts/oe-buildenv-internal b/scripts/oe-buildenv-internal
>> index bba6f8f..b514aa5 100755
>> --- a/scripts/oe-buildenv-internal
>> +++ b/scripts/oe-buildenv-internal
>> @@ -33,7 +33,7 @@ fi
>>   # sanity.bbclass because bitbake's source code doesn't even pass
>>   # parsing stage when used with python v3, so we catch it here so we
>>   # can offer a meaningful error message.
>> -py_v3_check=`/usr/bin/env python --version 2>&1 | grep "Python 3"`
>> +py_v3_check=`/usr/bin/env python2 --version 2>&1 | grep "Python 3"`
>>   if [ "$py_v3_check" != "" ]; then
>>          echo >&2 "Bitbake is not compatible with python v3"
>>          echo >&2 "Please set up python v2 as your default python interpreter"
>> @@ -43,7 +43,7 @@ fi
>>   # Similarly, we now have code that doesn't parse correctly with older
>>   # versions of Python, and rather than fixing that and being eternally
>>   # vigilant for any other new feature use, just check the version here.
>> -py_v26_check=`python -c 'import sys; print sys.version_info >= (2,7,3)'`
>> +py_v26_check=`python2 -c 'import sys; print sys.version_info >= (2,7,3)'`
>>   if [ "$py_v26_check" != "True" ]; then
>>          echo >&2 "BitBake requires Python 2.7.3 or later"
>>          return 1
>
> This is the section of shell script which checks the python version
> when you run 'oe-init-build-env'. If you want to change the way python
> is ran I'd start by looking at this code. If this script could
> automatically try 'python2' if 'python' is found to be Python 3, and
> ensure the correct interpreter is used in all commands that run after
> the environment is setup that would be fantastic. It'd probably be a
> mess to implement though.

True and true. It would be nice with some auto-config which sets up the 
environment to use the right python binary/symlink, and shouldn't be too 
messy if it's doable through something similar to virtualenv. I've seen 
similar approaches done with autoconf in gnome's jhbuild (although it 
failed on Arch too).

Yet, it's still needed to correct all the places using /usr/bin/python 
directly instead of depending on the environment.

> The change as it currently stands looks confusing as py_v3_check is
> set by running python2.

It becomes kind of redundant, yes. Maybe spit out a warning and some 
hints if default is python v3? A lot of packages might still depend on 
python2 as default, so users should be warned...

> I used to use a virtualenv to temporarily set Python 2 as the default
> for the shell in which I ran bitbake commands. That was a while ago
> though, all my current builds are running on Ubuntu 12.04/14.04 server
> instances which I access via ssh from my Arch Linux box.

Using a compatible distro-install is of course the easiest way to get 
going. Could also work with a virtual machine.

If this has interest, I will work on a python snippet to detect the 
possible python version, and setup the environment correspondingly.

Thanks,
Martin



More information about the Openembedded-core mailing list