def deploy_manifest(name, server, api_key, insecure, cacert, new, app_id, title, verbose, file): set_verbosity(verbose) with cli_feedback("Checking arguments"): connect_server = _validate_deploy_to_args(name, server, api_key, insecure, cacert) file = validate_manifest_file(file) app_store = AppStore(file) ( app_id, deployment_name, title, default_title, app_mode, package_manager, ) = gather_basic_deployment_info_from_manifest(connect_server, app_store, file, new, app_id, title) click.secho(' Deploying %s to server "%s"' % (file, connect_server.url), fg="white") if package_manager == "conda": with cli_feedback("Ensuring Conda is supported"): check_server_capabilities(connect_server, [is_conda_supported_on_server]) with cli_feedback("Creating deployment bundle"): try: bundle = make_manifest_bundle(file) except IOError as error: msg = "Unable to include the file %s in the bundle: %s" % ( error.filename, error.args[1], ) if error.args[0] == errno.ENOENT: msg = "\n".join([ msg, "Since the file is missing but referenced in the manifest, " "you will need to\nregenerate your manifest. See the help " 'for the "write-manifest" command or,\nfor non-Python ' 'content, run the "deploy other-content" command.', ]) raise api.RSConnectException(msg) _deploy_bundle( connect_server, app_store, file, app_id, app_mode, deployment_name, title, default_title, bundle, )
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, )
def test_check_server_capabilities(self): no_api_support = {"python": {"api_enabled": False}} api_support = {"python": {"api_enabled": True}} with self.assertRaises(api.RSConnectException) as context: check_server_capabilities(None, (are_apis_supported_on_server, ), lambda x: no_api_support) self.assertEqual( str(context.exception), "The RStudio Connect server does not allow for Python APIs.", ) check_server_capabilities(None, (are_apis_supported_on_server, ), lambda x: api_support) no_conda = api_support conda_not_supported = {"conda": {"supported": False}} conda_supported = {"conda": {"supported": True}} with self.assertRaises(api.RSConnectException) as context: check_server_capabilities(None, (is_conda_supported_on_server, ), lambda x: no_conda) self.assertEqual( str(context.exception), "Conda is not supported on the target server. " + "Try deploying without requesting Conda.", ) with self.assertRaises(api.RSConnectException) as context: check_server_capabilities(None, (is_conda_supported_on_server, ), lambda x: conda_not_supported) self.assertEqual( str(context.exception), "Conda is not supported on the target server. " + "Try deploying without requesting Conda.", ) check_server_capabilities(None, (is_conda_supported_on_server, ), lambda x: conda_supported) # noinspection PyUnusedLocal def fake_cap(details): return False # noinspection PyUnusedLocal def fake_cap_with_doc(details): """A docstring.""" return False with self.assertRaises(api.RSConnectException) as context: check_server_capabilities(None, (fake_cap, ), lambda x: None) self.assertEqual( str(context.exception), "The server does not satisfy the fake_cap capability check.", ) with self.assertRaises(api.RSConnectException) as context: check_server_capabilities(None, (fake_cap_with_doc, ), lambda x: None) self.assertEqual( str(context.exception), "The server does not satisfy the fake_cap_with_doc capability check.", )
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, )