diff mbox series

[v4,4/4] ci: install python on ubuntu

Message ID 20221125095954.4826-5-worldhello.net@gmail.com (mailing list archive)
State Accepted
Commit 0d3507f3e7b74ccbaa6f1ddc282cf467cce0e102
Headers show
Series Fix broken CI on newer github-actions runner image | expand

Commit Message

Jiang Xin Nov. 25, 2022, 9:59 a.m. UTC
From: Jiang Xin <zhiyou.jx@alibaba-inc.com>

Python is missing from the default ubuntu-22.04 runner image, which
prevent git-p4 from working. To install python on ubuntu, we need to
provide correct package name:

 * On Ubuntu 18.04 (bionic), "/usr/bin/python2" is provided by the
   "python" package, and "/usr/bin/python3" is provided by the "python3"
   package.

 * On Ubuntu 20.04 (focal) and above, "/usr/bin/python2" is provided by
   the "python2" package which has a different name from bionic, and
   "/usr/bin/python3" is provided by "python3".

Since the "ubuntu-latest" runner image has a higher version, so its safe
to use "python2" or "python3" package name.

Helped-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: Jiang Xin <zhiyou.jx@alibaba-inc.com>
---
 ci/install-dependencies.sh | 2 +-
 ci/lib.sh                  | 8 ++++----
 2 files changed, 5 insertions(+), 5 deletions(-)

Comments

Junio C Hamano Nov. 27, 2022, 12:30 a.m. UTC | #1
Jiang Xin <worldhello.net@gmail.com> writes:

> From: Jiang Xin <zhiyou.jx@alibaba-inc.com>
>
> Python is missing from the default ubuntu-22.04 runner image, which
> prevent git-p4 from working. To install python on ubuntu, we need to
> provide correct package name:
>
>  * On Ubuntu 18.04 (bionic), "/usr/bin/python2" is provided by the
>    "python" package, and "/usr/bin/python3" is provided by the "python3"
>    package.
>
>  * On Ubuntu 20.04 (focal) and above, "/usr/bin/python2" is provided by
>    the "python2" package which has a different name from bionic, and
>    "/usr/bin/python3" is provided by "python3".
>
> Since the "ubuntu-latest" runner image has a higher version, so its safe
> to use "python2" or "python3" package name.

Makes sense.  Just out of curiousity (read: not a suggestion to
change anything), what happens if you say "apt install python" on a
recent system?

Will queue.  Thanks.

> Helped-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
> Signed-off-by: Jiang Xin <zhiyou.jx@alibaba-inc.com>
> ---
>  ci/install-dependencies.sh | 2 +-
>  ci/lib.sh                  | 8 ++++----
>  2 files changed, 5 insertions(+), 5 deletions(-)
>
> diff --git a/ci/install-dependencies.sh b/ci/install-dependencies.sh
> index b569893b38..d8fafc8ed2 100755
> --- a/ci/install-dependencies.sh
> +++ b/ci/install-dependencies.sh
> @@ -15,7 +15,7 @@ case "$runs_on_pool" in
>  ubuntu-*)
>  	sudo apt-get -q update
>  	sudo apt-get -q -y install language-pack-is libsvn-perl apache2 \
> -		$UBUNTU_COMMON_PKGS $CC_PACKAGE
> +		$UBUNTU_COMMON_PKGS $CC_PACKAGE $PYTHON_PACKAGE
>  	mkdir --parents "$P4_PATH"
>  	pushd "$P4_PATH"
>  		wget --quiet "$P4WHENCE/bin.linux26x86_64/p4d"
> diff --git a/ci/lib.sh b/ci/lib.sh
> index 927b4529b0..cb30699f34 100755
> --- a/ci/lib.sh
> +++ b/ci/lib.sh
> @@ -232,12 +232,12 @@ ubuntu-*)
>  		break
>  	fi
>  
> -	if [ "$jobname" = linux-gcc ]
> +	PYTHON_PACKAGE=python2
> +	if test "$jobname" = linux-gcc
>  	then
> -		MAKEFLAGS="$MAKEFLAGS PYTHON_PATH=/usr/bin/python3"
> -	else
> -		MAKEFLAGS="$MAKEFLAGS PYTHON_PATH=/usr/bin/python2"
> +		PYTHON_PACKAGE=python3
>  	fi
> +	MAKEFLAGS="$MAKEFLAGS PYTHON_PATH=/usr/bin/$PYTHON_PACKAGE"
>  
>  	export GIT_TEST_HTTPD=true
Jiang Xin Nov. 27, 2022, 9:01 a.m. UTC | #2
On Sun, Nov 27, 2022 at 8:30 AM Junio C Hamano <gitster@pobox.com> wrote:
> > Since the "ubuntu-latest" runner image has a higher version, so its safe
> > to use "python2" or "python3" package name.
>
> Makes sense.  Just out of curiousity (read: not a suggestion to
> change anything), what happens if you say "apt install python" on a
> recent system?

In order to reproduce, I start a docker container like  this:

    $ docker run -it --rm ubuntu:22.04 /bin/bash

Fetch the latest apt source list, by running:

    $ apt-get update

Then install python with the following errors:

    $ apt-get install python
    Reading package lists... Done
    Building dependency tree... Done
    Reading state information... Done
    Package python is not available, but is referred to by another package.
This may mean that the package is missing, has been obsoleted, or
is only available from another source
However the following packages replace it:
  2to3 python2-minimal python2 dh-python python-is-python3

E: Package 'python' has no installation candidate

We can also find python package name from packages.ubuntu.com:

1. form the link below, we can say Ubuntu 18.04 is the last version
(LTS?) which has python package:

    https://packages.ubuntu.com/search?keywords=python&searchon=names&suite=all&section=all

2. Ubuntu 20.04 is the first version (LTS) which rename its python
pacakge to python2 package:

    https://packages.ubuntu.com/search?keywords=python2&searchon=names&suite=all&section=all

> Will queue.  Thanks.

Thanks.

--
Jiang Xin
Junio C Hamano Nov. 27, 2022, 11:36 p.m. UTC | #3
Jiang Xin <worldhello.net@gmail.com> writes:

>     $ apt-get install python
>     Reading package lists... Done
>     Building dependency tree... Done
>     Reading state information... Done
>     Package python is not available, but is referred to by another package.
> This may mean that the package is missing, has been obsoleted, or
> is only available from another source
> However the following packages replace it:
>   2to3 python2-minimal python2 dh-python python-is-python3
>
> E: Package 'python' has no installation candidate

OK, I see.  Thanks.  I wondered if "python" redirects to either one
of these versions.  Not that I would suggest another approach based
on such a redirection, even if it existed--as I said, the question
was purely out of curiosity.
diff mbox series

Patch

diff --git a/ci/install-dependencies.sh b/ci/install-dependencies.sh
index b569893b38..d8fafc8ed2 100755
--- a/ci/install-dependencies.sh
+++ b/ci/install-dependencies.sh
@@ -15,7 +15,7 @@  case "$runs_on_pool" in
 ubuntu-*)
 	sudo apt-get -q update
 	sudo apt-get -q -y install language-pack-is libsvn-perl apache2 \
-		$UBUNTU_COMMON_PKGS $CC_PACKAGE
+		$UBUNTU_COMMON_PKGS $CC_PACKAGE $PYTHON_PACKAGE
 	mkdir --parents "$P4_PATH"
 	pushd "$P4_PATH"
 		wget --quiet "$P4WHENCE/bin.linux26x86_64/p4d"
diff --git a/ci/lib.sh b/ci/lib.sh
index 927b4529b0..cb30699f34 100755
--- a/ci/lib.sh
+++ b/ci/lib.sh
@@ -232,12 +232,12 @@  ubuntu-*)
 		break
 	fi
 
-	if [ "$jobname" = linux-gcc ]
+	PYTHON_PACKAGE=python2
+	if test "$jobname" = linux-gcc
 	then
-		MAKEFLAGS="$MAKEFLAGS PYTHON_PATH=/usr/bin/python3"
-	else
-		MAKEFLAGS="$MAKEFLAGS PYTHON_PATH=/usr/bin/python2"
+		PYTHON_PACKAGE=python3
 	fi
+	MAKEFLAGS="$MAKEFLAGS PYTHON_PATH=/usr/bin/$PYTHON_PACKAGE"
 
 	export GIT_TEST_HTTPD=true