public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
* [Patch V2] BaseTools: Add python3-distutils Ubuntu package checking
@ 2019-02-28  2:04 Feng, Bob C
  2019-02-28 10:57 ` Philippe Mathieu-Daudé
  0 siblings, 1 reply; 2+ messages in thread
From: Feng, Bob C @ 2019-02-28  2:04 UTC (permalink / raw)
  To: edk2-devel; +Cc: Bob Feng, Liming Gao

https://bugzilla.tianocore.org/show_bug.cgi?id=1509
V2:
Remove OS/Package specific words. Print the error info which
is from python error message.

Add python3-distutils Ubuntu package checking.

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Bob Feng <bob.c.feng@intel.com>
Cc: Liming Gao <liming.gao@intel.com>
---
 BaseTools/Tests/RunTests.py | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/BaseTools/Tests/RunTests.py b/BaseTools/Tests/RunTests.py
index 0dd65632d0..f6d3f43653 100644
--- a/BaseTools/Tests/RunTests.py
+++ b/BaseTools/Tests/RunTests.py
@@ -17,10 +17,22 @@
 #
 import os
 import sys
 import unittest
 
+distutils_exist = True
+try:
+    import distutils.util
+except:
+    distutils_exist = False
+
+if not distutils_exist:
+    print("""
+Python report "No module named 'distutils.uitl'"
+""")
+    sys.exit(-1)
+
 import TestTools
 
 def GetCTestSuite():
     import CToolsTests
     return CToolsTests.TheTestSuite()
-- 
2.20.1.windows.1



^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [Patch V2] BaseTools: Add python3-distutils Ubuntu package checking
  2019-02-28  2:04 [Patch V2] BaseTools: Add python3-distutils Ubuntu package checking Feng, Bob C
@ 2019-02-28 10:57 ` Philippe Mathieu-Daudé
  0 siblings, 0 replies; 2+ messages in thread
From: Philippe Mathieu-Daudé @ 2019-02-28 10:57 UTC (permalink / raw)
  To: Feng, Bob C, edk2-devel
  Cc: Liming Gao, Laszlo Ersek, Ard Biesheuvel, Leif Lindholm

On 2/28/19 3:04 AM, Feng, Bob C wrote:
> https://bugzilla.tianocore.org/show_bug.cgi?id=1509
> V2:
> Remove OS/Package specific words. Print the error info which
> is from python error message.
> 
> Add python3-distutils Ubuntu package checking.
> 
> Contributed-under: TianoCore Contribution Agreement 1.1
> Signed-off-by: Bob Feng <bob.c.feng@intel.com>
> Cc: Liming Gao <liming.gao@intel.com>
> ---
>  BaseTools/Tests/RunTests.py | 12 ++++++++++++
>  1 file changed, 12 insertions(+)
> 
> diff --git a/BaseTools/Tests/RunTests.py b/BaseTools/Tests/RunTests.py
> index 0dd65632d0..f6d3f43653 100644
> --- a/BaseTools/Tests/RunTests.py
> +++ b/BaseTools/Tests/RunTests.py
> @@ -17,10 +17,22 @@
>  #
>  import os
>  import sys
>  import unittest
>  
> +distutils_exist = True

Why this variable? You can achieve the same without adding variables in
the global namespace.

> +try:
> +    import distutils.util
> +except:

I'd restrict that to ImportError, just in case.

> +    distutils_exist = False
> +
> +if not distutils_exist:
> +    print("""
> +Python report "No module named 'distutils.uitl'"

'distutils.util' ;)

> +""")
> +    sys.exit(-1)

Per the sys.exit doc:

  The optional argument arg can be an integer giving the exit status
  (defaulting to zero), or another type of object. If it is an integer,
  zero is considered “successful termination” and any nonzero value is
  considered “abnormal termination” by shells and the like. Most systems
  require it to be in the range 0–127, and produce undefined results
  otherwise.

Can we avoid to use negative return values?

I suggest to simply use this snippet:

  try:
      import distutils.util
  except ImportError as error:
      sys.exit("Python reported: " + error.message)

Note the difference with your patch are:
- no global namespace variable used
- exception not Import related still display stack dump
- the error message is displayed on stderr rather than stdout
- the return value is 1 instead of -1

Regards,

Phil.

>  import TestTools
>  
>  def GetCTestSuite():
>      import CToolsTests
>      return CToolsTests.TheTestSuite()
> 


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2019-02-28 10:57 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-02-28  2:04 [Patch V2] BaseTools: Add python3-distutils Ubuntu package checking Feng, Bob C
2019-02-28 10:57 ` Philippe Mathieu-Daudé

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox