1616
1717from databricks .labs .ucx .__about__ import __version__
1818from databricks .labs .ucx .config import GroupsConfig , MigrationConfig , TaclConfig
19- from databricks .labs .ucx .framework .tasks import _TASKS
19+ from databricks .labs .ucx .framework .tasks import _TASKS , Task
2020from databricks .labs .ucx .runtime import main
2121
2222TAG_STEP = "step"
@@ -65,6 +65,7 @@ def __init__(self, ws: WorkspaceClient, *, prefix: str = "ucx", promtps: bool =
6565 self ._ws = ws
6666 self ._prefix = prefix
6767 self ._prompts = promtps
68+ self ._this_file = Path (__file__ )
6869
6970 def run (self ):
7071 self ._configure ()
@@ -230,8 +231,7 @@ def _upload_wheel(self) -> str:
230231 self ._ws .workspace .upload (remote_wheel , f , overwrite = True , format = ImportFormat .AUTO )
231232 return remote_wheel
232233
233- def _job_settings (self , step_name , dbfs_path ):
234- config_file = f"/Workspace/{ self ._install_folder } /config.yml"
234+ def _job_settings (self , step_name : str , dbfs_path : str ):
235235 email_notifications = None
236236 if "@" in self ._my_username :
237237 email_notifications = jobs .JobEmailNotifications (
@@ -243,22 +243,44 @@ def _job_settings(self, step_name, dbfs_path):
243243 "tags" : {TAG_APP : self ._prefix , TAG_STEP : step_name },
244244 "job_clusters" : self ._job_clusters ({t .job_cluster for t in tasks }),
245245 "email_notifications" : email_notifications ,
246- "tasks" : [
247- jobs .Task (
248- task_key = task .name ,
249- job_cluster_key = task .job_cluster ,
250- depends_on = [jobs .TaskDependency (task_key = d ) for d in _TASKS [task .name ].depends_on ],
251- libraries = [compute .Library (whl = f"dbfs:{ dbfs_path } " )],
252- python_wheel_task = jobs .PythonWheelTask (
253- package_name = "databricks_labs_ucx" ,
254- entry_point = "runtime" , # [project.entry-points.databricks] in pyproject.toml
255- named_parameters = {"task" : task .name , "config" : config_file },
256- ),
257- )
258- for task in tasks
259- ],
246+ "tasks" : [self ._job_task (task , dbfs_path ) for task in tasks ],
260247 }
261248
249+ def _job_task (self , task : Task , dbfs_path : str ) -> jobs .Task :
250+ jobs_task = jobs .Task (
251+ task_key = task .name ,
252+ job_cluster_key = task .job_cluster ,
253+ depends_on = [jobs .TaskDependency (task_key = d ) for d in _TASKS [task .name ].depends_on ],
254+ )
255+ if task .notebook :
256+ return self ._job_notebook_task (jobs_task , task )
257+ return self ._job_wheel_task (jobs_task , task , dbfs_path )
258+
259+ def _job_notebook_task (self , jobs_task : jobs .Task , task : Task ) -> jobs .Task :
260+ local_notebook = self ._this_file .parent / task .notebook
261+ remote_notebook = f"{ self ._install_folder } /{ local_notebook .name } "
262+ with local_notebook .open ("rb" ) as f :
263+ self ._ws .workspace .upload (remote_notebook , f )
264+ return replace (
265+ jobs_task ,
266+ notebook_task = jobs .NotebookTask (
267+ notebook_path = remote_notebook ,
268+ # ES-872211: currently, we cannot read WSFS files from Scala context
269+ base_parameters = {"inventory_database" : self ._current_config .inventory_database },
270+ ),
271+ )
272+
273+ def _job_wheel_task (self , jobs_task : jobs .Task , task : Task , dbfs_path : str ) -> jobs .Task :
274+ return replace (
275+ jobs_task ,
276+ libraries = [compute .Library (whl = f"dbfs:{ dbfs_path } " )],
277+ python_wheel_task = jobs .PythonWheelTask (
278+ package_name = "databricks_labs_ucx" ,
279+ entry_point = "runtime" , # [project.entry-points.databricks] in pyproject.toml
280+ named_parameters = {"task" : task .name , "config" : self ._config_file },
281+ ),
282+ )
283+
262284 def _job_clusters (self , names : set [str ]):
263285 clusters = []
264286 spec = self ._cluster_node_type (
@@ -292,16 +314,15 @@ def _job_clusters(self, names: set[str]):
292314 )
293315 return clusters
294316
295- @staticmethod
296- def _build_wheel (tmp_dir : str , * , verbose : bool = False ):
317+ def _build_wheel (self , tmp_dir : str , * , verbose : bool = False ):
297318 """Helper to build the wheel package"""
298319 streams = {}
299320 if not verbose :
300321 streams = {
301322 "stdout" : subprocess .DEVNULL ,
302323 "stderr" : subprocess .DEVNULL ,
303324 }
304- project_root = Installer ._find_project_root (Path ( __file__ ) )
325+ project_root = Installer ._find_project_root (self . _this_file )
305326 if not project_root :
306327 msg = "Cannot find project root"
307328 raise NotADirectoryError (msg )
0 commit comments