Skip to content

Commit 9264a4b

Browse files
authored
Add version check for k8s setup venv command (#36673)
This command install airflow in k8s venv and in case version of Python is not yet supported by Airflow, it might fail. We do not have check it lower-bound because breeze supports the same minimum version of Airflow as Airflow itself. The command prints instructions on how to reinstall breeze with different Python version in such case.
1 parent 1f6d764 commit 9264a4b

File tree

1 file changed

+27
-1
lines changed

1 file changed

+27
-1
lines changed

dev/breeze/src/airflow_breeze/utils/kubernetes_utils.py

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,13 @@
3232
from typing import Any, NamedTuple
3333
from urllib import request
3434

35-
from airflow_breeze.global_constants import ALLOWED_ARCHITECTURES, HELM_VERSION, KIND_VERSION, PIP_VERSION
35+
from airflow_breeze.global_constants import (
36+
ALLOWED_ARCHITECTURES,
37+
ALLOWED_PYTHON_MAJOR_MINOR_VERSIONS,
38+
HELM_VERSION,
39+
KIND_VERSION,
40+
PIP_VERSION,
41+
)
3642
from airflow_breeze.utils.console import Output, get_console
3743
from airflow_breeze.utils.host_info_utils import Architecture, get_host_architecture, get_host_os
3844
from airflow_breeze.utils.path_utils import AIRFLOW_SOURCES_ROOT, BUILD_CACHE_DIR
@@ -330,6 +336,26 @@ def create_virtualenv(force_venv_setup: bool) -> RunCommandResult:
330336
get_console().print(f"[info]Dry run - would be removing {K8S_ENV_PATH}")
331337
else:
332338
shutil.rmtree(K8S_ENV_PATH, ignore_errors=True)
339+
max_python_version = ALLOWED_PYTHON_MAJOR_MINOR_VERSIONS[-1]
340+
max_python_version_tuple = tuple(int(x) for x in max_python_version.split("."))
341+
higher_python_version_tuple = max_python_version_tuple[0], max_python_version_tuple[1] + 1
342+
if sys.version_info >= higher_python_version_tuple:
343+
get_console().print(
344+
f"[red]This is not supported in Python {higher_python_version_tuple} and above[/]\n"
345+
)
346+
get_console().print(f"[warning]Please use Python version before {higher_python_version_tuple}[/]\n")
347+
get_console().print(
348+
"[info]You can uninstall breeze and install it again with earlier Python "
349+
"version. For example:[/]\n"
350+
)
351+
get_console().print("pipx uninstall apache-airflow-breeze")
352+
get_console().print("pipx install --python PYTHON_PATH -e ./dev/breeze\n")
353+
get_console().print(
354+
f"[info]PYTHON_PATH - path to your Python binary(< {higher_python_version_tuple})[/]\n"
355+
)
356+
get_console().print("[info]Then recreate your k8s virtualenv with:[/]\n")
357+
get_console().print("breeze k8s setup-env --force-venv-setup\n")
358+
sys.exit(1)
333359
venv_command_result = run_command(
334360
[sys.executable, "-m", "venv", str(K8S_ENV_PATH)],
335361
check=False,

0 commit comments

Comments
 (0)