@@ -74,6 +74,31 @@ def run(self):
7474 if self ._run :
7575 mlflow .end_run ()
7676
77+ def _identify_runtime_version (self ) -> Optional [int ]:
78+ command = """
79+ import os
80+ print(os.environ.get("DATABRICKS_RUNTIME_VERSION"))
81+ """
82+ _version_string = self ._client .client .execute_command (command , verbose = False )
83+ _clean_string = None if _version_string == "None" else _version_string
84+ if not _clean_string :
85+ return None
86+ else :
87+ try :
88+ _version = int (_clean_string .split ("." )[0 ])
89+ return _version
90+ except ValueError :
91+ dbx_echo ("🚨 Cannot identify the DBR version, package may not be updated" )
92+ return None
93+
94+ def _refresh_python_if_necessary (self ):
95+ _version = self ._identify_runtime_version ()
96+ if _version and _version >= 13 :
97+ dbx_echo ("🔄 Restarting Python to reflect the changes in environment" )
98+ refresh_command = "dbutils.library.restartPython()"
99+ self ._client .client .execute_command (refresh_command , verbose = False )
100+ dbx_echo ("✅ Restarting Python to reflect the changes in environment - done" )
101+
77102 def install_requirements_file (self ):
78103 if not self ._requirements_file .exists ():
79104 raise Exception (f"Requirements file provided, but doesn't exist at path { self ._requirements_file } " )
@@ -84,6 +109,7 @@ def install_requirements_file(self):
84109 )
85110 installation_command = f"%pip install -U -r { localized_requirements_path } "
86111 self ._client .client .execute_command (installation_command , verbose = False )
112+ self ._refresh_python_if_necessary ()
87113 dbx_echo ("Provided requirements installed" )
88114
89115 def install_package (self , pip_install_extras : Optional [str ]):
@@ -97,6 +123,7 @@ def install_package(self, pip_install_extras: Optional[str]):
97123 with Console ().status ("Installing package on the cluster 📦" , spinner = "dots" ):
98124 self ._client .install_package (localized_package_path , pip_install_extras )
99125
126+ self ._refresh_python_if_necessary ()
100127 dbx_echo (":white_check_mark: Installing package - done" )
101128
102129 def preprocess_task_parameters (self , parameters : Union [List [str ], Dict [str , str ]]):
0 commit comments