From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: mx.groups.io; dkim=pass header.i=@linaro.org header.s=google header.b=p0p/XT9u; spf=pass (domain: linaro.org, ip: 209.85.128.67, mailfrom: leif.lindholm@linaro.org) Received: from mail-wm1-f67.google.com (mail-wm1-f67.google.com [209.85.128.67]) by groups.io with SMTP; Tue, 16 Jul 2019 04:35:57 -0700 Received: by mail-wm1-f67.google.com with SMTP id a15so18291297wmj.5 for ; Tue, 16 Jul 2019 04:35:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=OEjBQqdyCXkpd/EeRYpoTK/P+CtPjhzYXyHs0OF6d+U=; b=p0p/XT9uevek60ZyfNaUXfK7NYFd25IxYNvfgXMc8OqVqFV23DiFeUL3r1f2ZOlNIW LwwxWEb5XOs/5F/cQFGZ6DQ8j22ugYPZrtiynKvslAtTtVmrWXeCR9TWbTJviLkul6SB Tm6BpPF91fhPQKK9IjPNhHVBKpdcxIV20zWUASzUxE4yUeU2CU1aa4KFB7An51rM5Y6g ph2BJnZrmxV+FNfQ0ZTJnyFMXlb1U0zK5SnZXOkIN5+Wlc6mWNxQ6pC6rDV0IBfr5sEY KGio4me6LIM2OoFKJlboRGdRUb9S8ICJ2jX5PH7tQqHEr9JfaHHOUQ+dKu0pHKNtH8xQ KJWg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=OEjBQqdyCXkpd/EeRYpoTK/P+CtPjhzYXyHs0OF6d+U=; b=blxxmb4+w5l6YdN8k3/sESpTJibgVCfm+A6Y3MXIdW6Tc2HMKEeLeDd4D9lU+pE+kW rZSfNhP6vR6iSuRmjbvN/KxQGwz4g1PU26Iw7wr7pVsPCLYkQkA0el2rwUtG23Jy+3JC hlwPj3Gpg5JfcYUtaTv+qIViwAKlaDgK6JpOE1A/I+2jZ2PoV85vrHmzbOpbjVhEbKqE cQ6DrycF6hfuv8juuxd38pZ04tvY2kMGN+dUyXxhVodI1AXTPX3igj3oAQpHPAlLDF6H HmmwgMWxU7Wv5gicTFhpp+RzWV28AszJPO1qr5F7vFmIbjnjFwOt5hzUYue2envUoWOq vpPQ== X-Gm-Message-State: APjAAAVQQr7QU1eKZtF1Zh4UrY0WCOi6/lZqlN5EajwiAkqMtz4EO5ZB XWt6Or2Vrk6JD2bKjU/KqvMG+w== X-Google-Smtp-Source: APXvYqz1dIwyFKDcSDOMC7Tu7P8dFf1w5l6Lznol3/iV+YZz0K3m+pHE51HjZppccWzhSrSY6xG9BQ== X-Received: by 2002:a1c:c545:: with SMTP id v66mr31045115wmf.51.1563276955204; Tue, 16 Jul 2019 04:35:55 -0700 (PDT) Return-Path: Received: from bivouac.eciton.net (bivouac.eciton.net. [2a00:1098:0:86:1000:23:0:2]) by smtp.gmail.com with ESMTPSA id y16sm19233248wrw.33.2019.07.16.04.35.54 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 16 Jul 2019 04:35:54 -0700 (PDT) Date: Tue, 16 Jul 2019 12:35:53 +0100 From: "Leif Lindholm" To: Rebecca Cran Cc: devel@edk2.groups.io, lersek@redhat.com, bob.c.feng@intel.com, liming.gao@intel.com, michael.d.kinney@intel.com, afish@apple.com, "Zhiju.Fan" Subject: Re: [PATCH v2] edksetup.sh: Simplify SetupPython3 and SetupPython functions. Message-ID: <20190716113552.bn6du2j4j2jloymm@bivouac.eciton.net> References: <20190716023606.54076-1-rebecca@bsdio.com> MIME-Version: 1.0 In-Reply-To: <20190716023606.54076-1-rebecca@bsdio.com> User-Agent: NeoMutt/20170113 (1.7.2) Content-Type: text/plain; charset=us-ascii Content-Disposition: inline +Bob, Liming, Zhijux On Mon, Jul 15, 2019 at 08:36:06PM -0600, Rebecca Cran wrote: > On Linux, "whereis" matches python3, python3.7, as well as > man pages, libs etc. While on macOS it only matches the specified > name, and so misses python3.7. Improve this by looping over > potential version numbers and seeing if such a binary exists and > can be executed. So, let's start by admitting I didn't bother reviewing the existing code very closely when it was first merged - just verifying it looked like it may be doing what it intends to do (on Linux, sorry). Looking more closely now, I have to say I'm not a fan. Effectively what it does is to pick the highest-version-number python installed in the system, regardless of what the administrator has set as the system default - and certainly likely to. This seems likely to lead to a really fun debugging session for someone down the line. So first of all, I would like to understand why we're doing this at all? Are we likely to see installations that have a python3.7 binary, but no python3? If we _are_ keeping it, I would really rather rewrite this as something that walks PATH and looks at wildcard matches rather than something that makes assumptions of maximum version numbers. i.e. PYTHONS= IFS=":" for dir in $PATH; do for file in $dir/python3\.*; do if [ -f $file ]; then PYTHONS=$file:$PYTHONS fi done done IFS=" " (Of course, we would also need to filter out -m versions. Or we could assume people have a functional python3 on the PATH and would like to use that? Best Regards, Leif > Signed-off-by: Rebecca Cran > --- > edksetup.sh | 44 +++++++------------------------------------- > 1 file changed, 7 insertions(+), 37 deletions(-) > > diff --git a/edksetup.sh b/edksetup.sh > index 06d2f041e6..5b90e55ed8 100755 > --- a/edksetup.sh > +++ b/edksetup.sh > @@ -107,24 +107,10 @@ function SetupEnv() > > function SetupPython3() > { > - if [ $origin_version ];then > - origin_version= > - fi > - for python in $(whereis python3) > - do > - python=$(echo $python | grep "[[:digit:]]$" || true) > - python_version=${python##*python} > - if [ -z "${python_version}" ] || (! command -v $python >/dev/null 2>&1);then > - continue > - fi > - if [ -z $origin_version ];then > - origin_version=$python_version > - export PYTHON_COMMAND=$python > - continue > - fi > - if [[ "$origin_version" < "$python_version" ]]; then > - origin_version=$python_version > + for ((pyver=15; pyver>=1; --pyver)); do > + if python=$(command -v python3.$pyver); then > export PYTHON_COMMAND=$python > + break > fi > done > return 0 > @@ -146,27 +132,11 @@ function SetupPython() > SetupPython3 > fi > > - if [ $PYTHON3_ENABLE ] && [ $PYTHON3_ENABLE != TRUE ] > - then > - if [ $origin_version ];then > - origin_version= > - fi > - for python in $(whereis python2) > - do > - python=$(echo $python | grep "[[:digit:]]$" || true) > - python_version=${python##*python} > - if [ -z "${python_version}" ] || (! command -v $python >/dev/null 2>&1);then > - continue > - fi > - if [ -z $origin_version ] > - then > - origin_version=$python_version > - export PYTHON_COMMAND=$python > - continue > - fi > - if [[ "$origin_version" < "$python_version" ]]; then > - origin_version=$python_version > + if [ -n "$PYTHON3_ENABLE" ] && [ "$PYTHON3_ENABLE" != "TRUE" ]; then > + for ((pyver=10; pyver>=1; --pyver)); do > + if python=$(command -v python2.$pyver); then > export PYTHON_COMMAND=$python > + break > fi > done > return 0 > -- > 2.22.0 >