Beispiel #1
0
def write_manifest_notebook(overwrite, python, conda, force_generate, verbose, file, extra_files):
    set_verbosity(verbose)
    with cli_feedback("Checking arguments"):
        validate_file_is_notebook(file)

        base_dir = dirname(file)
        extra_files = validate_extra_files(base_dir, extra_files)
        manifest_path = join(base_dir, "manifest.json")

        if exists(manifest_path) and not overwrite:
            raise api.RSConnectException("manifest.json already exists. Use --overwrite to overwrite.")

    with cli_feedback("Inspecting Python environment"):
        python, environment = get_python_env_info(file, python, conda, force_generate)

    _warn_on_ignored_conda_env(environment)

    with cli_feedback("Creating manifest.json"):
        environment_file_exists = write_notebook_manifest_json(
            file, environment, AppModes.JUPYTER_NOTEBOOK, extra_files
        )

    if environment_file_exists and not force_generate:
        click.secho(
            "    Warning: %s already exists and will not be overwritten." % environment.filename, fg="yellow",
        )
    else:
        with cli_feedback("Creating %s" % environment.filename):
            write_environment_file(environment, base_dir)
Beispiel #2
0
def _write_framework_manifest(
    overwrite,
    entrypoint,
    exclude,
    python,
    conda,
    force_generate,
    verbose,
    directory,
    extra_files,
    app_mode,
):
    """
    A common function for writing manifests for APIs as well as Dash, Streamlit, and Bokeh apps.

    :param overwrite: overwrite the manifest.json, if it exists.
    :param entrypoint: the entry point for the thing being deployed.
    :param exclude: a sequence of exclude glob patterns to exclude files from
                    the deploy.
    :param python: a path to the Python executable to use.
    :param conda: a flag to note whether Conda should be used/assumed..
    :param force_generate: a flag to force the generation of manifest and
                           requirements file.
    :param verbose: a flag to produce more (debugging) output.
    :param directory: the directory of the thing to deploy.
    :param extra_files: any extra files that should be included.
    :param app_mode: the app mode to use.
    """
    set_verbosity(verbose)

    with cli_feedback("Checking arguments"):
        entrypoint = validate_entry_point(entrypoint)
        extra_files = validate_extra_files(directory, extra_files)
        manifest_path = join(directory, "manifest.json")

        if exists(manifest_path) and not overwrite:
            raise api.RSConnectException(
                "manifest.json already exists. Use --overwrite to overwrite.")

    with cli_feedback("Inspecting Python environment"):
        _, environment = get_python_env_info(directory, python, conda,
                                             force_generate)

    _warn_on_ignored_conda_env(environment)

    with cli_feedback("Creating manifest.json"):
        environment_file_exists = write_api_manifest_json(
            directory, entrypoint, environment, app_mode, extra_files, exclude)

    if environment_file_exists and not force_generate:
        click.secho(
            "    Warning: %s already exists and will not be overwritten." %
            environment.filename,
            fg="yellow",
        )
    else:
        with cli_feedback("Creating %s" % environment.filename):
            write_environment_file(environment, directory)
Beispiel #3
0
def deploy_notebook(
    name,
    server,
    api_key,
    insecure,
    cacert,
    static,
    new,
    app_id,
    title,
    python,
    conda,
    force_generate,
    verbose,
    file,
    extra_files,
):
    set_verbosity(verbose)

    with cli_feedback("Checking arguments"):
        app_store = AppStore(file)
        connect_server = _validate_deploy_to_args(name, server, api_key, insecure, cacert)
        extra_files = validate_extra_files(dirname(file), extra_files)
        (app_id, deployment_name, title, default_title, app_mode,) = gather_basic_deployment_info_for_notebook(
            connect_server, app_store, file, new, app_id, title, static
        )

    click.secho('    Deploying %s to server "%s"' % (file, connect_server.url), fg="white")

    _warn_on_ignored_manifest(dirname(file))

    with cli_feedback("Inspecting Python environment"):
        python, environment = get_python_env_info(file, python, conda, force_generate)

    if environment.package_manager == "conda":
        with cli_feedback("Ensuring Conda is supported"):
            check_server_capabilities(connect_server, [is_conda_supported_on_server])
    else:
        _warn_on_ignored_conda_env(environment)

    if force_generate:
        _warn_on_ignored_requirements(dirname(file), environment.filename)

    with cli_feedback("Creating deployment bundle"):
        bundle = create_notebook_deployment_bundle(file, extra_files, app_mode, python, environment, False)

    _deploy_bundle(
        connect_server, app_store, file, app_id, app_mode, deployment_name, title, default_title, bundle,
    )
Beispiel #4
0
    def test_validate_extra_files(self):
        # noinspection SpellCheckingInspection
        directory = dirname(get_manifest_path("shinyapp"))

        with self.assertRaises(RSConnectException):
            validate_extra_files(directory, ["../other_dir/file.txt"])

        with self.assertRaises(RSConnectException):
            validate_extra_files(directory, ["not_a_file.txt"])

        self.assertEqual(validate_extra_files(directory, None), [])
        self.assertEqual(validate_extra_files(directory, []), [])
        self.assertEqual(
            validate_extra_files(directory, [join(directory, "index.htm")]), ["index.htm"],
        )
Beispiel #5
0
def _deploy_by_framework(
    name,
    server,
    api_key,
    insecure,
    cacert,
    entrypoint,
    exclude,
    new,
    app_id,
    title,
    python,
    conda,
    force_generate,
    verbose,
    directory,
    extra_files,
    gatherer,
):
    """
    A common function for deploying APIs, as well as Dash, Streamlit, and Bokeh apps.

    :param name: the nickname of the Connect server to use.
    :param server: the URL of the Connect server to use.
    :param api_key: the API key to use to authenticate with Connect.
    :param insecure: a flag noting whether insecure TLS should be used.
    :param cacert: a path to a CA certificates file to use with TLS.
    :param entrypoint: the entry point for the thing being deployed.
    :param exclude: a sequence of exclude glob patterns to exclude files
                    from the deploy.
    :param new: a flag to force the deploy to be new.
    :param app_id: the ID of the app to redeploy.
    :param title: the title to use for the app.
    :param python: a path to the Python executable to use.
    :param conda: a flag to note whether Conda should be used/assumed..
    :param force_generate: a flag to force the generation of manifest and
                           requirements file.
    :param verbose: a flag to produce more (debugging) output.
    :param directory: the directory of the thing to deploy.
    :param extra_files: any extra files that should be included.
    :param gatherer: the function to use to gather basic information.
    """
    set_verbosity(verbose)

    with cli_feedback("Checking arguments"):
        connect_server = _validate_deploy_to_args(name, server, api_key, insecure, cacert)
        module_file = fake_module_file_from_directory(directory)
        extra_files = validate_extra_files(directory, extra_files)
        app_store = AppStore(module_file)
        entrypoint, app_id, deployment_name, title, default_title, app_mode = gatherer(
            connect_server, app_store, directory, entrypoint, new, app_id, title
        )

    click.secho('    Deploying %s to server "%s"' % (directory, connect_server.url), fg="white")

    _warn_on_ignored_manifest(directory)

    with cli_feedback("Inspecting Python environment"):
        _, environment = get_python_env_info(module_file, python, conda, force_generate)

    with cli_feedback("Checking server capabilities"):
        checks = [are_apis_supported_on_server]
        if environment.package_manager == "conda":
            checks.append(is_conda_supported_on_server)
        check_server_capabilities(connect_server, checks)

    _warn_on_ignored_conda_env(environment)

    if force_generate:
        _warn_on_ignored_requirements(directory, environment.filename)

    with cli_feedback("Creating deployment bundle"):
        bundle = create_api_deployment_bundle(directory, extra_files, exclude, entrypoint, app_mode, environment, False)

    _deploy_bundle(
        connect_server, app_store, directory, app_id, app_mode, deployment_name, title, default_title, bundle,
    )