Skip to content

Commit 1775b09

Browse files
authored
Merge pull request #516 from KhiopsML/515-improve-messages-unhappy-installation-paths
Improve messages and behaviour when detecting unhappy installation paths
2 parents 6e5bcb1 + 8ba7676 commit 1775b09

File tree

5 files changed

+65
-20
lines changed

5 files changed

+65
-20
lines changed

.github/workflows/tests.yml

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -445,16 +445,29 @@ jobs:
445445
fi
446446
447447
# Print status
448-
python -c \
449-
"import sys; import khiops.core as kh; return_code = kh.get_runner().print_status(); sys.exit(return_code)"
450-
RETCODE=$?
448+
PATTERN=$(python -c \
449+
"import sys; import khiops.core as kh; return_code = kh.get_runner().print_status(); sys.exit(return_code)" 2> >(grep -Ei 'with.*?unknown.*?installer') )
451450
# The installation status check will fail
452451
# because the library was not installed properly (the source code was only cloned)
453-
if [ $RETCODE -ne 0 ]; then
452+
if [ -n "$PATTERN" ]; then
454453
echo "::error::Status error: improper setup, as expected: khiops-python has been cloned, not installed from a package"
455454
fi
456455
457-
# Run integration tests on Ubuntu and Rocky
456+
# Run the library against an incompatible Khiops (with a different major version)
457+
# This instance of Khiops is isolated in a dedicated conda environment
458+
CONDA="/root/miniforge3/bin/conda"
459+
# Check an error is raised because of the major version mismatch
460+
# The khiops-python library from the cloned sources is used here
461+
PATTERN=$($CONDA run -n py3_khiops10_conda python -c "import khiops.core as kh; print(kh.get_runner().khiops_version)" 2> >(grep -Ei 'major version.*?does not match'))
462+
if [ -z "$PATTERN" ]; then
463+
echo "::error::Status error: khiops-python should fail because of the major version mismatch"
464+
if [[ "${{ matrix.container }}" == "debian13" ]]; then
465+
deactivate
466+
fi
467+
exit 1;
468+
fi
469+
470+
# Run the remaining integration tests
458471
python -m unittest -v tests.test_khiops_integrations
459472
460473
# Execute Khiops sample (train and deploy model), which uses MPI

khiops/core/internals/runner.py

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1076,30 +1076,46 @@ def _initialize_khiops_version(self):
10761076
error_msg += f"\nstderr: {stderr}" if stderr else ""
10771077
raise KhiopsRuntimeError(error_msg)
10781078

1079+
# Khiops core version
10791080
self._khiops_version = KhiopsVersion(khiops_version_str)
10801081

1081-
# Warn if the khiops version does not match the Khiops Python library version
1082-
# Note: Currently the check is very strict. It may be loosened in the future
1083-
# (major.minor.patch must be the same)
1082+
# Library version
10841083
compatible_khiops_version = khiops.get_compatible_khiops_version()
1084+
1085+
operating_system = platform.system()
1086+
installation_method = _infer_khiops_installation_method()
1087+
1088+
# Fail immediately if the major versions differ
1089+
# Note: the installation status will not show at all
1090+
if self.khiops_version.major != compatible_khiops_version.major:
1091+
raise KhiopsRuntimeError(
1092+
f"Major version '{self.khiops_version.major}' of the Khiops "
1093+
"executables does not match the Khiops Python library major version "
1094+
f"'{compatible_khiops_version.major}'. "
1095+
"To avoid any compatibility error, "
1096+
"please update either the Khiops "
1097+
f"executables package for your '{operating_system}' operating "
1098+
"system, or the Khiops Python library, "
1099+
f"according to your '{installation_method}' environment. "
1100+
"See https://khiops.org for more information.",
1101+
)
1102+
1103+
# Warn if the khiops minor and patch versions do not match
1104+
# the Khiops Python library ones
10851105
# KhiopsVersion implements the equality operator, which however also
10861106
# takes pre-release tags into account.
10871107
# The restriction here does not apply to pre-release tags
10881108
if (
1089-
self.khiops_version.major,
10901109
self.khiops_version.minor,
10911110
self.khiops_version.patch,
10921111
) != (
1093-
compatible_khiops_version.major,
10941112
compatible_khiops_version.minor,
10951113
compatible_khiops_version.patch,
10961114
):
1097-
operating_system = platform.system()
1098-
installation_method = _infer_khiops_installation_method()
10991115
warnings.warn(
11001116
f"Version '{self._khiops_version}' of the Khiops executables "
11011117
"does not match the Khiops Python library version "
1102-
f"'{khiops.__version__}' (different major.minor.patch version). "
1118+
f"'{khiops.__version__}' (different minor.patch version). "
11031119
"There may be compatibility errors and "
11041120
"we recommend to update either the Khiops "
11051121
f"executables package for your '{operating_system}' operating "
@@ -1160,8 +1176,9 @@ def _detect_library_installation_incompatibilities(self, library_root_dir):
11601176
f"Khiops Python library installation path '{library_root_dir}' "
11611177
"does not match the current Conda environment "
11621178
f"'{os.environ['CONDA_PREFIX']}'. "
1163-
"Please install the Khiops Python library "
1164-
"in the current Conda environment. "
1179+
"Either deactivate the current Conda environment "
1180+
"or use the Khiops Python library "
1181+
"belonging to the current Conda environment. "
11651182
"Go to https://khiops.org for instructions.\n"
11661183
)
11671184
error_list.append(error)
@@ -1172,7 +1189,7 @@ def _detect_library_installation_incompatibilities(self, library_root_dir):
11721189
f"Khiops binary path '{self.khiops_path}' "
11731190
"does not match the current Conda environment "
11741191
f"'{os.environ['CONDA_PREFIX']}'. "
1175-
"Please install the Khiops binary "
1192+
"We recommend installing the Khiops binary "
11761193
"in the current Conda environment. "
11771194
"Go to https://khiops.org for instructions.\n"
11781195
)

packaging/docker/khiopspydev/Dockerfile.debian

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,12 @@ RUN true \
7474
$CONDA install -y -n py${version}_conda \
7575
khiops-driver-s3==${KHIOPS_S3_DRIVER_REVISION} \
7676
khiops-driver-gcs==${KHIOPS_GCS_DRIVER_REVISION}; \
77-
done' \
77+
done; \
78+
# Install Khiops from a different major version in a dedicated conda environment \
79+
# The python interpreter version of the base environment is used as no specific version is given \
80+
$CONDA create -y -n py3_khiops10_conda; \
81+
$CONDA install -y -n py3_khiops10_conda khiops::khiops-core==10.3.1; \
82+
' \
7883
&& true
7984

8085
RUN mkdir -p /scripts

packaging/docker/khiopspydev/Dockerfile.rocky

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,13 @@ RUN true \
8787
do \
8888
$CONDA create -y -n $CONDA_ENV python=${version}; \
8989
done; \
90-
$CONDA install -y -n py${version}_conda ${RC_LABEL}khiops-core=$(echo ${KHIOPS_REVISION} | tr -d "-") ; \
91-
done' \
90+
$CONDA install -y -n py${version}_conda ${RC_LABEL}khiops-core==$(echo ${KHIOPS_REVISION} | tr -d "-") ; \
91+
done; \
92+
# Install Khiops from a different major version in a dedicated conda environment \
93+
# The python interpreter version of the base environment is used as no specific version is given \
94+
$CONDA create -y -n py3_khiops10_conda; \
95+
$CONDA install -y -n py3_khiops10_conda khiops::khiops-core==10.3.1; \
96+
' \
9297
&& true
9398

9499
RUN mkdir -p /scripts

packaging/docker/khiopspydev/Dockerfile.ubuntu

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,12 @@ RUN true \
7272
$CONDA install -y -n py${version}_conda \
7373
khiops-driver-s3==${KHIOPS_S3_DRIVER_REVISION} \
7474
khiops-driver-gcs==${KHIOPS_GCS_DRIVER_REVISION}; \
75-
done' \
75+
done; \
76+
# Install Khiops from a different major version in a dedicated conda environment \
77+
# The python interpreter version of the base environment is used as no specific version is given \
78+
$CONDA create -y -n py3_khiops10_conda; \
79+
$CONDA install -y -n py3_khiops10_conda khiops::khiops-core==10.3.1; \
80+
' \
7681
&& true
7782

7883
RUN mkdir -p /scripts

0 commit comments

Comments
 (0)