Example #1
0
File: nb.py Project: ydataai/kale
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:
        processor = NotebookProcessor(os.path.expanduser(source_notebook_path),
                                      skip_validation=True)
        params_source = processor.get_pipeline_parameters_source()
        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 = astutils.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
Example #2
0
 def parse_pipeline_parameters(self, source: str):
     """Get pipeline parameters from source code."""
     pipeline_parameters = astutils.parse_assignments_expressions(source)
     for name, (v_type, v_value) in pipeline_parameters.items():
         pipeline_parameters[name] = PipelineParam(v_type, v_value)
     self.pipeline.pipeline_parameters = pipeline_parameters
Example #3
0
def test_parse_assignments_expressions_exc(code):
    """Test parse_assignments_expressions function."""
    with pytest.raises(ValueError):
        kale_ast.parse_assignments_expressions(code)
Example #4
0
def test_parse_assignments_expressions(code, target):
    """Test parse_assignments_expressions function."""
    res = kale_ast.parse_assignments_expressions(code)
    compare(res, target)