Skip to contentSkip to conversation

selftest/buildoptions: pexpect not a builtin module

PATCH Superseded Benjamin Esquivel 4 participants 9 messages Sep 18, 2015 – Sep 21, 2015

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 selftest/buildoptions: pexpect not a builtin module

put the import of pexpect around a try statement so it can tell you why it failed to import when in a system that has the module unreachable

the message that outputs is:

"No module named pexpect, import failed"

---
 meta/lib/oeqa/selftest/buildoptions.py | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
meta/lib/oeqa/selftest/buildoptions.py +7 -1
index 483803b..9a3c9a1 100644
@@ -3,7 +3,13 @@ import os
 import logging
 import re
 import glob as g
-import pexpect as p
+
+try:
+    import pexpect as p
+except  ImportError as e:
+    import sys
+    sys.stderr.write("{}, import failed\n".format(e))
+    raise e
 
 from oeqa.selftest.base import oeSelfTest
 from oeqa.selftest.buildhistory import BuildhistoryBase
Signature · 1 line
2.5.1
#1 lore raw
Quoted 3 lines · Benjamin Esquivel

put the import of pexpect around a try statement so it can tell you why it failed to import when in a system that has the module unreachable

As the failing import is throwing an exception, can't the calling code display the exception correctly?

Ross

#2 lore raw
Quoted 8 lines · Ross

On 17 September 2015 at 21:38, Benjamin Esquivel <

Quoted 2 lines · [email protected]> wrote:

put the import of pexpect around a try statement so it can tell you why it failed to import when in a system that has the module unreachable

As the failing import is throwing an exception, can't the calling code display the exception correctly?

If we're going to trap this I think we should be displaying something like "Please install pexpect (python-pexpect)".

Cheers,
Paul

Signature · 2 lines
Paul Eggleton
Intel Open Source Technology Centre
#3 lore raw

PATCH v2 1/1 selftest/buildoptions: pexpect not a builtin module

put the import of pexpect around a try statement so it can tell you why it failed to import when in a system that has the module unreachable

the message that outputs is:

"No module named pexpect, import failed"
"Please install pexpect (python-pexpect)"

---
 meta/lib/oeqa/selftest/buildoptions.py | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
meta/lib/oeqa/selftest/buildoptions.py +8 -1
index 483803b..1fa4802 100644
@@ -3,7 +3,14 @@ import os
 import logging
 import re
 import glob as g
-import pexpect as p
+
+try:
+    import pexpect as p
+except  ImportError as e:
+    import sys
+    sys.stderr.write("{}, import failed\n".format(e))
+    sys.stderr.write("Please install pexpect (python-pexpect)\n")
+    raise e
 
 from oeqa.selftest.base import oeSelfTest
 from oeqa.selftest.buildhistory import BuildhistoryBase
Signature · 1 line
2.5.1
#4 lore raw

Hi Benjamin, Paul,

Just want to point out that 'pexpect' is an unused import in buildoptions.py. Unused imports are also unittest and logging. Instead of try-catch an import that is not used I think it's best to get rid of them.

--Daniel

-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of Benjamin Esquivel
Sent: Friday, September 18, 2015 11:34
To: [email protected]
Cc: [email protected]
Subject: [OE-core] [PATCH V2] selftest/buildoptions: pexpect not a builtin module

put the import of pexpect around a try statement so it can tell you why it failed to import when in a system that has the module unreachable

the message that outputs is:

"No module named pexpect, import failed"
"Please install pexpect (python-pexpect)"

---
 meta/lib/oeqa/selftest/buildoptions.py | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
meta/lib/oeqa/selftest/buildoptions.py +8 -2
index 483803b..1fa4802 100644
@@ -3,7 +3,14 @@ import os
 import logging
 import re
 import glob as g
-import pexpect as p
+
+try:
+    import pexpect as p
+except  ImportError as e:
+    import sys
+    sys.stderr.write("{}, import failed\n".format(e))
+    sys.stderr.write("Please install pexpect (python-pexpect)\n")
+    raise e
 
 from oeqa.selftest.base import oeSelfTest  from oeqa.selftest.buildhistory import BuildhistoryBase
--

2.5.1

--
_______________________________________________
Openembedded-core mailing list
[email protected]
http://lists.openembedded.org/mailman/listinfo/openembedded-core

#5 lore raw
Quoted 5 lines · Daniel AlexandruX

Just want to point out that 'pexpect' is an unused import in buildoptions.py. Unused imports are also unittest and logging. Instead of try-catch an import that is not used I think it's best to get rid of them.

Totally agreed. Can you send a quick patch?

Ross

#6 lore raw

Hi Ross,

I sent the patch: http://lists.openembedded.org/pipermail/openembedded-core/2015-September/110738.html

--Daniel

From: Burton, Ross [mailto:[email protected]]
Sent: Monday, September 21, 2015 13:20
To: Istrate, Daniel AlexandruX
Cc: Benjamin Esquivel; [email protected]; [email protected]
Subject: Re: [OE-core] [PATCH V2] selftest/buildoptions: pexpect not a builtin module

On 21 September 2015 at 09:37, Istrate, Daniel AlexandruX <[email protected]<mailto:[email protected]>> wrote:
Just want to point out that 'pexpect' is an unused import in buildoptions.py. Unused imports are also unittest and logging. Instead of try-catch an import that is not used I think it's best to get rid of them.

Totally agreed. Can you send a quick patch?

Ross

#7 lore raw

Great! thanks Daniel.

Quoted 26 lines · Daniel AlexandruX

Hi Ross,

I sent the patch: http://lists.openembedded.org/pipermail/openembedde
d-core/2015-September/110738.html

--Daniel

From: Burton, Ross [mailto:[email protected]]
Sent: Monday, September 21, 2015 13:20
To: Istrate, Daniel AlexandruX
Cc: Benjamin Esquivel; [email protected]; [email protected]
Subject: Re: [OE-core] [PATCH V2] selftest/buildoptions: pexpect not a builtin module

On 21 September 2015 at 09:37, Istrate, Daniel AlexandruX < [email protected]> wrote:
Just want to point out that 'pexpect' is an unused import in buildoptions.py. Unused imports are also unittest and logging. Instead of try-catch an import that is not used I think it's best to get rid of them.

Totally agreed. Can you send a quick patch?

Ross

#8 lore raw
In reply to Burton, Ross
Quoted 9 lines · Ross
Quoted 4 lines · Benjamin Esquivel

put the import of pexpect around a try statement so it can tell you why it failed to import when in a system that has the module unreachable

As the failing import is throwing an exception, can't the calling code display the exception correctly?

This is the logging without the change:

2015-09-18 08:27:44,233 - selftest - INFO - Loading tests from:
oeqa.selftest.buildhistory
2015-09-18 08:27:44,234 - selftest - INFO - Loading tests from:
oeqa.selftest.buildoptions
2015-09-18 08:27:44,236 - selftest - ERROR - Failed to import
oeqa.selftest.buildoptions
2015-09-18 08:27:44,236 - selftest - ERROR - 'module' object has no
attribute 'buildoptions'
This is the logging with the proposed change and including Paul's
comment:
2015-09-18 08:27:44,233 - selftest - INFO - Loading tests from:
oeqa.selftest.buildhistory
2015-09-18 08:27:44,234 - selftest - INFO - Loading tests from:
oeqa.selftest.buildoptions
No module named pexpect, import failed
Please install pexpect (python-pexpect)
2015-09-18 08:27:44,236 - selftest - ERROR - Failed to import
oeqa.selftest.buildoptions
2015-09-18 08:27:44,236 - selftest - ERROR - 'module' object has no

attribute 'buildoptions'
I'm sending the patch V2

Quoted 2 lines
Quoted 1 line

Ross