Fix extra_files paths for subfolder Quarto documents#762
Fix extra_files paths for subfolder Quarto documents#762anders-wiggers wants to merge 2 commits intoposit-dev:mainfrom
extra_files paths for subfolder Quarto documents#762Conversation
refactoring of extra_files to handle building bundle for deployment which done in a sub-directory.
jonkeane
left a comment
There was a problem hiding this comment.
Thank you so much for submitting a PR for this. Overall this looks ok, but would you mind also adding some tests to confirm this behavior?
I suspect using something like
rsconnect-python/tests/test_bundle.py
Lines 1018 to 1067 in 323223d
| base_dir = os.path.commonpath(abs_paths) | ||
|
|
||
| # Store paths relative to base_dir | ||
| relevant_files = [os.path.relpath(p, base_dir) for p in abs_paths] |
There was a problem hiding this comment.
Am I reading this correctly that this is using absolute paths at first then shifts them to relative paths (relative to the base_dir)? Is there a way to avoid that back and forth and just go directly to paths relative to the base_dir? It's not the end of the world if not, just seems like a bit of extra back and forth that is slightly distracting.
| manifest_add_buffer(manifest, environment.filename, environment.contents) | ||
|
|
||
| manifest_add_buffer(manifest, environment.filename, environment.contents) | ||
| for rel_path in relevant_files: | ||
| manifest_add_file(manifest, rel_path, base_dir) | ||
|
|
||
| manifest_add_file(manifest, rel_path, base_dir) |
There was a problem hiding this comment.
These are just whitespace changes, yeah?
Intent
Fix incorrect file paths in the manifest when rendering standalone Quarto documents whose
.qmdfile andextra_filesare located in a subdirectory. Previously, the subdirectory name could be duplicated when joiningbase_dirandrel_path, causing extra files to be resolved to non-existent paths (e.g.subdir/subdir/file.ext).Type of Change
Approach
For standalone Quarto documents (the
elsebranch wherefile_or_directoryis not a directory):Compute a common base directory across the main
.qmdfile and allextra_files:Convert all relevant file paths to be relative to this common
base_dir:Keep the directory-based Quarto project branch (
isdir(file_or_directory)) unchanged, still delegating to_create_quarto_file_list.This ensures:
When both the
.qmdandextra_fileslive in the same subfolder (e.g.subdir/report.qmdandsubdir/data.csv) andextra_filesis specified with the subfolder component (["subdir/data.csv"]), the manifest now uses:base_dir = <common root>rel_path = "subdir/data.csv"avoiding the duplicated
subdir/subdirpath.Extra files located outside the
.qmd’s subdirectory continue to work: the common path becomes the deepest shared parent directory, and all paths are consistently relative to that parent.Directions for Reviewers
To validate manually:
Create a structure like:
From
project-root, invoke the packaging logic with:file_or_directory="subdir/report.qmd"extra_files=["subdir/test/data.csv"]Inspect the generated manifest (or log / debug around
manifest_add_file) and verify:data.csvis added once.data.csvcontainssubdir/test/data.csv(notsubdir/subdir/test/data.csv).Checklist
rsconnect-python-tests-at-nightworkflow in Connect against this feature branch.