def get_pipeline_metrics(request, source_notebook_path): """Get the pipeline metrics tagged in the notebook.""" # read notebook log = request.log if hasattr(request, "log") else logger try: notebook = nbformat.read(source_notebook_path, as_version=nbformat.NO_CONVERT) metrics_source = parser.get_pipeline_metrics_source(notebook) if metrics_source == '': raise ValueError("No pipeline metrics found. Please tag a cell" " of the notebook with the `pipeline-metrics`" " tag.") # get a dict from the 'pipeline parameters' cell source code metrics = ast.parse_metrics_print_statements(metrics_source) except ValueError as e: log.exception("Failed to parse pipeline metrics") raise RPCInternalError(details=str(e), trans_id=request.trans_id) log.info("Pipeline metrics: {}".format(metrics)) return metrics
def get_pipeline_metrics(request, source_notebook_path): """Get the pipeline metrics tagged in the notebook.""" # read notebook log = request.log if hasattr(request, "log") else logger try: processor = NotebookProcessor(os.path.expanduser(source_notebook_path), skip_validation=True) metrics_source = processor.get_pipeline_metrics_source() if metrics_source == '': raise ValueError("No pipeline metrics found. Please tag a cell" " of the notebook with the `pipeline-metrics`" " tag.") # get a dict from the 'pipeline parameters' cell source code metrics = astutils.parse_metrics_print_statements(metrics_source) except ValueError as e: log.exception("Failed to parse pipeline metrics") raise RPCInternalError(details=str(e), trans_id=request.trans_id) log.info("Pipeline metrics: {}".format(metrics)) return metrics
def get_pipeline_parameters(request, source_notebook_path): """Get the pipeline parameters tagged in the notebook.""" # read notebook log = request.log if hasattr(request, "log") else logger try: notebook = nbformat.read(source_notebook_path, as_version=nbformat.NO_CONVERT) params_source = parser.get_pipeline_parameters_source(notebook) if params_source == '': raise ValueError("No pipeline parameters found. Please tag a cell" " of the notebook with the `pipeline-parameters`" " tag.") # get a dict from the 'pipeline parameters' cell source code params_dict = ast.parse_assignments_expressions(params_source) except ValueError as e: log.exception("Value Error during parsing of pipeline parameters") raise RPCInternalError(details=str(e), trans_id=request.trans_id) # convert dict in list so its easier to parse in js params = [[k, *v] for k, v in params_dict.items()] log.info("Pipeline parameters:") for ln in tabulate(params, headers=["name", "type", "value"]).split("\n"): log.info(ln) return params