Esempio n. 1
0
def test_nbadapter_repo():
    from nb2workflow.nbadapter import NotebookAdapter, find_notebooks
    from nb2workflow import ontology

    nbas = find_notebooks(test_notebook_repo)

    logger.info(ontology.service_semantic_signature(nbas))
Esempio n. 2
0
def test_nbadapter_repo():
    from nb2workflow.nbadapter import NotebookAdapter, find_notebooks

    nbas=find_notebooks(test_notebook_repo)

    assert len(nbas) == 2

    for nba_name,nba in nbas.items():
        print("notebook",nba_name)
        
        continue
        parameters=nba.extract_parameters()

        print(parameters)
        assert len(parameters)==4

        if os.path.exists(nba.output_notebook_fn):
            os.remove(nba.output_notebook_fn)

        if os.path.exists(nba.preproc_notebook_fn):
            os.remove(nba.preproc_notebook_fn)

        nba.execute(dict())

        output=nba.extract_output()

        print(output)
Esempio n. 3
0
def main():
    import argparse

    parser = argparse.ArgumentParser(description='Process some integers.')
    parser.add_argument('notebook', metavar='notebook', type=str)
    parser.add_argument('--host', metavar='host', type=str, default="127.0.0.1")
    parser.add_argument('--port', metavar='port', type=int, default=9191)
    #parser.add_argument('--tmpdir', metavar='tmpdir', type=str, default=None)
    parser.add_argument('--publish', metavar='upstream-url', type=str, default=None)
    parser.add_argument('--publish-as', metavar='published url', type=str, default=None)
    parser.add_argument('--profile', metavar='service profile', type=str, default="oda")
    parser.add_argument('--debug', action="store_true")

    args = parser.parse_args()

    if args.debug:
        logging.getLogger("nb2workflow").setLevel(level=logging.DEBUG)
        logging.getLogger("flask").setLevel(level=logging.DEBUG)

    app.notebook_adapters = find_notebooks(args.notebook)
    setup_routes(app)
    app.service_semantic_signature=ontology.service_semantic_signature(app.notebook_adapters)

    if args.publish:
        logger.info("publishing to %s",args.publish)

        if args.publish_as:
            s = args.publish_as.split(":")
            publish_host, publish_port = ":".join(s[:-1]), int(s[-1])
        else:
            publish_host, publish_port = args.host, args.port

        for nba_name, nba in app.notebook_adapters.items():
            publish.publish(args.publish, nba_name, publish_host, publish_port)


  #  for rule in app.url_map.iter_rules():
 #       logger.debug("==>> %s %s %s %s",rule,rule.endpoint,rule.__class__,rule.__dict__)

    app.run(host=args.host,port=args.port)
Esempio n. 4
0
def main():

    parser = argparse.ArgumentParser(description='Process some integers.')
    parser.add_argument('repo', metavar='repo', type=str)
    parser.add_argument('--run', action='store_true')
    parser.add_argument('--build', action='store_true')
    parser.add_argument('--job', action='store_true')
    parser.add_argument('--name', metavar='TAG', type=str, default="nb2worker")
    parser.add_argument('--from-image',
                        metavar='FROM IMAGE',
                        type=str,
                        default="python:3.6")
    parser.add_argument('--tag-image', metavar='TAG', type=str, default="")
    parser.add_argument('--host',
                        metavar='host',
                        type=str,
                        default="127.0.0.1")
    parser.add_argument('--port', metavar='port', type=int, default=9191)
    parser.add_argument('--nb2wrev', metavar='TAG', type=str, default="master")
    parser.add_argument('--nb2wpath', metavar='PATH', type=str)
    parser.add_argument('--volume', metavar='mount:mount', type=str, nargs="*")
    parser.add_argument('--docker-run-prefix', type=str, default="")
    parser.add_argument('--store-dockerfile',
                        metavar='location',
                        type=str,
                        default=None)
    parser.add_argument('--docker-command', type=str, default=None)

    args = parser.parse_args()

    repo_path = args.repo
    tag_image = args.tag_image

    if args.tag_image == "":
        tag_image = os.path.basename(os.path.abspath(repo_path))

    tempdir = prepare_image(repo_path,
                            args.from_image,
                            service=not args.job,
                            nb2w_path=args.nb2wpath,
                            runprefix=args.docker_run_prefix)

    if args.store_dockerfile:
        shutil.copy(os.path.join(tempdir, "Dockerfile"), args.store_dockerfile)
        print("stored Dockerfile as", args.store_dockerfile)

    if args.build:
        build_result = build_image(tempdir, tag_image, args.nb2wrev)

        if build_result is None:
            raise Exception("failed to build")

        print("built:", build_result)

        if args.job:

            for n, nba in find_notebooks(repo_path).items():
                nb2cwl_container(tag_image,
                                 nba.notebook_fn,
                                 n + ".cwl",
                                 command=args.docker_command)

        if args.run:
            if not args.job:
                print("running", tag_image, "service on", args.port)
                cli = docker.from_env()
                c = cli.containers.run(
                    tag_image,
                    user=os.getuid(),
                    ports={9191: (args.host, args.port)},
                    name=args.name,
                    detach=True,
                    volumes=dict([
                        (os.getcwd(), {
                            "bind": "/workdir",
                            "mode": "rw"
                        }),
                    ] + [v.split(":", 1) for v in args.volume]),
                )

                for r in c.attach(stream=True):
                    print(c, r.strip())
            else:
                print("running", tag_image)
                cli = docker.from_env()
                c = cli.containers.run(
                    tag_image,
                    user=os.getuid(),
                    name=args.name,
                    detach=True,
                    volumes=dict([
                        (os.getcwd(), {
                            "bind": "/workdir",
                            "mode": "rw"
                        }),
                    ] + [v.split(":", 1) for v in args.volume]),
                    entrypoint=["nbrun", "/repo/*ipynb"],
                )

                for r in c.attach(stream=True):
                    print(c, r.strip())