From acfbade0392ad46bbf53a22c2219f5557e14b03d Mon Sep 17 00:00:00 2001 From: Michael Marchetti Date: Fri, 19 May 2023 14:00:11 -0400 Subject: [PATCH 1/4] ensure posix paths in manifest --- rsconnect/bundle.py | 5 ++- tests/test_Manifest.py | 79 ------------------------------------------ 2 files changed, 2 insertions(+), 82 deletions(-) diff --git a/rsconnect/bundle.py b/rsconnect/bundle.py index b032df2c..c28241f4 100644 --- a/rsconnect/bundle.py +++ b/rsconnect/bundle.py @@ -173,7 +173,8 @@ def primary_html(self, value): self.data["metadata"]["primary_html"] = value def add_file(self, path): - self.data["files"][path] = {"checksum": file_checksum(path)} + manifestPath = Path(path).as_posix() + self.data["files"][manifestPath] = {"checksum": file_checksum(path)} return self def discard_file(self, path): @@ -296,7 +297,6 @@ def make_source_manifest( quarto_inspection: typing.Dict[str, typing.Any], image: str = None, ) -> typing.Dict[str, typing.Any]: - manifest = { "version": 1, } # type: typing.Dict[str, typing.Any] @@ -543,7 +543,6 @@ def make_notebook_source_bundle( bundle_file = tempfile.TemporaryFile(prefix="rsc_bundle") with tarfile.open(mode="w:gz", fileobj=bundle_file) as bundle: - # add the manifest first in case we want to partially untar the bundle for inspection bundle_add_buffer(bundle, "manifest.json", json.dumps(manifest, indent=2)) bundle_add_buffer(bundle, environment.filename, environment.contents) diff --git a/tests/test_Manifest.py b/tests/test_Manifest.py index 86fa5c04..9ce6d1ea 100644 --- a/tests/test_Manifest.py +++ b/tests/test_Manifest.py @@ -1,4 +1,3 @@ -import sys import json import os @@ -11,7 +10,6 @@ html_manifest_json_file = os.path.join(cur_dir, "testdata", "Manifest", "html_manifest.json") -@pytest.mark.skipif(sys.platform in ("win32", "win64"), reason="Backslash vs forward slash") def test_Manifest_from_json(): html_manifest_dict = { "version": 1, @@ -27,23 +25,6 @@ def test_Manifest_from_json(): assert m.json == manifest_json_str -@pytest.mark.skipif(sys.platform not in ("win32", "win64"), reason="Backslash vs forward slash") -def test_Manifest_from_json_Windows(): - html_manifest_dict = { - "version": 1, - "metadata": {"appmode": "static", "primary_html": "index.html", "entrypoint": "index.html"}, - "files": { - "index.html": {"checksum": "c14bd63e50295f94b761ffe9d41e3742"}, - "test1.txt": {"checksum": "3e7705498e8be60520841409ebc69bc1"}, - "test_folder1\\testfoldertext1.txt": {"checksum": "0a576fd324b6985bac6aa934131d2f5c"}, - }, - } - manifest_json_str = json.dumps(html_manifest_dict, indent=2) - m = Manifest.from_json(manifest_json_str) - assert m.json == manifest_json_str - - -@pytest.mark.skipif(sys.platform in ("win32", "win64"), reason="Backslash vs forward slash") def test_Manifest_from_json_file(): m = Manifest.from_json_file(html_manifest_json_file) with open(html_manifest_json_file) as json_file: @@ -51,7 +32,6 @@ def test_Manifest_from_json_file(): assert m.json == json.dumps(json_dict, indent=2) -@pytest.mark.skipif(sys.platform in ("win32", "win64"), reason="Backslash vs forward slash") def test_Manifest_properties(): html_manifest_dict = { "version": 1, @@ -71,27 +51,6 @@ def test_Manifest_properties(): assert list(m.data["files"].keys()) == ["index.html", "test1.txt"] -@pytest.mark.skipif(sys.platform not in ("win32", "win64"), reason="Backslash vs forward slash") -def test_Manifest_properties_Windows(): - html_manifest_dict = { - "version": 1, - "metadata": {"appmode": "static", "primary_html": "index.html", "entrypoint": "index.html"}, - "files": { - "index.html": {"checksum": "c14bd63e50295f94b761ffe9d41e3742"}, - "test1.txt": {"checksum": "3e7705498e8be60520841409ebc69bc1"}, - "test_folder1\\testfoldertext1.txt": {"checksum": "0a576fd324b6985bac6aa934131d2f5c"}, - }, - } - manifest_json_str = json.dumps(html_manifest_dict, indent=2) - m = Manifest.from_json(manifest_json_str) - assert m.primary_html == html_manifest_dict["metadata"]["primary_html"] - assert m.entrypoint == html_manifest_dict["metadata"]["entrypoint"] - - m.discard_file("test_folder1\\testfoldertext1.txt") - assert list(m.data["files"].keys()) == ["index.html", "test1.txt"] - - -@pytest.mark.skipif(sys.platform in ("win32", "win64"), reason="Backslash vs forward slash") def test_Manifest_flattened_copy(): start = { "version": 1, @@ -125,44 +84,6 @@ def test_Manifest_flattened_copy(): assert m.flattened_copy.data == html_manifest_dict -@pytest.mark.skipif(sys.platform not in ("win32", "win64"), reason="Backslash vs forward slash") -def test_Manifest_flattened_copy_Windows(): - start = { - "version": 1, - "metadata": { - "appmode": "static", - "primary_html": "tests\\testdata\\html_tests\\single_file_index\\index.html", - "entrypoint": "tests\\testdata\\html_tests\\single_file_index\\index.html", - }, - "files": { - "tests\\testdata\\html_tests\\single_file_index\\index.html": { - "checksum": "c14bd63e50295f94b761ffe9d41e3742" - }, - "tests\\testdata\\html_tests\\single_file_index\\test1.txt": { - "checksum": "3e7705498e8be60520841409ebc69bc1" - }, - "tests\\testdata\\html_tests\\single_file_index\\test_folder1\\testfoldertext1.txt": { - "checksum": "0a576fd324b6985bac6aa934131d2f5c" - }, - }, - } - start_json_str = json.dumps(start, indent=2) - m = Manifest.from_json(start_json_str) - assert m.data == start - m.entrypoint = "tests\\testdata\\html_tests\\single_file_index\\index.html" - m.deploy_dir = "tests\\testdata\\html_tests\\single_file_index" - html_manifest_dict = { - "version": 1, - "metadata": {"appmode": "static", "primary_html": "index.html", "entrypoint": "index.html"}, - "files": { - "index.html": {"checksum": "c14bd63e50295f94b761ffe9d41e3742"}, - "test1.txt": {"checksum": "3e7705498e8be60520841409ebc69bc1"}, - "test_folder1\\testfoldertext1.txt": {"checksum": "0a576fd324b6985bac6aa934131d2f5c"}, - }, - } - assert m.flattened_copy.data == html_manifest_dict - - def test_Manifest_empty_init(): init = { "version": 1, From 4f466ca5f71ba73e7511c0538c174381bfa8466c Mon Sep 17 00:00:00 2001 From: Michael Marchetti Date: Fri, 19 May 2023 14:03:02 -0400 Subject: [PATCH 2/4] posix paths in manifest_add_file --- rsconnect/bundle.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/rsconnect/bundle.py b/rsconnect/bundle.py index c28241f4..33fa593c 100644 --- a/rsconnect/bundle.py +++ b/rsconnect/bundle.py @@ -355,7 +355,8 @@ def manifest_add_file(manifest, rel_path, base_dir): path = join(base_dir, rel_path) if os.path.isdir(base_dir) else rel_path if "files" not in manifest: manifest["files"] = {} - manifest["files"][rel_path] = {"checksum": file_checksum(path)} + manifestPath = Path(rel_path).as_posix() + manifest["files"][manifestPath] = {"checksum": file_checksum(path)} def manifest_add_buffer(manifest, filename, buf): From e9793dba07cd4fa0541fc58fb6ddfe6abdb78f37 Mon Sep 17 00:00:00 2001 From: Michael Marchetti Date: Fri, 19 May 2023 14:24:34 -0400 Subject: [PATCH 3/4] more posix paths --- rsconnect/bundle.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/rsconnect/bundle.py b/rsconnect/bundle.py index 33fa593c..a3e90012 100644 --- a/rsconnect/bundle.py +++ b/rsconnect/bundle.py @@ -206,7 +206,8 @@ def flattened_data(self): deploy_dir = self.deploy_dir or deploy_dir for path in self.data["files"]: rel_path = relpath(path, deploy_dir) - new_data_files[rel_path] = self.data["files"][path] + manifestPath = Path(rel_path).as_posix() + new_data_files[manifestPath] = self.data["files"][path] return new_data_files @property @@ -217,7 +218,8 @@ def flattened_buffer(self): deploy_dir = self.deploy_dir or deploy_dir for k, v in self.buffer.items(): rel_path = relpath(k, deploy_dir) - new_buffer[rel_path] = v + manifestPath = Path(rel_path).as_posix() + new_buffer[manifestPath] = v return new_buffer @property From 8774a3daeaa79b45d5d41baa55084e3de7b10f3b Mon Sep 17 00:00:00 2001 From: Michael Marchetti Date: Fri, 19 May 2023 14:40:02 -0400 Subject: [PATCH 4/4] ensure posix paths in test cases --- tests/test_bundle.py | 26 ++++++++------------------ 1 file changed, 8 insertions(+), 18 deletions(-) diff --git a/tests/test_bundle.py b/tests/test_bundle.py index aaf2e1c5..f9b00d4d 100644 --- a/tests/test_bundle.py +++ b/tests/test_bundle.py @@ -1126,9 +1126,6 @@ def test_create_voila_manifest_multi_notebook(path, entrypoint): source="file", ) - bqplot_path = os.path.join("bqplot", "bqplot.ipynb") - dashboard_path = os.path.join("dashboard", "dashboard.ipynb") - if sys.platform == "win32": bqplot_hash = "ddb4070466d3c45b2f233dd39906ddf6" dashboard_hash = "b2d7dc369ac602c7d7a703b6eb868562" @@ -1146,8 +1143,8 @@ def test_create_voila_manifest_multi_notebook(path, entrypoint): }, "files": { "requirements.txt": {"checksum": "9cce1aac313043abd5690f67f84338ed"}, - bqplot_path: {"checksum": bqplot_hash}, - dashboard_path: {"checksum": dashboard_hash}, + "bqplot/bqplot.ipynb": {"checksum": bqplot_hash}, + "dashboard/dashboard.ipynb": {"checksum": dashboard_hash}, }, } manifest = Manifest() @@ -1182,7 +1179,7 @@ def test_create_voila_manifest_multi_notebook(path, entrypoint): image=None, multi_notebook=True, ) - assert ans == json.loads(manifest.flattened_copy.json) + assert json.loads(manifest.flattened_copy.json) == ans @pytest.mark.parametrize( @@ -1345,9 +1342,6 @@ def test_make_voila_bundle_multi_notebook( source="file", ) - bqplot_path = os.path.join("bqplot", "bqplot.ipynb") - dashboard_path = os.path.join("dashboard", "dashboard.ipynb") - if sys.platform == "win32": bqplot_hash = "ddb4070466d3c45b2f233dd39906ddf6" dashboard_hash = "b2d7dc369ac602c7d7a703b6eb868562" @@ -1365,8 +1359,8 @@ def test_make_voila_bundle_multi_notebook( }, "files": { "requirements.txt": {"checksum": "9395f3162b7779c57c86b187fa441d96"}, - bqplot_path: {"checksum": bqplot_hash}, - dashboard_path: {"checksum": dashboard_hash}, + "bqplot/bqplot.ipynb": {"checksum": bqplot_hash}, + "dashboard/dashboard.ipynb": {"checksum": dashboard_hash}, }, } if (path, entrypoint) in ( @@ -1407,7 +1401,7 @@ def test_make_voila_bundle_multi_notebook( ] reqs = tar.extractfile("requirements.txt").read() assert reqs == b"bqplot" - assert ans == json.loads(tar.extractfile("manifest.json").read().decode("utf-8")) + assert json.loads(tar.extractfile("manifest.json").read().decode("utf-8")) == ans @pytest.mark.parametrize( @@ -1575,8 +1569,6 @@ def test_create_html_manifest(): image=None, ) - test_folder_path = os.path.join("test_folder1", "testfoldertext1.txt") - if sys.platform == "win32": index_hash = "0c3d8c84223089949954d069f2eef7e9" txt_hash = "e6a96602853b20607831eec27dbb6cf0" @@ -1603,7 +1595,7 @@ def test_create_html_manifest(): "files": { "index.html": {"checksum": index_hash}, "test1.txt": {"checksum": txt_hash}, - test_folder_path: {"checksum": folder_txt_hash}, + "test_folder1/testfoldertext1.txt": {"checksum": folder_txt_hash}, }, } @@ -1712,8 +1704,6 @@ def test_create_html_manifest(): def test_make_html_bundle(): - folder_path = os.path.join("test_folder1", "testfoldertext1.txt") - if sys.platform == "win32": index_hash = "0c3d8c84223089949954d069f2eef7e9" txt_hash = "e6a96602853b20607831eec27dbb6cf0" @@ -1747,7 +1737,7 @@ def test_make_html_bundle(): "files": { "index.html": {"checksum": index_hash}, "test1.txt": {"checksum": txt_hash}, - folder_path: {"checksum": folder_txt_hash}, + "test_folder1/testfoldertext1.txt": {"checksum": folder_txt_hash}, }, } with make_html_bundle(