From 76284ea1f84a5f31f28b60cfbbe21149fb3492fd 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 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/rsconnect/bundle.py b/rsconnect/bundle.py index ad7770fe..ac8dd7e1 100644 --- a/rsconnect/bundle.py +++ b/rsconnect/bundle.py @@ -498,7 +498,7 @@ def write_manifest( return created, skipped -def list_files(base_dir, include_sub_dirs, walk=os.walk): +def list_files(base_dir, include_sub_dirs, walk=os.walk, followlinks=True): """List the files in the directory at path. If include_sub_dirs is True, recursively list @@ -1038,7 +1038,7 @@ def create_file_list( file_set.add(path_to_add) return sorted(file_set) - for cur_dir, sub_dirs, files in os.walk(path): + for cur_dir, sub_dirs, 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 aa3a496b2319ab60f9dcfe5dfab7978018535d90 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 | 26 -------------------------- tests/test_bundle.py | 36 ------------------------------------ 2 files changed, 62 deletions(-) diff --git a/rsconnect/bundle.py b/rsconnect/bundle.py index ac8dd7e1..31209523 100644 --- a/rsconnect/bundle.py +++ b/rsconnect/bundle.py @@ -498,32 +498,6 @@ def write_manifest( return created, skipped -def list_files(base_dir, include_sub_dirs, walk=os.walk, followlinks=True): - """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 cc8f5bcd..1c977e23 100644 --- a/tests/test_bundle.py +++ b/tests/test_bundle.py @@ -20,7 +20,6 @@ create_python_environment, get_python_env_info, inspect_environment, - list_files, make_api_bundle, make_api_manifest, make_html_bundle, @@ -427,41 +426,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"))