From 2bca9a9424a08febccaef48d1de2acc1cec51bf3 Mon Sep 17 00:00:00 2001 From: Aron Atkins Date: Tue, 16 Jan 2024 14:41:30 -0500 Subject: [PATCH 1/2] quarto: address inconsistencies between deprecated and live implementations fixes #534 --- CHANGELOG.md | 3 +++ rsconnect/actions.py | 14 ++------------ rsconnect/bundle.py | 20 ++++++++++++++------ 3 files changed, 19 insertions(+), 18 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index aa7930ed..7154fc76 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -27,6 +27,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 should help prevent users from getting stuck a "build already running" state. See [#467](https://github.com/rstudio/rsconnect-python/issues/467) for details. +- Addressed an error which occurred when attempting to create manifests for + Quarto documents. (#534) + ## [1.21.0] - 2023-10-26 ### Fixed diff --git a/rsconnect/actions.py b/rsconnect/actions.py index 1ae0ca11..3839212e 100644 --- a/rsconnect/actions.py +++ b/rsconnect/actions.py @@ -32,7 +32,6 @@ make_notebook_html_bundle, make_notebook_source_bundle, make_quarto_source_bundle, - make_quarto_manifest, make_source_manifest, manifest_add_buffer, manifest_add_file, @@ -518,8 +517,7 @@ def write_quarto_manifest_json( The server administrator is responsible for installing packages in the runtime environment. Default = None. """ warn("This method has been moved and will be deprecated.", DeprecationWarning, stacklevel=2) - - manifest, _ = make_quarto_manifest( + bundle.write_quarto_manifest_json( file_or_directory, inspect, app_mode, @@ -531,21 +529,13 @@ def write_quarto_manifest_json( env_management_r, ) - base_dir = file_or_directory - if not isdir(file_or_directory): - base_dir = dirname(file_or_directory) - manifest_path = join(base_dir, "manifest.json") - write_manifest_json(manifest_path, manifest) - def write_manifest_json(manifest_path, manifest): """ Write the manifest data as JSON to the named manifest.json with a trailing newline. """ warn("This method has been moved and will be deprecated.", DeprecationWarning, stacklevel=2) - with open(manifest_path, "w") as f: - json.dump(manifest, f, indent=2) - f.write("\n") + bundle.write_manifest_json(manifest_path, manifest) def deploy_html( diff --git a/rsconnect/bundle.py b/rsconnect/bundle.py index 36c19bff..ad7770fe 100644 --- a/rsconnect/bundle.py +++ b/rsconnect/bundle.py @@ -1324,7 +1324,7 @@ def make_quarto_manifest( # Standalone Quarto document base_dir = dirname(file_or_directory) file_name = basename(file_or_directory) - relevant_files = [file_name] + extra_files + relevant_files = [file_name] + list(extra_files or []) manifest = make_source_manifest( app_mode, @@ -2015,7 +2015,7 @@ def describe_manifest( def write_quarto_manifest_json( - directory: str, + file_or_directory: str, inspect: typing.Any, app_mode: AppMode, environment: Environment, @@ -2028,7 +2028,7 @@ def write_quarto_manifest_json( """ Creates and writes a manifest.json file for the given Quarto project. - :param directory: The directory containing the Quarto project. + :param file_or_directory: The Quarto document or the directory containing the Quarto project. :param inspect: The parsed JSON from a 'quarto inspect' against the project. :param app_mode: The application mode to assume (such as AppModes.STATIC_QUARTO) :param environment: The (optional) Python environment to use. @@ -2041,12 +2041,20 @@ def write_quarto_manifest_json( The server administrator is responsible for installing packages in the runtime environment. Default = None. """ - extra_files = validate_extra_files(directory, extra_files) manifest, _ = make_quarto_manifest( - directory, inspect, app_mode, environment, extra_files, excludes, image, env_management_py, env_management_r + file_or_directory, + inspect, + app_mode, + environment, + extra_files, + excludes, + image, ) - manifest_path = join(directory, "manifest.json") + base_dir = file_or_directory + if not isdir(file_or_directory): + base_dir = dirname(file_or_directory) + manifest_path = join(base_dir, "manifest.json") write_manifest_json(manifest_path, manifest) From 1d230670d26f5982cb7fec41b89e9ef9c3616f88 Mon Sep 17 00:00:00 2001 From: Aron Atkins Date: Tue, 16 Jan 2024 15:40:11 -0500 Subject: [PATCH 2/2] address (existing) lint failures --- tests/test_main_content.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/test_main_content.py b/tests/test_main_content.py index 8f380c5f..9ccb895f 100644 --- a/tests/test_main_content.py +++ b/tests/test_main_content.py @@ -19,7 +19,7 @@ # For some reason setup and teardown aren't enough to fully reset the state # between tests. Overriding the env var CONNECT_CONTENT_BUILD_DIR to be a tempdir # would be preferable but this is fine for now. -TEMP_DIR="rsconnect-build-test" +TEMP_DIR = "rsconnect-build-test" def register_uris(connect_server: str): def register_content_endpoints(i: int, guid: str): @@ -39,8 +39,8 @@ def register_content_endpoints(i: int, guid: str): httpretty.GET, f"{connect_server}/__api__/applications/{guid}/config", body='{' + - f'"config_url": "{connect_server}/connect/#/apps/{guid}",' + - f'"logs_url": "{connect_server}/connect/#/apps/{guid}"' + + f'"config_url": "{connect_server}/connect/#/apps/{guid}",' + + f'"logs_url": "{connect_server}/connect/#/apps/{guid}"' + '}', adding_headers={"Content-Type": "application/json"}, )