55import math
66import os
77import pathlib
8+ import re
9+ import sys
810from typing import cast
911from typing import Dict
1012from typing import List
1113from typing import Optional
1214
1315import click
16+ from vdk .internal .builtin_plugins .config import vdk_config
17+ from vdk .internal .builtin_plugins .config .job_config import JobConfig
1418from vdk .internal .builtin_plugins .run import job_input_error_classifier
1519from vdk .internal .builtin_plugins .run .data_job import DataJobFactory
1620from vdk .internal .builtin_plugins .run .execution_tracking import (
1923from vdk .internal .builtin_plugins .version import version
2024from vdk .internal .core import errors
2125from vdk .internal .core .context import CoreContext
26+ from vdk .internal .core .errors import VdkConfigurationError
2227
2328log = 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