From: "Leif Lindholm" <leif.lindholm@linaro.org>
To: Rebecca Cran <rebecca@bsdio.com>
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" <zhijux.fan@intel.com>
Subject: Re: [PATCH v2] edksetup.sh: Simplify SetupPython3 and SetupPython functions.
Date: Tue, 16 Jul 2019 12:35:53 +0100 [thread overview]
Message-ID: <20190716113552.bn6du2j4j2jloymm@bivouac.eciton.net> (raw)
In-Reply-To: <20190716023606.54076-1-rebecca@bsdio.com>
+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 <rebecca@bsdio.com>
> ---
> 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
>
next prev parent reply other threads:[~2019-07-16 11:35 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-07-16 2:36 [PATCH v2] edksetup.sh: Simplify SetupPython3 and SetupPython functions rebecca
2019-07-16 10:41 ` Laszlo Ersek
2019-07-16 11:35 ` Leif Lindholm [this message]
2019-07-16 14:17 ` [edk2-devel] " rebecca
2019-07-16 14:22 ` Leif Lindholm
2019-07-16 16:36 ` rebecca
2019-07-16 14:31 ` Laszlo Ersek
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-list from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190716113552.bn6du2j4j2jloymm@bivouac.eciton.net \
--to=devel@edk2.groups.io \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox