From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=209.85.128.50; helo=mail-wm1-f50.google.com; envelope-from=philmd@redhat.com; receiver=edk2-devel@lists.01.org Received: from mail-wm1-f50.google.com (mail-wm1-f50.google.com [209.85.128.50]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 80C09208EB417 for ; Thu, 28 Feb 2019 02:57:20 -0800 (PST) Received: by mail-wm1-f50.google.com with SMTP id g20so7695998wmh.5 for ; Thu, 28 Feb 2019 02:57:20 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:openpgp:message-id :date:user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=ByalkOGrpdw1oyfOrdHdwhFv1hu0LRnICAMCDbfZGFk=; b=RscyzIaQVX5TbDigZeBAdYiu3D5QfBfbrLEAyDpE/9dpo8pW8KI+Ud9peH7Mex2WHg w3A5XID+CRvC3icCbaLRMnPSYuv9XKyckmcGoMvbaBt60gwrUDIZuq7HwDGEX7OedngZ jcZ0ZbhepUCZbjVtv8cP5JuP3NPHKMy+KGEt7rWrtseiTo5YILMkVDPHNtTrB7FCMLEc ezJHmPNZ5zKOjTUcZqise2l0TEurdYMvtRRi1Y8/VTHj74jy6AiMpGTWPvv4APbAfJCp QlnXT5Y3FLCECOxa31mRA5vqkCp9wM70SdnjIHhdsAMBznOAjNyf0DjF8yrqcWyE+IX3 a/AQ== X-Gm-Message-State: APjAAAUYjvNNvcQy+VsHt1PuONwaks4Jd/18OSg3HBmKPQ0dR7/VBHYG tMLoqPcfBTRrwPTW2Zq9ZvRKT78wF4gKkA== X-Google-Smtp-Source: APXvYqxsZnwpK1DtIpVbcD/UK8hq4Hr7vvtdHAL7Get88MVPMQxhLVusU6/Nmnvbnhu/+uIsWZ6Cwg== X-Received: by 2002:a1c:740d:: with SMTP id p13mr2692802wmc.46.1551351438742; Thu, 28 Feb 2019 02:57:18 -0800 (PST) Received: from [192.168.1.37] (43.red-88-25-181.staticip.rima-tde.net. [88.25.181.43]) by smtp.gmail.com with ESMTPSA id g10sm27446838wrq.61.2019.02.28.02.57.17 (version=TLS1_3 cipher=AEAD-AES128-GCM-SHA256 bits=128/128); Thu, 28 Feb 2019 02:57:18 -0800 (PST) To: "Feng, Bob C" , edk2-devel@lists.01.org Cc: Liming Gao , Laszlo Ersek , Ard Biesheuvel , Leif Lindholm References: <20190228020447.24768-1-bob.c.feng@intel.com> From: =?UTF-8?Q?Philippe_Mathieu-Daud=c3=a9?= Openpgp: id=89C1E78F601EE86C867495CBA2A3FD6EDEADC0DE; url=http://pgp.mit.edu/pks/lookup?op=get&search=0xA2A3FD6EDEADC0DE Message-ID: Date: Thu, 28 Feb 2019 11:57:17 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.5.1 MIME-Version: 1.0 In-Reply-To: <20190228020447.24768-1-bob.c.feng@intel.com> Subject: Re: [Patch V2] BaseTools: Add python3-distutils Ubuntu package checking X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 28 Feb 2019 10:57:20 -0000 Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit 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 > Cc: Liming Gao > --- > 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() >