Skip to content

Ensure posix paths in manifest #425

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
May 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions rsconnect/bundle.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -205,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
Expand All @@ -216,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
Expand Down Expand Up @@ -296,7 +299,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]
Expand Down Expand Up @@ -355,7 +357,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):
Expand Down Expand Up @@ -543,7 +546,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)
Expand Down
79 changes: 0 additions & 79 deletions tests/test_Manifest.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import sys
import json
import os

Expand All @@ -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,
Expand All @@ -27,31 +25,13 @@ 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:
json_dict = json.load(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,
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
26 changes: 8 additions & 18 deletions tests/test_bundle.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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()
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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"
Expand All @@ -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 (
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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"
Expand All @@ -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},
},
}

Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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(
Expand Down