Skip to content

Allow FlowDecorators, FlowMutators and StepMutators to add_to_package#3082

Open
romain-intel wants to merge 5 commits intomasterfrom
romain/worktree/add_files
Open

Allow FlowDecorators, FlowMutators and StepMutators to add_to_package#3082
romain-intel wants to merge 5 commits intomasterfrom
romain/worktree/add_files

Conversation

@romain-intel
Copy link
Copy Markdown
Contributor

This provides an easier way to build things that can modify what gets packaged with the .tar.gz that gets sent remotely to execute

PR Type

  • Bug fix
  • [ X] New feature
  • Core Runtime change (higher bar -- see CONTRIBUTING.md)
  • Docs / tooling
  • Refactoring

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented Apr 3, 2026

Greptile Summary

This PR extends FlowDecorator, FlowMutator, and StepMutator with an add_to_package() hook, allowing them to contribute files to the .tar.gz code package sent to remote executors. A new USER_CONTENT content type is introduced for files that should be packaged alongside user flow code (with walker-level deduplication), and an example package_suffixes mutator is included to demonstrate the feature.

Confidence Score: 5/5

Safe to merge — only P2 style/hygiene findings, no correctness issues.

All core logic is sound: USER_CONTENT dedup is handled correctly across _check_tuple/_add_tuple/_user_code_tuples, StepMutator dedup uses id() safely while objects are live, and the phase-init move in cli.py is idempotent thanks to the _ran_init guard. Only two P2 issues found: an incomplete debug.py comment and package_suffixes_mutator omitting exclude_tl_dirs from its walk() call.

metaflow/plugins/package_suffixes_mutator.py — walk() call omits exclude_tl_dirs

Important Files Changed

Filename Overview
metaflow/cli.py Moves phase init and flow-mutator external_init() earlier (before _process_config_decorators) so the phase is available to mutators; removes the now-redundant later phase assignment.
metaflow/debug.py Adds prefix-length trimming for long Bazel-style file paths in debug output; has a minor incomplete comment (P2).
metaflow/package/init.py Implements _add_addl_files: adds FlowDecorator/FlowMutator/StepMutator hooks, introduces USER_CONTENT handling via _user_content_from_addl, and merges those files into _user_code_tuples. Logic is correct; USER_CONTENT intentionally falls through _add_tuple (well-commented).
metaflow/plugins/package_suffixes_mutator.py New example FlowMutator that adds extra file suffixes to the package; walk() call omits exclude_tl_dirs (P2).
metaflow/user_decorators/user_flow_decorator.py Adds add_to_package() stub with detailed docstring to FlowMutator; clean addition.
metaflow/user_decorators/user_step_decorator.py Adds add_to_package() stub with detailed docstring to StepMutator; clean addition.
test/unit/test_add_to_package.py Comprehensive unit tests covering all decorator types, USER_CONTENT dedup, walker merge, and integration scenarios.
test/unit/test_package_suffixes_mutator.py Unit tests for package_suffixes mutator covering init forms, suffix matching, and empty-suffix early exit.

Reviews (7): Last reviewed commit: "Address comment" | Re-trigger Greptile

Comment thread metaflow/decorators.py
@romain-intel romain-intel force-pushed the romain/worktree/add_files branch 2 times, most recently from 0612694 to bb7d386 Compare April 14, 2026 19:17
@romain-intel
Copy link
Copy Markdown
Contributor Author

Add a PR on top to implement the package suffixes addition using this and flowmutator.

@romain-intel romain-intel force-pushed the romain/worktree/add_files branch from bb7d386 to 311e744 Compare April 23, 2026 19:27
Comment thread metaflow/user_decorators/user_flow_decorator.py Outdated
Comment thread metaflow/cli.py
Comment on lines +478 to +481
# Initialize the phase early so it can be used in the mutators
# The phase is determined by which CLI subcommand is being invoked (e.g. "run" → LAUNCH,
# "step" → TASK, "batch" → TRAMPOLINE).
system_context._update(phase=_phase_from_cli_args(getattr(ctx, "saved_args", None)))
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what would this change when you moved it up?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can now use the phase in the external_init of mutators (for example)

This provides an easier way to build things that can modify what
gets packaged with the .tar.gz that gets sent remotely to
execute
USER_CONTENT tuples produced by FlowDecorator/StepDecorator/
FlowMutator/StepMutator add_to_package hooks were previously dropped
on the floor. They are now recorded per-arcname and merged into the
packaged user code: files already yielded by the flow-directory walker
are skipped (dedup), and anything outside the flow dir or filtered out
by the suffix/user filter still makes it into the package.

Also add an example `@package_suffixes` FlowMutator that declares
additional file suffixes to include in the package — mirroring the
`--package-suffixes` CLI option as a decorator and demonstrating the
new USER_CONTENT merging behavior.
@romain-intel romain-intel force-pushed the romain/worktree/add_files branch from 66d46f0 to 2ef9783 Compare April 28, 2026 00:06
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.

2 participants