1- """
1+ """
22Exports a run to a directory.
33"""
44
1414from mlflow_export_import .common import MlflowExportImportException
1515from mlflow_export_import import utils , click_doc
1616
17- print ("MLflow Version:" , mlflow .version .VERSION )
18- print ("MLflow Tracking URI:" , mlflow .get_tracking_uri ())
1917
2018class RunExporter :
21- def __init__ (self , mlflow_client , export_source_tags = False , notebook_formats = None ):
19+ def __init__ (self , mlflow_client , export_source_tags = False , notebook_formats = None , host = None ):
2220 """
2321 :param mlflow_client: MLflow client.
2422 :param export_source_tags: Export source run metadata tags.
2523 :param notebook_formats: List of notebook formats to export. Values are SOURCE, HTML, JUPYTER or DBC.
24+ :param host: Pass host to the DatabricksHttpClient.
2625 """
2726 if notebook_formats is None :
2827 notebook_formats = []
2928 self .mlflow_client = mlflow_client
30- self .dbx_client = DatabricksHttpClient ()
29+ self .dbx_client = DatabricksHttpClient (host = host )
3130 print ("Databricks REST client:" , self .dbx_client )
3231 self .export_source_tags = export_source_tags
3332 self .notebook_formats = notebook_formats
@@ -38,7 +37,7 @@ def _get_metrics_with_steps(self, run):
3837 metric_history = self .mlflow_client .get_metric_history (run .info .run_id ,metric )
3938 lst = [utils .strip_underscores (m ) for m in metric_history ]
4039 for x in lst :
41- del x ["key" ]
40+ del x ["key" ]
4241 metrics_with_steps [metric ] = lst
4342 return metrics_with_steps
4443
@@ -91,8 +90,8 @@ def _export_notebook(self, output_dir, notebook, tags, fs):
9190 revision_id = tags ["mlflow.databricks.notebookRevisionID" ]
9291 notebook_path = tags ["mlflow.databricks.notebookPath" ]
9392 notebook_name = os .path .basename (notebook_path )
94- manifest = {
95- "mlflow.databricks.notebookRevisionID" : revision_id ,
93+ manifest = {
94+ "mlflow.databricks.notebookRevisionID" : revision_id ,
9695 "mlflow.databricks.notebookPath" : notebook_path ,
9796 "mlflow.databricks.export-notebook-revision" : revision_id }
9897 path = os .path .join (notebook_dir , "manifest.json" )
@@ -101,11 +100,11 @@ def _export_notebook(self, output_dir, notebook, tags, fs):
101100 self ._export_notebook_format (notebook_dir , notebook , format , format .lower (), notebook_name , revision_id )
102101
103102 def _export_notebook_format (self , notebook_dir , notebook , format , extension , notebook_name , revision_id ):
104- params = {
105- "path" : notebook ,
103+ params = {
104+ "path" : notebook ,
106105 "direct_download" : True ,
107106 "format" : format ,
108- "revision_timestamp" : revision_id
107+ "revision_timestamp" : revision_id
109108 }
110109 try :
111110 rsp = self .dbx_client ._get ("workspace/export" , params )
@@ -115,26 +114,26 @@ def _export_notebook_format(self, notebook_dir, notebook, format, extension, not
115114 print (f"WARNING: Cannot save notebook '{ notebook } '. { e } " )
116115
117116@click .command ()
118- @click .option ("--run-id" ,
119- help = "Run ID." ,
117+ @click .option ("--run-id" ,
118+ help = "Run ID." ,
120119 type = str ,
121120 required = True
122121)
123- @click .option ("--output-dir" ,
124- help = "Output directory." ,
122+ @click .option ("--output-dir" ,
123+ help = "Output directory." ,
125124 type = str ,
126125 required = True
127126)
128- @click .option ("--export-source-tags" ,
129- help = click_doc .export_source_tags ,
130- type = bool ,
131- default = False ,
127+ @click .option ("--export-source-tags" ,
128+ help = click_doc .export_source_tags ,
129+ type = bool ,
130+ default = False ,
132131 show_default = True
133132)
134- @click .option ("--notebook-formats" ,
135- help = click_doc .notebook_formats ,
133+ @click .option ("--notebook-formats" ,
134+ help = click_doc .notebook_formats ,
136135 type = str ,
137- default = "" ,
136+ default = "" ,
138137 show_default = True
139138)
140139
@@ -145,7 +144,7 @@ def main(run_id, output_dir, export_source_tags, notebook_formats):
145144 client = mlflow .tracking .MlflowClient ()
146145 exporter = RunExporter (
147146 client ,
148- export_source_tags = export_source_tags ,
147+ export_source_tags = export_source_tags ,
149148 notebook_formats = utils .string_to_list (notebook_formats ))
150149 exporter .export_run (run_id , output_dir )
151150
0 commit comments