Skip to content

Commit 6a36b39

Browse files
authored
Merge pull request #425 from rstudio/mm-posix-paths
Ensure posix paths in manifest
2 parents 678d9d7 + 8774a3d commit 6a36b39

File tree

3 files changed

+16
-103
lines changed

3 files changed

+16
-103
lines changed

rsconnect/bundle.py

+8-6
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,8 @@ def primary_html(self, value):
173173
self.data["metadata"]["primary_html"] = value
174174

175175
def add_file(self, path):
176-
self.data["files"][path] = {"checksum": file_checksum(path)}
176+
manifestPath = Path(path).as_posix()
177+
self.data["files"][manifestPath] = {"checksum": file_checksum(path)}
177178
return self
178179

179180
def discard_file(self, path):
@@ -205,7 +206,8 @@ def flattened_data(self):
205206
deploy_dir = self.deploy_dir or deploy_dir
206207
for path in self.data["files"]:
207208
rel_path = relpath(path, deploy_dir)
208-
new_data_files[rel_path] = self.data["files"][path]
209+
manifestPath = Path(rel_path).as_posix()
210+
new_data_files[manifestPath] = self.data["files"][path]
209211
return new_data_files
210212

211213
@property
@@ -216,7 +218,8 @@ def flattened_buffer(self):
216218
deploy_dir = self.deploy_dir or deploy_dir
217219
for k, v in self.buffer.items():
218220
rel_path = relpath(k, deploy_dir)
219-
new_buffer[rel_path] = v
221+
manifestPath = Path(rel_path).as_posix()
222+
new_buffer[manifestPath] = v
220223
return new_buffer
221224

222225
@property
@@ -296,7 +299,6 @@ def make_source_manifest(
296299
quarto_inspection: typing.Dict[str, typing.Any],
297300
image: str = None,
298301
) -> typing.Dict[str, typing.Any]:
299-
300302
manifest = {
301303
"version": 1,
302304
} # type: typing.Dict[str, typing.Any]
@@ -355,7 +357,8 @@ def manifest_add_file(manifest, rel_path, base_dir):
355357
path = join(base_dir, rel_path) if os.path.isdir(base_dir) else rel_path
356358
if "files" not in manifest:
357359
manifest["files"] = {}
358-
manifest["files"][rel_path] = {"checksum": file_checksum(path)}
360+
manifestPath = Path(rel_path).as_posix()
361+
manifest["files"][manifestPath] = {"checksum": file_checksum(path)}
359362

360363

361364
def manifest_add_buffer(manifest, filename, buf):
@@ -543,7 +546,6 @@ def make_notebook_source_bundle(
543546

544547
bundle_file = tempfile.TemporaryFile(prefix="rsc_bundle")
545548
with tarfile.open(mode="w:gz", fileobj=bundle_file) as bundle:
546-
547549
# add the manifest first in case we want to partially untar the bundle for inspection
548550
bundle_add_buffer(bundle, "manifest.json", json.dumps(manifest, indent=2))
549551
bundle_add_buffer(bundle, environment.filename, environment.contents)

tests/test_Manifest.py

-79
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import sys
21
import json
32
import os
43

@@ -11,7 +10,6 @@
1110
html_manifest_json_file = os.path.join(cur_dir, "testdata", "Manifest", "html_manifest.json")
1211

1312

14-
@pytest.mark.skipif(sys.platform in ("win32", "win64"), reason="Backslash vs forward slash")
1513
def test_Manifest_from_json():
1614
html_manifest_dict = {
1715
"version": 1,
@@ -27,31 +25,13 @@ def test_Manifest_from_json():
2725
assert m.json == manifest_json_str
2826

2927

30-
@pytest.mark.skipif(sys.platform not in ("win32", "win64"), reason="Backslash vs forward slash")
31-
def test_Manifest_from_json_Windows():
32-
html_manifest_dict = {
33-
"version": 1,
34-
"metadata": {"appmode": "static", "primary_html": "index.html", "entrypoint": "index.html"},
35-
"files": {
36-
"index.html": {"checksum": "c14bd63e50295f94b761ffe9d41e3742"},
37-
"test1.txt": {"checksum": "3e7705498e8be60520841409ebc69bc1"},
38-
"test_folder1\\testfoldertext1.txt": {"checksum": "0a576fd324b6985bac6aa934131d2f5c"},
39-
},
40-
}
41-
manifest_json_str = json.dumps(html_manifest_dict, indent=2)
42-
m = Manifest.from_json(manifest_json_str)
43-
assert m.json == manifest_json_str
44-
45-
46-
@pytest.mark.skipif(sys.platform in ("win32", "win64"), reason="Backslash vs forward slash")
4728
def test_Manifest_from_json_file():
4829
m = Manifest.from_json_file(html_manifest_json_file)
4930
with open(html_manifest_json_file) as json_file:
5031
json_dict = json.load(json_file)
5132
assert m.json == json.dumps(json_dict, indent=2)
5233

5334

54-
@pytest.mark.skipif(sys.platform in ("win32", "win64"), reason="Backslash vs forward slash")
5535
def test_Manifest_properties():
5636
html_manifest_dict = {
5737
"version": 1,
@@ -71,27 +51,6 @@ def test_Manifest_properties():
7151
assert list(m.data["files"].keys()) == ["index.html", "test1.txt"]
7252

7353

74-
@pytest.mark.skipif(sys.platform not in ("win32", "win64"), reason="Backslash vs forward slash")
75-
def test_Manifest_properties_Windows():
76-
html_manifest_dict = {
77-
"version": 1,
78-
"metadata": {"appmode": "static", "primary_html": "index.html", "entrypoint": "index.html"},
79-
"files": {
80-
"index.html": {"checksum": "c14bd63e50295f94b761ffe9d41e3742"},
81-
"test1.txt": {"checksum": "3e7705498e8be60520841409ebc69bc1"},
82-
"test_folder1\\testfoldertext1.txt": {"checksum": "0a576fd324b6985bac6aa934131d2f5c"},
83-
},
84-
}
85-
manifest_json_str = json.dumps(html_manifest_dict, indent=2)
86-
m = Manifest.from_json(manifest_json_str)
87-
assert m.primary_html == html_manifest_dict["metadata"]["primary_html"]
88-
assert m.entrypoint == html_manifest_dict["metadata"]["entrypoint"]
89-
90-
m.discard_file("test_folder1\\testfoldertext1.txt")
91-
assert list(m.data["files"].keys()) == ["index.html", "test1.txt"]
92-
93-
94-
@pytest.mark.skipif(sys.platform in ("win32", "win64"), reason="Backslash vs forward slash")
9554
def test_Manifest_flattened_copy():
9655
start = {
9756
"version": 1,
@@ -125,44 +84,6 @@ def test_Manifest_flattened_copy():
12584
assert m.flattened_copy.data == html_manifest_dict
12685

12786

128-
@pytest.mark.skipif(sys.platform not in ("win32", "win64"), reason="Backslash vs forward slash")
129-
def test_Manifest_flattened_copy_Windows():
130-
start = {
131-
"version": 1,
132-
"metadata": {
133-
"appmode": "static",
134-
"primary_html": "tests\\testdata\\html_tests\\single_file_index\\index.html",
135-
"entrypoint": "tests\\testdata\\html_tests\\single_file_index\\index.html",
136-
},
137-
"files": {
138-
"tests\\testdata\\html_tests\\single_file_index\\index.html": {
139-
"checksum": "c14bd63e50295f94b761ffe9d41e3742"
140-
},
141-
"tests\\testdata\\html_tests\\single_file_index\\test1.txt": {
142-
"checksum": "3e7705498e8be60520841409ebc69bc1"
143-
},
144-
"tests\\testdata\\html_tests\\single_file_index\\test_folder1\\testfoldertext1.txt": {
145-
"checksum": "0a576fd324b6985bac6aa934131d2f5c"
146-
},
147-
},
148-
}
149-
start_json_str = json.dumps(start, indent=2)
150-
m = Manifest.from_json(start_json_str)
151-
assert m.data == start
152-
m.entrypoint = "tests\\testdata\\html_tests\\single_file_index\\index.html"
153-
m.deploy_dir = "tests\\testdata\\html_tests\\single_file_index"
154-
html_manifest_dict = {
155-
"version": 1,
156-
"metadata": {"appmode": "static", "primary_html": "index.html", "entrypoint": "index.html"},
157-
"files": {
158-
"index.html": {"checksum": "c14bd63e50295f94b761ffe9d41e3742"},
159-
"test1.txt": {"checksum": "3e7705498e8be60520841409ebc69bc1"},
160-
"test_folder1\\testfoldertext1.txt": {"checksum": "0a576fd324b6985bac6aa934131d2f5c"},
161-
},
162-
}
163-
assert m.flattened_copy.data == html_manifest_dict
164-
165-
16687
def test_Manifest_empty_init():
16788
init = {
16889
"version": 1,

tests/test_bundle.py

+8-18
Original file line numberDiff line numberDiff line change
@@ -1126,9 +1126,6 @@ def test_create_voila_manifest_multi_notebook(path, entrypoint):
11261126
source="file",
11271127
)
11281128

1129-
bqplot_path = os.path.join("bqplot", "bqplot.ipynb")
1130-
dashboard_path = os.path.join("dashboard", "dashboard.ipynb")
1131-
11321129
if sys.platform == "win32":
11331130
bqplot_hash = "ddb4070466d3c45b2f233dd39906ddf6"
11341131
dashboard_hash = "b2d7dc369ac602c7d7a703b6eb868562"
@@ -1146,8 +1143,8 @@ def test_create_voila_manifest_multi_notebook(path, entrypoint):
11461143
},
11471144
"files": {
11481145
"requirements.txt": {"checksum": "9cce1aac313043abd5690f67f84338ed"},
1149-
bqplot_path: {"checksum": bqplot_hash},
1150-
dashboard_path: {"checksum": dashboard_hash},
1146+
"bqplot/bqplot.ipynb": {"checksum": bqplot_hash},
1147+
"dashboard/dashboard.ipynb": {"checksum": dashboard_hash},
11511148
},
11521149
}
11531150
manifest = Manifest()
@@ -1182,7 +1179,7 @@ def test_create_voila_manifest_multi_notebook(path, entrypoint):
11821179
image=None,
11831180
multi_notebook=True,
11841181
)
1185-
assert ans == json.loads(manifest.flattened_copy.json)
1182+
assert json.loads(manifest.flattened_copy.json) == ans
11861183

11871184

11881185
@pytest.mark.parametrize(
@@ -1345,9 +1342,6 @@ def test_make_voila_bundle_multi_notebook(
13451342
source="file",
13461343
)
13471344

1348-
bqplot_path = os.path.join("bqplot", "bqplot.ipynb")
1349-
dashboard_path = os.path.join("dashboard", "dashboard.ipynb")
1350-
13511345
if sys.platform == "win32":
13521346
bqplot_hash = "ddb4070466d3c45b2f233dd39906ddf6"
13531347
dashboard_hash = "b2d7dc369ac602c7d7a703b6eb868562"
@@ -1365,8 +1359,8 @@ def test_make_voila_bundle_multi_notebook(
13651359
},
13661360
"files": {
13671361
"requirements.txt": {"checksum": "9395f3162b7779c57c86b187fa441d96"},
1368-
bqplot_path: {"checksum": bqplot_hash},
1369-
dashboard_path: {"checksum": dashboard_hash},
1362+
"bqplot/bqplot.ipynb": {"checksum": bqplot_hash},
1363+
"dashboard/dashboard.ipynb": {"checksum": dashboard_hash},
13701364
},
13711365
}
13721366
if (path, entrypoint) in (
@@ -1407,7 +1401,7 @@ def test_make_voila_bundle_multi_notebook(
14071401
]
14081402
reqs = tar.extractfile("requirements.txt").read()
14091403
assert reqs == b"bqplot"
1410-
assert ans == json.loads(tar.extractfile("manifest.json").read().decode("utf-8"))
1404+
assert json.loads(tar.extractfile("manifest.json").read().decode("utf-8")) == ans
14111405

14121406

14131407
@pytest.mark.parametrize(
@@ -1575,8 +1569,6 @@ def test_create_html_manifest():
15751569
image=None,
15761570
)
15771571

1578-
test_folder_path = os.path.join("test_folder1", "testfoldertext1.txt")
1579-
15801572
if sys.platform == "win32":
15811573
index_hash = "0c3d8c84223089949954d069f2eef7e9"
15821574
txt_hash = "e6a96602853b20607831eec27dbb6cf0"
@@ -1603,7 +1595,7 @@ def test_create_html_manifest():
16031595
"files": {
16041596
"index.html": {"checksum": index_hash},
16051597
"test1.txt": {"checksum": txt_hash},
1606-
test_folder_path: {"checksum": folder_txt_hash},
1598+
"test_folder1/testfoldertext1.txt": {"checksum": folder_txt_hash},
16071599
},
16081600
}
16091601

@@ -1712,8 +1704,6 @@ def test_create_html_manifest():
17121704

17131705

17141706
def test_make_html_bundle():
1715-
folder_path = os.path.join("test_folder1", "testfoldertext1.txt")
1716-
17171707
if sys.platform == "win32":
17181708
index_hash = "0c3d8c84223089949954d069f2eef7e9"
17191709
txt_hash = "e6a96602853b20607831eec27dbb6cf0"
@@ -1747,7 +1737,7 @@ def test_make_html_bundle():
17471737
"files": {
17481738
"index.html": {"checksum": index_hash},
17491739
"test1.txt": {"checksum": txt_hash},
1750-
folder_path: {"checksum": folder_txt_hash},
1740+
"test_folder1/testfoldertext1.txt": {"checksum": folder_txt_hash},
17511741
},
17521742
}
17531743
with make_html_bundle(

0 commit comments

Comments
 (0)