<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://bugzilla.yoctoproject.org/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.6"
          urlbase="https://bugzilla.yoctoproject.org/"
          
          maintainer="it-coreprojects-helpdesk@linuxfoundation.org"
>

    <bug>
          <bug_id>10896</bug_id>
          
          <creation_ts>2017-01-07 23:28:23 +0000</creation_ts>
          <short_desc>bad magic number in &apos;oeqa&apos;: b&apos;\x03\xf3\r\n&apos;</short_desc>
          <delta_ts>2017-12-06 17:22:15 +0000</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>10</classification_id>
          <classification>QA/Testing</classification>
          <product>Runtime Testing</product>
          <component>general</component>
          <version>2.2.1</version>
          <rep_platform>x86</rep_platform>
          <op_sys>Multiple</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>NOTABUG</resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>Medium</priority>
          <bug_severity>normal</bug_severity>
          <target_milestone>2.4 M2</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Armin Kuster">akuster</reporter>
          <assigned_to name="Richard Purdie">richard.purdie</assigned_to>
          <cc>benjamin.esquivel</cc>
    
    <cc>brian.avery</cc>
    
    <cc>joshuagloe</cc>
    
    <cc>ross.burton</cc>
          
          
          <cf_os>---</cf_os>
          <cf_regression_type>---</cf_regression_type>
          
          <cf_docchange>Don&apos;t know</cf_docchange>

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>69612</commentid>
    <comment_count>0</comment_count>
    <who name="Armin Kuster">akuster</who>
    <bug_when>2017-01-07 23:28:23 +0000</bug_when>
    <thetext>File: &apos;/home/akuster/oss/maint/poky/meta/classes/testimage.bbclass&apos;, lineno: 126, function: testimage_main
     0122:
     0123:def testimage_main(d):
     0124:    import unittest
     0125:    import os
 *** 0126:    import oeqa.runtime
     0127:    import time
     0128:    import signal
     0129:    from oeqa.oetest import ImageTestContext
     0130:    from oeqa.targetcontrol import get_target_controller
Exception: ImportError: bad magic number in &apos;oeqa&apos;: b&apos;\x03\xf3\r\n&apos;


I have only tried Morty. I initially saw this on a Ubuntu 16.0x system. My system was updated via Ubuntu&apos;s &apos;do release update&apos; process that failed so I wrote this error off do to that. Over Xmas break I updated the system to Fedora Core 25 and am still seeing the issue.

I finally had some time to poke at it and it looks like a pythong2 / python3 issue.

as simple test 
python -c &apos;import runtime&apos;
python3 -c &apos;import runtime&apos;
Traceback (most recent call last):
  File &quot;&lt;string&gt;&quot;, line 1, in &lt;module&gt;
ImportError: bad magic number in &apos;runtime&apos;: b&apos;\x03\xf3\r\n&apos;

 I noticed the runtime dir had a lot of *.pyc files, I deleted those and the problem went away.

I now think this is an issue if someone builds krogoth then Morty within the same repo.

Is this an FAQ, doc, wiki note or just an Old man thing?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>69832</commentid>
    <comment_count>1</comment_count>
    <who name="Benjamin Esquivel">benjamin.esquivel</who>
    <bug_when>2017-01-16 17:28:09 +0000</bug_when>
    <thetext>I&apos;ve seen this in the past and I did the same workaround that you did, erasing the .pyc files. I believe your analysis is pointing towards .pyc files that are generated by Python2 and then tried to be used by Python3. If this is indeed the case, it means you could reproduce it by running tests on YP releases pre/post Python2/3 change.

I would not consider this a case a lot of users are going to find so a wiki note with the workaround might do the trick. A better solution would be to handle the exception with an error indicating what we know about it and how could it be fixed (workaround again here)</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>70754</commentid>
    <comment_count>2</comment_count>
    <who name="Joshua Lock">joshuagloe</who>
    <bug_when>2017-02-16 16:43:22 +0000</bug_when>
    <thetext>Python 3 bytecode files are usually stored in a __pycache__ directory, so it&apos;s somewhat of a surprise that we&apos;re trying to use the Python 2.7 pyc files that live alongside the source.

According to PEP-3147[1]:

&quot;Python will ignore all legacy pyc files when a source file exists next to it. In other words, if a foo.pyc file exists next to the foo.py file, the pyc file will be ignored in all cases &quot;

It sounds like we have a bug here. Why are we trying to load the 2.7 bytecode in Python3 when PEP-3147 states that shouldn&apos;t happen? Are we somehow telling Python to do that when mangling load paths to load from a layers meta/lib?

1. https://www.python.org/dev/peps/pep-3147/
2. http://raulcd.com/how-python-caches-compiled-bytecode.html</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>70755</commentid>
    <comment_count>3</comment_count>
    <who name="brian avery">brian.avery</who>
    <bug_when>2017-02-16 16:46:54 +0000</bug_when>
    <thetext>On both a clean crops/poky:ubuntu-16.04 and crops/poky:fedora-25 I did the following:

# apt-get/dnf install python-pip
# apt-get/dnf install python3-pip
# pip install runtime
# pip3 install runtime greenlet

$ python -c &apos;import runtime&apos;
$ python3 -c &apos;import runtime&apos;

----
There were no errors, so it seems likely that something else is [ea]ffecting this. The above container have the minimal requirements for oe/poky builds, which is why I had to install  pip and pip3 by hand.

----</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>73734</commentid>
    <comment_count>4</comment_count>
    <who name="Ross Burton">ross.burton</who>
    <bug_when>2017-06-06 11:20:39 +0000</bug_when>
    <thetext>Made it happen!

$ cd poky/meta/lib
$ git checkout origin/krogoth
$ PYTHONPATH=. python
&gt;&gt;&gt; import oeqa.runtime
$ git checkout origin/master
$ PYTHONPATH=. python3
&gt;&gt;&gt; import oeqa
Traceback (most recent call last):
  File &quot;&lt;stdin&gt;&quot;, line 1, in &lt;module&gt;
ImportError: bad magic number in &apos;oeqa&apos;: b&apos;\x03\xf3\r\n&apos;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>73735</commentid>
    <comment_count>5</comment_count>
    <who name="Ross Burton">ross.burton</who>
    <bug_when>2017-06-06 11:21:58 +0000</bug_when>
    <thetext>getcwd(&quot;/home/ross/Yocto/poky/meta/lib&quot;, 1026) = 31
stat(&quot;/home/ross/Yocto/poky/meta/lib&quot;, {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0
stat(&quot;/home/ross/Yocto/poky/meta/lib/oeqa/__init__.cpython-34m-x86_64-linux-gnu.so&quot;, 0x7ffcdb0331c0) = -1 ENOENT (No such file or directory)
stat(&quot;/home/ross/Yocto/poky/meta/lib/oeqa/__init__.cpython-34m.so&quot;, 0x7ffcdb0331c0) = -1 ENOENT (No such file or directory)
stat(&quot;/home/ross/Yocto/poky/meta/lib/oeqa/__init__.abi3.so&quot;, 0x7ffcdb0331c0) = -1 ENOENT (No such file or directory)
stat(&quot;/home/ross/Yocto/poky/meta/lib/oeqa/__init__.so&quot;, 0x7ffcdb0331c0) = -1 ENOENT (No such file or directory)
stat(&quot;/home/ross/Yocto/poky/meta/lib/oeqa/__init__.py&quot;, 0x7ffcdb0331c0) = -1 ENOENT (No such file or directory)
stat(&quot;/home/ross/Yocto/poky/meta/lib/oeqa/__init__.pyc&quot;, {st_mode=S_IFREG|0644, st_size=103, ...}) = 0
getcwd(&quot;/home/ross/Yocto/poky/meta/lib&quot;, 1026) = 31
stat(&quot;/home/ross/Yocto/poky/meta/lib&quot;, {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0
stat(&quot;/home/ross/Yocto/poky/meta/lib/oeqa/__init__.cpython-34m-x86_64-linux-gnu.so&quot;, 0x7ffcdb032c20) = -1 ENOENT (No such file or directory)
stat(&quot;/home/ross/Yocto/poky/meta/lib/oeqa/__init__.cpython-34m.so&quot;, 0x7ffcdb032c20) = -1 ENOENT (No such file or directory)
stat(&quot;/home/ross/Yocto/poky/meta/lib/oeqa/__init__.abi3.so&quot;, 0x7ffcdb032c20) = -1 ENOENT (No such file or directory)
stat(&quot;/home/ross/Yocto/poky/meta/lib/oeqa/__init__.so&quot;, 0x7ffcdb032c20) = -1 ENOENT (No such file or directory)
stat(&quot;/home/ross/Yocto/poky/meta/lib/oeqa/__init__.py&quot;, 0x7ffcdb032c20) = -1 ENOENT (No such file or directory)
stat(&quot;/home/ross/Yocto/poky/meta/lib/oeqa/__init__.pyc&quot;, {st_mode=S_IFREG|0644, st_size=103, ...}) = 0
open(&quot;/home/ross/Yocto/poky/meta/lib/oeqa/__init__.pyc&quot;, O_RDONLY|O_CLOEXEC) = 3</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>73736</commentid>
    <comment_count>6</comment_count>
    <who name="Ross Burton">ross.burton</who>
    <bug_when>2017-06-06 11:23:43 +0000</bug_when>
    <thetext>So why is it looking for .pyc before __pycache__?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>73740</commentid>
    <comment_count>7</comment_count>
    <who name="Ross Burton">ross.burton</who>
    <bug_when>2017-06-06 11:35:58 +0000</bug_when>
    <thetext>So py3 looks for __init__.py but that isn&apos;t present as it&apos;s optional in py3, but then finds the .pyc and fails.

Stupid python.

I think we just need to add back the missing empty __init__.py files.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>73744</commentid>
    <comment_count>8</comment_count>
    <who name="Ross Burton">ross.burton</who>
    <bug_when>2017-06-06 11:56:19 +0000</bug_when>
    <thetext>Ok, so I have a patch which adds back about ten empty __init__.py files into meta/lib/oeqa.

Or we tell people that this is what happens if you switch a branch between versions without doing a clean first.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>73880</commentid>
    <comment_count>9</comment_count>
    <who name="Ross Burton">ross.burton</who>
    <bug_when>2017-06-08 13:26:24 +0000</bug_when>
    <thetext>Personally I think that this is a subtle gotcha but one that we can&apos;t neatly handle: module paths change over time and we&apos;d need to maintain empty __init__.py in every directory.

I prefer the solution of &quot;run git clean&quot; to remove these files if you switch between py2 and py3 branches in the same repository.  Or, use git-worktree.</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>