Skip to content

Commit 2f8703a

Browse files
committed
optional absolute paths for validate_extra_files
1 parent f5a2146 commit 2f8703a

File tree

2 files changed

+40
-7
lines changed

2 files changed

+40
-7
lines changed

rsconnect/bundle.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -843,7 +843,6 @@ def make_api_manifest(
843843
def create_html_manifest(
844844
path: str,
845845
entrypoint: str,
846-
app_mode: AppMode = AppModes.STATIC,
847846
extra_files: typing.List[str] = None,
848847
excludes: typing.List[str] = None,
849848
image: str = None,
@@ -884,7 +883,7 @@ def create_html_manifest(
884883
raise RSConnectException("No valid entrypoint found.")
885884
entrypoint = abs_entrypoint(path, entrypoint)
886885

887-
extra_files = validate_extra_files(deploy_dir, extra_files)
886+
extra_files = validate_extra_files(deploy_dir, extra_files, use_abspath=True)
888887
excludes = list(excludes) if excludes else []
889888
excludes.extend(["manifest.json"])
890889
excludes.extend(list_environment_dirs(deploy_dir))
@@ -1315,7 +1314,7 @@ def validate_file_is_notebook(file_name):
13151314
raise RSConnectException("A Jupyter notebook (.ipynb) file is required here.")
13161315

13171316

1318-
def validate_extra_files(directory, extra_files):
1317+
def validate_extra_files(directory, extra_files, use_abspath=False):
13191318
"""
13201319
If the user specified a list of extra files, validate that they all exist and are
13211320
beneath the given directory and, if so, return a list of them made relative to that
@@ -1335,6 +1334,7 @@ def validate_extra_files(directory, extra_files):
13351334
raise RSConnectException("%s must be under %s." % (extra_file, directory))
13361335
if not exists(join(directory, extra_file)):
13371336
raise RSConnectException("Could not find file %s under %s" % (extra, directory))
1337+
extra_file = abspath(join(directory, extra_file)) if use_abspath else extra_file
13381338
result.append(extra_file)
13391339
return result
13401340

tests/test_bundle.py

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -835,7 +835,7 @@ def test_guess_deploy_dir(self):
835835
self.assertEqual(abspath(bqplot_dir), guess_deploy_dir(bqplot_dir, None))
836836
self.assertEqual(abspath(bqplot_dir), guess_deploy_dir(bqplot_ipynb, None))
837837
self.assertEqual(abspath(bqplot_dir), guess_deploy_dir(bqplot_ipynb, bqplot_ipynb))
838-
self.assertEqual(abspath(bqplot_dir), guess_deploy_dir(bqplot_dir, "bqplot.ipynb"))
838+
self.assertEqual(abspath(bqplot_dir), guess_deploy_dir(bqplot_dir, bqplot_ipynb))
839839

840840

841841
@pytest.mark.parametrize(
@@ -1357,8 +1357,10 @@ def test_make_voila_bundle_2(
13571357
single_file_nonindex_dir = os.path.join(cur_dir, "./testdata/html_tests/single_file_nonindex")
13581358
multi_file_index_dir = os.path.join(cur_dir, "./testdata/html_tests/multi_file_index")
13591359
multi_file_index_file = os.path.join(cur_dir, "./testdata/html_tests/multi_file_index/index.html")
1360+
multi_file_index_file2 = os.path.join(cur_dir, "./testdata/html_tests/multi_file_index/main.html")
13601361
multi_file_nonindex_dir = os.path.join(cur_dir, "./testdata/html_tests/multi_file_nonindex")
1361-
multi_file_nonindex_file = os.path.join(cur_dir, "./testdata/html_tests/multi_file_nonindex/b.html")
1362+
multi_file_nonindex_fileb = os.path.join(cur_dir, "./testdata/html_tests/multi_file_nonindex/b.html")
1363+
multi_file_nonindex_filea = os.path.join(cur_dir, "./testdata/html_tests/multi_file_nonindex/a.html")
13621364

13631365

13641366
def test_create_html_manifest():
@@ -1460,7 +1462,7 @@ def test_create_html_manifest():
14601462
}
14611463

14621464
manifest = create_html_manifest(
1463-
multi_file_nonindex_file,
1465+
multi_file_nonindex_fileb,
14641466
None,
14651467
)
14661468
assert multi_file_nonindex_file_ans == json.loads(manifest.flattened_copy.json)
@@ -1476,6 +1478,37 @@ def test_create_html_manifest():
14761478

14771479
manifest = create_html_manifest(
14781480
multi_file_nonindex_dir,
1479-
multi_file_nonindex_file,
1481+
multi_file_nonindex_fileb,
14801482
)
14811483
assert multi_file_nonindex_dir_and_file_ans == json.loads(manifest.flattened_copy.json)
1484+
1485+
multi_file_nonindex_file_extras_ans = {
1486+
"version": 1,
1487+
"metadata": {"appmode": "static", "primary_html": "b.html", "entrypoint": "b.html"},
1488+
"files": {
1489+
"a.html": {"checksum": "c14bd63e50295f94b761ffe9d41e3742"},
1490+
"b.html": {"checksum": "c14bd63e50295f94b761ffe9d41e3742"},
1491+
},
1492+
}
1493+
manifest = create_html_manifest(
1494+
multi_file_nonindex_fileb,
1495+
None,
1496+
extra_files=[multi_file_nonindex_filea],
1497+
)
1498+
assert multi_file_nonindex_file_extras_ans == json.loads(manifest.flattened_copy.json)
1499+
1500+
multi_file_index_dir_extras_ans = {
1501+
"version": 1,
1502+
"metadata": {"appmode": "static", "primary_html": "index.html", "entrypoint": "index.html"},
1503+
"files": {
1504+
"index.html": {"checksum": "c14bd63e50295f94b761ffe9d41e3742"},
1505+
"main.html": {"checksum": "c14bd63e50295f94b761ffe9d41e3742"},
1506+
},
1507+
}
1508+
1509+
manifest = create_html_manifest(
1510+
multi_file_index_dir,
1511+
None,
1512+
extra_files=[multi_file_index_file2],
1513+
)
1514+
assert multi_file_index_dir_extras_ans == json.loads(manifest.flattened_copy.json)

0 commit comments

Comments
 (0)