Bug 4427

Summary: python-native: the assert doesn't work
Product: [Build System, Metadata & Runtime] OE-Core Reporter: Robert Yang <liezhi.yang>
Component: devtools / tool chainAssignee: Robert Yang <liezhi.yang>
Status: VERIFIED FIXED QA Contact:
Severity: normal    
Priority: Medium CC: meta.mr.watcher, meta.watcher, ning.zhang, nitin.a.kamble, richard.purdie, sgw
Version: 1.5   
Target Milestone: 1.5 M1   
Hardware: x86   
OS: Multiple   
Whiteboard:
OS type for building Yocto: --- Type of Regression: ---
Verified: Documentation change: ---

Description Robert Yang 2013-04-29 08:25:53 UTC
We had set the deafult optimization to 1 by the patch 04-default-is-optimized.patch, the assert doesn't work when optimization is 1, both native and target have this patch, but they are different, the target's optimization can be disabled by the "-N" option, the native python doesn't have the "-N" option. I think that we have two solutions:

1) Add the "-N" option for the native python

or

2) We won't set the optimization by default just like other distributions do, the user can set it by the "-O" option, we have removed the "-O" and "-OO" option currently.
Comment 1 Saul Wold 2013-04-29 18:31:36 UTC
What issue are you trying to solve?
Comment 2 Robert Yang 2013-04-30 01:43:38 UTC
(In reply to comment #1)
> What issue are you trying to solve?

Hi Saul, the 'assert' statement doesn't work which would cause/hide unexpected errors, and it is a widely used statement, e.g., the 'assert False' should raise an exception, but it doesn't since we have hard coded the default optimizaton to 1 (the assert would work when optimization is 0), usually, the python would work like this: Set the default optimizaton to 0 (and use -O/-OO to optimize when the user needs), we have set the default optimizaton to 1 by default ( we have disabled to -O/-OO, there is a "-N" option for the target python, but no such an option for the native python), my suggestions are:

1) We would not set the default optimization to 1, and don't disable the -O/-OO

Or

2) If we want to set it, we should not change the source code to hard code it, we can "export PYTHONOPTIMIZE=1 or 2" in the env by default.

Or

3) I think that we should do no optimization for the native python by default.
Comment 4 Ning Zhang 2013-05-28 09:33:19 UTC
Verified with poky(master:176a46b088135f2891983bb8540bc45389341d90)

Native test log:

wrsadmin@pek-nzhang0-d3:/home/yocto/20130527/tmp/sysroots/x86_64-linux/usr/bin/python-native$ python -N
Unknown option: -N
Unknown option: -N
usage: python [option] ... [-c cmd | -m mod | file | -] [arg] ...
Try `python -h' for more information.

wrsadmin@pek-nzhang0-d3:/home/yocto/20130527/tmp/sysroots/x86_64-linux/usr/bin/python-native$ python -O
Python 2.7.3 (default, Aug  1 2012, 05:14:39) 
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> assert False
>>> 

wrsadmin@pek-nzhang0-d3:/home/yocto/20130527/tmp/sysroots/x86_64-linux/usr/bin/python-native$ python
Python 2.7.3 (default, Aug  1 2012, 05:14:39) 
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> assert False
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AssertionError

Target python test result is same.