Skip to content

feat: Allow build scripts to override package contents - #2476

Merged
wolfv merged 3 commits into
prefix-dev:mainfrom
baszalmstra:claude/custom-package-files-option-DfYkn
May 8, 2026
Merged

wolfv merged 3 commits into
prefix-dev:mainfrom
baszalmstra:claude/custom-package-files-option-DfYkn

Conversation

@baszalmstra

Copy link
Copy Markdown
Contributor

Summary

This PR adds support for build scripts to explicitly specify which files should be included in the final package by writing paths to a file pointed at by the RATTLER_BUILD_PACKAGE_FILES environment variable. This provides an alternative to the default mechanism that determines package contents by diffing the prefix against conda-meta records.

Key Changes

  • New read_package_files_list() function: Reads and parses the package files override list from disk, handling missing files and empty lines gracefully
  • New Files::from_paths() method: Constructs a Files struct from an explicit list of paths, with validation that paths exist and stay within the prefix, plus support for applying files and always_include globs on top
  • New collect_previous_files() helper: Extracted common logic for collecting previously installed files from conda-meta records
  • Build script integration:
    • Resets the package files list before running the build script to avoid stale data
    • Sets RATTLER_BUILD_PACKAGE_FILES environment variable pointing to the override file
    • Falls back to default behavior if the file is empty or missing
  • Error handling: Added PackageFileOutsidePrefix and PackageFileMissing error variants for validation
  • Documentation: Added comprehensive docs explaining the feature, including examples for both bash and batch scripts
  • Tests: Added unit tests for path reading, validation, and glob filtering, plus integration tests

Implementation Details

  • The override file is stored at .rattler-build-package-files in the build directory to avoid accidental clobbering by build scripts
  • Paths can be absolute (under $PREFIX) or relative (resolved against $PREFIX)
  • Empty lines are skipped to support shell idioms like echo path >> $RATTLER_BUILD_PACKAGE_FILES
  • The files and always_include globs still apply on top of the explicit list, allowing combined filtering
  • The feature is fully backward compatible—if the file is empty or missing, the default behavior is used

claude added 2 commits May 7, 2026 13:31
…ILD_PACKAGE_FILES

Set RATTLER_BUILD_PACKAGE_FILES to a writable file path before running the
build script. If the script writes any paths to that file, those paths are
used as the package contents instead of the default new-files-in-$PREFIX
diff. Each entry must be an absolute path under $PREFIX or a relative path
that resolves against $PREFIX. The file is appendable across invocations,
and falls back to the default behavior when empty or absent.
Rename the override file from `<build_dir>/package_files.txt` to
`<build_dir>/.rattler-build-package-files` so that build scripts dropping
files into $BUILD_DIR are extremely unlikely to clobber it by accident.
Recipes only ever interact with the file through $RATTLER_BUILD_PACKAGE_FILES,
so the rename is transparent to them.
@baszalmstra
baszalmstra requested a review from wolfv May 7, 2026 13:43
@baszalmstra baszalmstra changed the title Allow build scripts to override package contents via file list feat: Allow build scripts to override package contents May 7, 2026
- Docs: correct the description of the default file-discovery mechanism
  (conda-meta diff against $PREFIX, not a before/after snapshot of the
  build script).
- Docs + code: keep applying `build.files` and `build.always_include_files`
  globs when the override list is used, so explicit selection composes with
  the usual filtering.
- Docs + code: make paths that escape the prefix or do not exist a hard
  error instead of a silent warning. Add `PackagingError::PackageFileMissing`
  and `PackagingError::PackageFileOutsidePrefix`.
- Drop the pre-existence stat in `read_package_files_list` — read the file
  directly and treat `NotFound` as the empty case.
- Drop the pre-existence stat when clearing the override file before the
  build script runs — match on `ErrorKind::NotFound` instead.
- Tests updated to cover the new signature and error semantics.
@baszalmstra
baszalmstra force-pushed the claude/custom-package-files-option-DfYkn branch from 1845cca to a5ac3c6 Compare May 7, 2026 13:58
@baszalmstra baszalmstra mentioned this pull request May 8, 2026
2 tasks done
@wolfv
wolfv merged commit 353717b into prefix-dev:main May 8, 2026
14 checks passed
@baszalmstra
baszalmstra deleted the claude/custom-package-files-option-DfYkn branch July 8, 2026 08:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants