Skip to content

Commit 4c19dba

Browse files
committed
Fixes from code review
1 parent 94d4019 commit 4c19dba

File tree

3 files changed

+41
-46
lines changed

3 files changed

+41
-46
lines changed

Diff for: rsconnect/bundle.py

+21-26
Original file line numberDiff line numberDiff line change
@@ -264,25 +264,25 @@ def discard_from_buffer(self, key: str):
264264
del self.data["files"][key]
265265
return self
266266

267-
def check_and_get_entrypoint(self) -> str:
267+
def require_entrypoint(self) -> str:
268268
"""
269269
If self.entrypoint is a string, return it; if it is None, raise an exception.
270270
"""
271271
if self.entrypoint is None:
272272
raise RSConnectException("A valid entrypoint must be provided.")
273273
return self.entrypoint
274274

275-
@property
276-
def flattened_data(self) -> dict[str, ManifestDataFile]:
275+
def get_manifest_files(self) -> dict[str, ManifestDataFile]:
277276
new_data_files: dict[str, ManifestDataFile] = {}
278277
deploy_dir: str
279278

280-
entrypoint = self.check_and_get_entrypoint()
279+
entrypoint = self.require_entrypoint()
281280
if self.deploy_dir is not None:
282281
deploy_dir = self.deploy_dir
283282
elif entrypoint is not None and isfile(entrypoint):
284283
deploy_dir = dirname(entrypoint)
285284
else:
285+
# TODO: This branch might be an error case. Need to investigate.
286286
deploy_dir = entrypoint
287287

288288
for path in self.data["files"]:
@@ -291,18 +291,17 @@ def flattened_data(self) -> dict[str, ManifestDataFile]:
291291
new_data_files[manifestPath] = self.data["files"][path]
292292
return new_data_files
293293

294-
@property
295-
def flattened_buffer(self) -> dict[str, str]:
294+
def get_manifest_files_from_buffer(self) -> dict[str, str]:
296295
new_buffer: dict[str, str] = {}
297-
298296
deploy_dir: str
299297

300-
entrypoint = self.check_and_get_entrypoint()
298+
entrypoint = self.require_entrypoint()
301299
if self.deploy_dir is not None:
302300
deploy_dir = self.deploy_dir
303301
elif entrypoint is not None and isfile(entrypoint):
304302
deploy_dir = dirname(entrypoint)
305303
else:
304+
# TODO: This branch might be an error case. Need to investigate.
306305
deploy_dir = entrypoint
307306

308307
for k, v in self.buffer.items():
@@ -311,26 +310,22 @@ def flattened_buffer(self) -> dict[str, str]:
311310
new_buffer[manifestPath] = v
312311
return new_buffer
313312

314-
@property
315-
def flattened_entrypoint(self) -> str:
316-
entrypoint = self.check_and_get_entrypoint()
317-
return relpath(entrypoint, dirname(entrypoint))
313+
def get_relative_entrypoint(self) -> str:
314+
entrypoint = self.require_entrypoint()
315+
return basename(entrypoint)
318316

319-
@property
320-
def flattened_primary_html(self):
317+
def get_flattened_primary_html(self):
321318
if self.primary_html is None:
322319
raise RSConnectException("A valid primary_html must be provided.")
323320
return relpath(self.primary_html, dirname(self.primary_html))
324321

325-
@property
326-
def flattened_copy(self):
327-
self.check_and_get_entrypoint()
322+
def get_flattened_copy(self):
328323
new_manifest = deepcopy(self)
329-
new_manifest.data["files"] = self.flattened_data
330-
new_manifest.buffer = self.flattened_buffer
331-
new_manifest.entrypoint = self.flattened_entrypoint
324+
new_manifest.data["files"] = self.get_manifest_files()
325+
new_manifest.buffer = self.get_manifest_files_from_buffer()
326+
new_manifest.entrypoint = self.get_relative_entrypoint()
332327
if self.primary_html:
333-
new_manifest.primary_html = self.flattened_primary_html
328+
new_manifest.primary_html = self.get_flattened_primary_html()
334329
return new_manifest
335330

336331

@@ -1087,10 +1082,10 @@ def make_html_bundle(
10871082
if f in manifest.buffer:
10881083
continue
10891084
bundle.add_file(f)
1090-
for k, v in manifest.flattened_buffer.items():
1085+
for k, v in manifest.get_manifest_files_from_buffer().items():
10911086
bundle.add_to_buffer(k, v)
10921087

1093-
manifest_flattened_copy_data = manifest.flattened_copy.data
1088+
manifest_flattened_copy_data = manifest.get_flattened_copy().data
10941089
bundle.add_to_buffer("manifest.json", json.dumps(manifest_flattened_copy_data, indent=2))
10951090

10961091
return bundle.to_file(manifest.deploy_dir)
@@ -1281,10 +1276,10 @@ def make_voila_bundle(
12811276
if f in manifest.buffer:
12821277
continue
12831278
bundle.add_file(f)
1284-
for k, v in manifest.flattened_buffer.items():
1279+
for k, v in manifest.get_manifest_files_from_buffer().items():
12851280
bundle.add_to_buffer(k, v)
12861281

1287-
manifest_flattened_copy_data = manifest.flattened_copy.data
1282+
manifest_flattened_copy_data = manifest.get_flattened_copy().data
12881283
if multi_notebook and "metadata" in manifest_flattened_copy_data:
12891284
manifest_flattened_copy_data["metadata"]["entrypoint"] = ""
12901285
bundle.add_to_buffer("manifest.json", json.dumps(manifest_flattened_copy_data, indent=2))
@@ -1993,7 +1988,7 @@ def write_voila_manifest_json(
19931988
raise RSConnectException("Voila manifest requires an entrypoint.")
19941989

19951990
deploy_dir = dirname(manifest.entrypoint) if isfile(manifest.entrypoint) else manifest.entrypoint
1996-
manifest_flattened_copy_data = manifest.flattened_copy.data
1991+
manifest_flattened_copy_data = manifest.get_flattened_copy().data
19971992
if multi_notebook and "metadata" in manifest_flattened_copy_data:
19981993
manifest_flattened_copy_data["metadata"]["entrypoint"] = ""
19991994
manifest_path = join(deploy_dir, "manifest.json")

Diff for: tests/test_Manifest.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ def test_Manifest_flattened_copy():
8181
"test_folder1/testfoldertext1.txt": {"checksum": "0a576fd324b6985bac6aa934131d2f5c"},
8282
},
8383
}
84-
assert m.flattened_copy.data == html_manifest_dict
84+
assert m.get_flattened_copy().data == html_manifest_dict
8585

8686

8787
def test_Manifest_empty_init():
@@ -97,4 +97,4 @@ def test_Manifest_empty_init():
9797
def test_Manifest_empty_exceptions():
9898
m = Manifest()
9999
with pytest.raises(RSConnectException) as _:
100-
m.check_and_get_entrypoint()
100+
m.require_entrypoint()

Diff for: tests/test_bundle.py

+18-18
Original file line numberDiff line numberDiff line change
@@ -1463,7 +1463,7 @@ def test_create_voila_manifest_1(path, entrypoint):
14631463
image=None,
14641464
multi_notebook=False,
14651465
)
1466-
assert ans == json.loads(manifest.flattened_copy.json)
1466+
assert ans == json.loads(manifest.get_flattened_copy().json)
14671467

14681468

14691469
@pytest.mark.parametrize(
@@ -1521,7 +1521,7 @@ def test_create_voila_manifest_2(path, entrypoint):
15211521
image=None,
15221522
multi_notebook=False,
15231523
)
1524-
assert ans == json.loads(manifest.flattened_copy.json)
1524+
assert ans == json.loads(manifest.get_flattened_copy().json)
15251525

15261526

15271527
def test_create_voila_manifest_extra():
@@ -1569,7 +1569,7 @@ def test_create_voila_manifest_extra():
15691569
image=None,
15701570
multi_notebook=False,
15711571
)
1572-
assert ans == json.loads(manifest.flattened_copy.json)
1572+
assert ans == json.loads(manifest.get_flattened_copy().json)
15731573

15741574

15751575
@pytest.mark.parametrize(
@@ -1671,7 +1671,7 @@ def test_create_voila_manifest_multi_notebook(path, entrypoint):
16711671
image=None,
16721672
multi_notebook=True,
16731673
)
1674-
assert json.loads(manifest.flattened_copy.json) == ans
1674+
assert json.loads(manifest.get_flattened_copy().json) == ans
16751675

16761676

16771677
@pytest.mark.parametrize(
@@ -2077,7 +2077,7 @@ def test_create_html_manifest():
20772077
extra_files=tuple(),
20782078
excludes=tuple(),
20792079
)
2080-
assert single_file_index_file_ans == json.loads(manifest.flattened_copy.json)
2080+
assert single_file_index_file_ans == json.loads(manifest.get_flattened_copy().json)
20812081

20822082
# check all runtime_environment vars
20832083
single_file_index_file_ans = {
@@ -2101,7 +2101,7 @@ def test_create_html_manifest():
21012101
env_management_py=False,
21022102
env_management_r=False,
21032103
)
2104-
assert single_file_index_file_ans == json.loads(manifest.flattened_copy.json)
2104+
assert single_file_index_file_ans == json.loads(manifest.get_flattened_copy().json)
21052105

21062106
# check image param
21072107
single_file_index_file_ans = {
@@ -2121,7 +2121,7 @@ def test_create_html_manifest():
21212121
env_management_py=None,
21222122
env_management_r=None,
21232123
)
2124-
assert single_file_index_file_ans == json.loads(manifest.flattened_copy.json)
2124+
assert single_file_index_file_ans == json.loads(manifest.get_flattened_copy().json)
21252125

21262126
# check env_management_py param
21272127
single_file_index_file_ans = {
@@ -2141,7 +2141,7 @@ def test_create_html_manifest():
21412141
excludes=tuple(),
21422142
env_management_py=False,
21432143
)
2144-
assert single_file_index_file_ans == json.loads(manifest.flattened_copy.json)
2144+
assert single_file_index_file_ans == json.loads(manifest.get_flattened_copy().json)
21452145

21462146
# check env_management_r param
21472147
single_file_index_file_ans = {
@@ -2161,7 +2161,7 @@ def test_create_html_manifest():
21612161
excludes=tuple(),
21622162
env_management_r=False,
21632163
)
2164-
assert single_file_index_file_ans == json.loads(manifest.flattened_copy.json)
2164+
assert single_file_index_file_ans == json.loads(manifest.get_flattened_copy().json)
21652165

21662166
single_file_index_dir_ans = {
21672167
"version": 1,
@@ -2179,15 +2179,15 @@ def test_create_html_manifest():
21792179
extra_files=tuple(),
21802180
excludes=tuple(),
21812181
)
2182-
assert single_file_index_dir_ans == json.loads(manifest.flattened_copy.json)
2182+
assert single_file_index_dir_ans == json.loads(manifest.get_flattened_copy().json)
21832183

21842184
manifest = create_html_manifest(
21852185
single_file_index_dir,
21862186
single_file_index_file,
21872187
extra_files=tuple(),
21882188
excludes=tuple(),
21892189
)
2190-
assert single_file_index_dir_ans == json.loads(manifest.flattened_copy.json)
2190+
assert single_file_index_dir_ans == json.loads(manifest.get_flattened_copy().json)
21912191

21922192
multi_file_index_file_ans = {
21932193
"version": 1,
@@ -2201,7 +2201,7 @@ def test_create_html_manifest():
22012201
extra_files=tuple(),
22022202
excludes=tuple(),
22032203
)
2204-
assert multi_file_index_file_ans == json.loads(manifest.flattened_copy.json)
2204+
assert multi_file_index_file_ans == json.loads(manifest.get_flattened_copy().json)
22052205

22062206
multi_file_index_dir_ans = {
22072207
"version": 1,
@@ -2218,15 +2218,15 @@ def test_create_html_manifest():
22182218
extra_files=tuple(),
22192219
excludes=tuple(),
22202220
)
2221-
assert multi_file_index_dir_ans == json.loads(manifest.flattened_copy.json)
2221+
assert multi_file_index_dir_ans == json.loads(manifest.get_flattened_copy().json)
22222222

22232223
manifest = create_html_manifest(
22242224
multi_file_index_dir,
22252225
multi_file_index_file,
22262226
extra_files=tuple(),
22272227
excludes=tuple(),
22282228
)
2229-
assert multi_file_index_dir_ans == json.loads(manifest.flattened_copy.json)
2229+
assert multi_file_index_dir_ans == json.loads(manifest.get_flattened_copy().json)
22302230

22312231
multi_file_nonindex_file_ans = {
22322232
"version": 1,
@@ -2240,7 +2240,7 @@ def test_create_html_manifest():
22402240
extra_files=tuple(),
22412241
excludes=tuple(),
22422242
)
2243-
assert multi_file_nonindex_file_ans == json.loads(manifest.flattened_copy.json)
2243+
assert multi_file_nonindex_file_ans == json.loads(manifest.get_flattened_copy().json)
22442244

22452245
multi_file_nonindex_dir_and_file_ans = {
22462246
"version": 1,
@@ -2257,7 +2257,7 @@ def test_create_html_manifest():
22572257
extra_files=tuple(),
22582258
excludes=tuple(),
22592259
)
2260-
assert multi_file_nonindex_dir_and_file_ans == json.loads(manifest.flattened_copy.json)
2260+
assert multi_file_nonindex_dir_and_file_ans == json.loads(manifest.get_flattened_copy().json)
22612261

22622262
multi_file_nonindex_file_extras_ans = {
22632263
"version": 1,
@@ -2273,7 +2273,7 @@ def test_create_html_manifest():
22732273
extra_files=[multi_file_nonindex_filea],
22742274
excludes=tuple(),
22752275
)
2276-
assert multi_file_nonindex_file_extras_ans == json.loads(manifest.flattened_copy.json)
2276+
assert multi_file_nonindex_file_extras_ans == json.loads(manifest.get_flattened_copy().json)
22772277

22782278
multi_file_index_dir_extras_ans = {
22792279
"version": 1,
@@ -2290,7 +2290,7 @@ def test_create_html_manifest():
22902290
extra_files=[multi_file_index_file2],
22912291
excludes=tuple(),
22922292
)
2293-
assert multi_file_index_dir_extras_ans == json.loads(manifest.flattened_copy.json)
2293+
assert multi_file_index_dir_extras_ans == json.loads(manifest.get_flattened_copy().json)
22942294

22952295

22962296
def test_make_html_bundle():

0 commit comments

Comments
 (0)