From 8dfbbc089e22b76ccaa8919c96f6c9d265ba1963 Mon Sep 17 00:00:00 2001 From: Joe Cheng Date: Thu, 22 Feb 2024 10:32:19 -0800 Subject: [PATCH 1/2] Follow symlinks when building bundle --- rsconnect/bundle.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/rsconnect/bundle.py b/rsconnect/bundle.py index 00ef2bde..c948ff3d 100644 --- a/rsconnect/bundle.py +++ b/rsconnect/bundle.py @@ -578,6 +578,7 @@ def list_files( base_dir: str, include_sub_dirs: bool, walk: Callable[[str], Iterator[tuple[str, list[str], list[str]]]] = os.walk, + followlinks: bool = True, ) -> list[str]: """List the files in the directory at path. @@ -1259,7 +1260,7 @@ def create_file_list( file_set.add(path_to_add) return sorted(file_set) - for cur_dir, _, files in os.walk(path): + for cur_dir, _, files in os.walk(path, followlinks=True): if Path(cur_dir) in exclude_paths: continue if any(parent in exclude_paths for parent in Path(cur_dir).parents): From 272241f3ef79ea9644bd3d316ea44a54ff029cb6 Mon Sep 17 00:00:00 2001 From: Joe Cheng Date: Thu, 22 Feb 2024 14:23:12 -0800 Subject: [PATCH 2/2] Remove unused list_files function --- rsconnect/bundle.py | 31 ------------------------------- tests/test_bundle.py | 36 ------------------------------------ 2 files changed, 67 deletions(-) diff --git a/rsconnect/bundle.py b/rsconnect/bundle.py index c948ff3d..47ff1b8f 100644 --- a/rsconnect/bundle.py +++ b/rsconnect/bundle.py @@ -574,37 +574,6 @@ def write_manifest( return created, skipped -def list_files( - base_dir: str, - include_sub_dirs: bool, - walk: Callable[[str], Iterator[tuple[str, list[str], list[str]]]] = os.walk, - followlinks: bool = True, -) -> list[str]: - """List the files in the directory at path. - - If include_sub_dirs is True, recursively list - files in subdirectories. - - Returns an iterable of file paths relative to base_dir. - """ - skip_dirs = [".ipynb_checkpoints", ".git"] - - def iter_files(): - for root, sub_dirs, files in walk(base_dir): - if include_sub_dirs: - for skip in skip_dirs: - if skip in sub_dirs: - sub_dirs.remove(skip) - else: - # tell walk not to traverse any subdirectories - sub_dirs[:] = [] - - for filename in files: - yield relpath(join(root, filename), base_dir) - - return list(iter_files()) - - def make_notebook_source_bundle( file: str, environment: Environment, diff --git a/tests/test_bundle.py b/tests/test_bundle.py index d6aa5d4b..9acd6a64 100644 --- a/tests/test_bundle.py +++ b/tests/test_bundle.py @@ -20,7 +20,6 @@ get_default_node_entrypoint, guess_deploy_dir, keep_manifest_specified_file, - list_files, make_api_bundle, make_api_manifest, make_html_bundle, @@ -686,41 +685,6 @@ def test_make_quarto_source_bundle_from_file(self): }, ) - def test_list_files(self): - # noinspection SpellCheckingInspection - paths = [ - "notebook.ipynb", - "somedata.csv", - os.path.join("subdir", "subfile"), - os.path.join("subdir2", "subfile2"), - os.path.join(".ipynb_checkpoints", "notebook.ipynb"), - os.path.join(".git", "config"), - ] - - def walk(base_dir): - dir_names = [] - file_names = [] - - for path in paths: - if os.sep in path: - dir_name, file_name = path.split(os.sep, 1) - dir_names.append(dir_name) - else: - file_names.append(path) - - yield base_dir, dir_names, file_names - - for subdir in dir_names: - for path in paths: - if path.startswith(subdir + os.sep): - yield base_dir + os.sep + subdir, [], [path.split(os.sep, 1)[1]] - - files = list_files(".", True, walk=walk) - self.assertEqual(files, paths[:4]) - - files = list_files(os.sep, False, walk=walk) - self.assertEqual(files, paths[:2]) - def test_html_bundle1(self): self.do_test_html_bundle(get_dir("pip1"))