Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Packaging] When installed with RPM, run python3.6 if available #19110

Merged
merged 3 commits into from
Aug 31, 2021

Conversation

jiasli
Copy link
Member

@jiasli jiasli commented Aug 3, 2021

Fix #18222, #15668, #13892, #13612, #13017, #11819

Symptom

When run on fedora:34, Azure CLI fails with:

$ az connectedk8s connect
ImportError: cannot import name '_psutil_linux' from partially initialized module 'psutil' (most likely due to a circular import) (/usr/lib64/az/lib/python3.6/site-packages/psutil/__init__.py)

Cause

The build pipeline uses centos:centos7

to build the RPM package, which has Python 3.6 preinstalled.

Even though azure-cli.spec only specifies python3 (not python3.6):

%define python_cmd python3

Requires: %{python_cmd}

due to the preinstalled Python 3.6 on centos:centos7, libpython3.6m.so.1.0()(64bit) is added to the RPM package's requirement:

# dnf repoquery --requires azure-cli-2.26.1
...
libpython3.6m.so.1.0()(64bit)
python3

# dnf repoquery --whatprovides "libpython3.6m.so.1.0()(64bit)"
Last metadata expiration check: 0:05:45 ago on Tue Aug  3 08:55:51 2021.
python3.6-0:3.6.13-2.fc34.x86_64
python3.6-0:3.6.14-1.fc34.x86_64

Therefore, when installing Azure CLI with

dnf install azure-cli

Python 3.6 will be installed.

However, on new Linux distributions like fedora:34, python3 by default points to python3.9.

# command -v python3
/usr/bin/python3

# stat /usr/bin/python3
  File: /usr/bin/python3 -> python3.9

The generated entry script /usr/bin/az in the RPM package is

# cat /usr/bin/az
#!/usr/bin/env bash
bin_dir=`cd "$(dirname "$BASH_SOURCE[0]")"; pwd`
AZ_INSTALLER=RPM PYTHONPATH="$bin_dir"/../lib64/az/lib/python3.6/site-packages python3 -sm azure.cli "$@"

When run on fedora:34, python3.9 is executed with python3.6-compatible so files, leading to failure.

Change

The availability of python3.6 varies on different distributions:

  • fedora:34: all python3.6, python3.9 and python3 (links to python3.9) are available
  • centos:centos7: only python3 (which is 3.6) is available

This PR dynamically decides which Python to run (python_cmd) by checking if python3.6 is available, which is the same version of Python used to build the RPM. If python3.6 exists, use it, otherwise use python3.

The entry script /usr/bin/az becomes

# cat /usr/bin/az
#!/usr/bin/env bash
bin_dir=`cd "$(dirname "$BASH_SOURCE[0]")"; pwd`
python_cmd=python3
if command -v python3.6 &>/dev/null; then python_cmd=python3.6; fi
AZ_INSTALLER=RPM PYTHONPATH="$bin_dir"/../lib64/az/lib/python3.6/site-packages $python_cmd -sm azure.cli "$@"

Notes

As Python 3.6 will be deprecated by 2021-12-23 (https://www.python.org/downloads/), we need to bump the build image to newer versions so that the RPM is build with newer versions of Python.

@jiasli jiasli requested a review from kairu-ms as a code owner August 3, 2021 15:05
@yonzhan yonzhan added this to the Aug 2021 (2021-09-07) milestone Aug 3, 2021
@yonzhan
Copy link
Collaborator

yonzhan commented Aug 3, 2021

Packaging

@jiasli jiasli merged commit 1b3dd92 into Azure:dev Aug 31, 2021
@jiasli jiasli deleted the rpm branch August 31, 2021 03:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
5 participants