Ejemplo n.º 1
0
def main():
    args, unknown_args = parse_args()

    out_dir: Path = args.out_dir
    preexec(out_dir)
    retcode: int

    with (out_dir / "logs.txt").open("w") as stream_logs, (
            out_dir / "results.json").open("w") as results_stream:
        try:
            # check cli compatible with server - should never really fail
            if args.server_version:
                is_version_compatible(args.server_version, __version__)

            # read the config files
            # NOTE - we could supply config also by env-var or already write k8s volume in the future
            run_config = decode(args.config, compressed=True)
            setup_api(args.dp_token, args.dp_host, args.debug, stream_logs)
            res = run_api(run_config)
        except ModelRunError as e:
            ErrorResult(error=e.error,
                        error_detail=e.details).to_json(results_stream)
            retcode = 103  # NOTE - all user errors return 103
        except Exception:
            log.exception("Unhandled Exception in Model Runner")
            # we could send traceback as details, but not useful to end user
            ErrorResult(error="Unhandled Exception",
                        debug=traceback.format_exc()).to_json(results_stream)
            retcode = 104
        else:
            res.to_json(results_stream)
            retcode = 0

    sys.exit(retcode)
Ejemplo n.º 2
0
def run_api(run_config: RunnerConfig) -> RunResult:
    """Bootstrap the recursive calls into run"""
    script = api.Script.by_id(run_config.script_id)
    # is the script compatible with the client runner/api
    if not is_version_compatible(
            __version__, script.api_version, raise_exception=False):
        log.warning(
            f"Script developed for an older version of Datapane ({script.api_version}) - "
            + "this run may fail, please update.")

    # TODO - we should pull param defaults from script and add in the call
    script.call(run_config.env, **run_config.format())

    # create the RunResult
    script_result = str(api.Result.get()) if api.Result.exists() else None
    report_id = None
    try:
        report = api._report.pop()
        log.debug(f"Returning report id {report.id}")
        report_id = report.id
    except IndexError:
        log.debug(
            "User script didn't generate report - perhaps result / action only"
        )

    return RunResult(report_id=report_id, script_result=script_result)
Ejemplo n.º 3
0
def test_version():
    assert "1.1.0" == str(Version("1.1.0"))
    v.is_version_compatible(provider_v_in="0.1.0", consumer_v_in="0.1.8")
    v.is_version_compatible(provider_v_in=Version("1.1.0"),
                            consumer_v_in=Version("1.1.8"))
    # NOTE - below not supported as it's not proper semver
    # v.version_check(provider_version_s="2.1.0", client_version_s="2.0.8")
    with pytest.raises(v.VersionMismatch):
        v.is_version_compatible(provider_v_in="0.2.0", consumer_v_in="0.1.8")
    with pytest.raises(v.VersionMismatch):
        v.is_version_compatible(provider_v_in="2.1.0", consumer_v_in="1.1.0")