Skip to content

Commit 8e9d09a

Browse files
committed
vdk-core: Add python version disparity warning
If a user has set a specific python_version in their data job's config.ini file, but they develop the data job in a python environment with a different version, the execution results may be unexpected when the job is deployed. This change adds a warning message for local data job executions, in case there is a disparity between the configured python version and the python environment that executes the job. Testing Done: Locally tested with a data job, and verified the message appears when there is a python version disparity. Signed-off-by: Andon Andonov <andonova@vmware.com>
1 parent afdff88 commit 8e9d09a

File tree

1 file changed

+58
-0
lines changed
  • projects/vdk-core/src/vdk/internal/builtin_plugins/run

1 file changed

+58
-0
lines changed

projects/vdk-core/src/vdk/internal/builtin_plugins/run/cli_run.py

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,16 @@
55
import math
66
import os
77
import pathlib
8+
import re
9+
import sys
810
from typing import cast
911
from typing import Dict
1012
from typing import List
1113
from typing import Optional
1214

1315
import click
16+
from vdk.internal.builtin_plugins.config import vdk_config
17+
from vdk.internal.builtin_plugins.config.job_config import JobConfig
1418
from vdk.internal.builtin_plugins.run import job_input_error_classifier
1519
from vdk.internal.builtin_plugins.run.data_job import DataJobFactory
1620
from vdk.internal.builtin_plugins.run.execution_tracking import (
@@ -19,6 +23,7 @@
1923
from vdk.internal.builtin_plugins.version import version
2024
from vdk.internal.core import errors
2125
from vdk.internal.core.context import CoreContext
26+
from vdk.internal.core.errors import VdkConfigurationError
2227

2328
log = logging.getLogger(__name__)
2429

@@ -66,6 +71,55 @@ def __split_into_chunks(exec_steps: List, chunks: int) -> List:
6671
+ (quotient + 1 if i < remainder else quotient)
6772
]
6873

74+
@staticmethod
75+
def __warn_on_python_version_disparity(
76+
context: CoreContext, job_directory: pathlib.Path
77+
):
78+
log_config_type = context.configuration.get_value(vdk_config.LOG_CONFIG)
79+
if log_config_type == "LOCAL":
80+
# Get the local python installation's version.
81+
python_env_version = sys.version_info
82+
local_py_version = f"{python_env_version.major}.{python_env_version.minor}"
83+
84+
# Get the python_version set in the config.ini if any.
85+
job_path = job_directory.resolve()
86+
try:
87+
config = JobConfig(data_job_path=job_path)
88+
except VdkConfigurationError as e:
89+
log.info(
90+
f"An exception occurred while loading job configuration. Error was {e}"
91+
)
92+
return
93+
configured_python_version = config.get_python_version()
94+
95+
if not configured_python_version:
96+
return
97+
98+
pattern = r"^\d+\.\d+"
99+
version_match = re.match(pattern, configured_python_version)
100+
101+
if version_match:
102+
extracted_configured_version = version_match.group()
103+
if extracted_configured_version != local_py_version:
104+
log.warning(
105+
f"""
106+
{os.linesep + (' ' * 20) + ('*' * 80)}
107+
Python version ({configured_python_version}), set in the job's config.ini file, is different
108+
from the python version ({local_py_version}) used to execute the data job.
109+
WHAT: python_version is different from the version of the execution
110+
environment.
111+
WHY: The python_version set in the data job's config.ini file is
112+
different from the python version of the execution environment.
113+
CONSEQUENCES: Developing a data job with one python version, and
114+
using a different version for the deployed data job could lead to
115+
unexpected and hard to troubleshoot errors.
116+
COUNTERMEASURES: Please, make sure that the python version set in
117+
the python_version property of the config.ini file is the same as
118+
the python version of your execution environment.
119+
{os.linesep + (' ' * 20) + ('*' * 80)}
120+
"""
121+
)
122+
69123
def create_and_run_data_job(
70124
self,
71125
context: CoreContext,
@@ -75,6 +129,10 @@ def create_and_run_data_job(
75129
log.info(f"Run job with directory {data_job_directory}")
76130
context.plugin_registry.load_plugin_with_hooks_impl(ExecutionTrackingPlugin())
77131

132+
self.__warn_on_python_version_disparity(
133+
context=context, job_directory=data_job_directory
134+
)
135+
78136
job = self.__job_factory.new_datajob(
79137
data_job_directory=data_job_directory, core_context=context
80138
)

0 commit comments

Comments
 (0)