This is an automated email from the ASF dual-hosted git repository.

taragolis pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/airflow.git


The following commit(s) were added to refs/heads/main by this push:
     new db884a64db Use sys.version_info to get the python version (#37750)
db884a64db is described below

commit db884a64db99476170d64023aee814ad199b5a67
Author: Joan Karadimov <[email protected]>
AuthorDate: Sat Mar 2 11:29:57 2024 +0200

    Use sys.version_info to get the python version (#37750)
    
    * Use sys.version_info to get the python version
    
    Previously either 'sys.version_info' or 'python --version' is used.
    The latter can fail on certain Python distributions (e.g. Conda).
    
    * Apply update-inlined-dockerfile-scripts hook
    
    ---------
    
    Co-authored-by: Joan Karadimov <[email protected]>
    Co-authored-by: Andrey Anshin <[email protected]>
---
 Dockerfile                        | 4 ++--
 Dockerfile.ci                     | 2 +-
 scripts/docker/common.sh          | 2 +-
 scripts/docker/entrypoint_prod.sh | 2 +-
 4 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/Dockerfile b/Dockerfile
index 292e0a9ed1..1e75319200 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -555,7 +555,7 @@ function common::get_constraints_location() {
     if [[ -z ${AIRFLOW_CONSTRAINTS_LOCATION=} ]]; then
         local 
constraints_base="https://raw.githubusercontent.com/${CONSTRAINTS_GITHUB_REPOSITORY}/${AIRFLOW_CONSTRAINTS_REFERENCE}";
         local python_version
-        python_version="$(python --version 2>/dev/stdout | cut -d " " -f 2 | 
cut -d "." -f 1-2)"
+        python_version=$(python -c 'import sys; 
print(f"{sys.version_info.major}.{sys.version_info.minor}")')
         
AIRFLOW_CONSTRAINTS_LOCATION="${constraints_base}/${AIRFLOW_CONSTRAINTS_MODE}-${python_version}.txt"
     fi
 }
@@ -1076,7 +1076,7 @@ function set_pythonpath_for_root_user() {
     # Now also adds applications installed as local user "airflow".
     if [[ $UID == "0" ]]; then
         local python_major_minor
-        python_major_minor="$(python --version | cut -d " " -f 2 | cut -d "." 
-f 1-2)"
+        python_major_minor=$(python -c 'import sys; 
print(f"{sys.version_info.major}.{sys.version_info.minor}")')
         export 
PYTHONPATH="${AIRFLOW_USER_HOME_DIR}/.local/lib/python${python_major_minor}/site-packages:${PYTHONPATH:-}"
         >&2 echo "The container is run as root user. For security, consider 
using a regular user account."
     fi
diff --git a/Dockerfile.ci b/Dockerfile.ci
index d7f01464da..15475969a7 100644
--- a/Dockerfile.ci
+++ b/Dockerfile.ci
@@ -513,7 +513,7 @@ function common::get_constraints_location() {
     if [[ -z ${AIRFLOW_CONSTRAINTS_LOCATION=} ]]; then
         local 
constraints_base="https://raw.githubusercontent.com/${CONSTRAINTS_GITHUB_REPOSITORY}/${AIRFLOW_CONSTRAINTS_REFERENCE}";
         local python_version
-        python_version="$(python --version 2>/dev/stdout | cut -d " " -f 2 | 
cut -d "." -f 1-2)"
+        python_version=$(python -c 'import sys; 
print(f"{sys.version_info.major}.{sys.version_info.minor}")')
         
AIRFLOW_CONSTRAINTS_LOCATION="${constraints_base}/${AIRFLOW_CONSTRAINTS_MODE}-${python_version}.txt"
     fi
 }
diff --git a/scripts/docker/common.sh b/scripts/docker/common.sh
index 29da11bac7..b39a139799 100644
--- a/scripts/docker/common.sh
+++ b/scripts/docker/common.sh
@@ -92,7 +92,7 @@ function common::get_constraints_location() {
     if [[ -z ${AIRFLOW_CONSTRAINTS_LOCATION=} ]]; then
         local 
constraints_base="https://raw.githubusercontent.com/${CONSTRAINTS_GITHUB_REPOSITORY}/${AIRFLOW_CONSTRAINTS_REFERENCE}";
         local python_version
-        python_version="$(python --version 2>/dev/stdout | cut -d " " -f 2 | 
cut -d "." -f 1-2)"
+        python_version=$(python -c 'import sys; 
print(f"{sys.version_info.major}.{sys.version_info.minor}")')
         
AIRFLOW_CONSTRAINTS_LOCATION="${constraints_base}/${AIRFLOW_CONSTRAINTS_MODE}-${python_version}.txt"
     fi
 }
diff --git a/scripts/docker/entrypoint_prod.sh 
b/scripts/docker/entrypoint_prod.sh
index add3ab7ec9..fe7b0109d8 100755
--- a/scripts/docker/entrypoint_prod.sh
+++ b/scripts/docker/entrypoint_prod.sh
@@ -184,7 +184,7 @@ function set_pythonpath_for_root_user() {
     # Now also adds applications installed as local user "airflow".
     if [[ $UID == "0" ]]; then
         local python_major_minor
-        python_major_minor="$(python --version | cut -d " " -f 2 | cut -d "." 
-f 1-2)"
+        python_major_minor=$(python -c 'import sys; 
print(f"{sys.version_info.major}.{sys.version_info.minor}")')
         export 
PYTHONPATH="${AIRFLOW_USER_HOME_DIR}/.local/lib/python${python_major_minor}/site-packages:${PYTHONPATH:-}"
         >&2 echo "The container is run as root user. For security, consider 
using a regular user account."
     fi

Reply via email to