ADX-202 Support Copying of Assets via Pipeline DSL#1040
Conversation
There was a problem hiding this comment.
Pull request overview
This PR adds asset support to Pipeline DSL-generated step directories so helper files and directories can be packaged with generated pipeline steps.
Changes:
- Adds an
assetsargument to@step(...)andStepDefinition. - Resolves, validates, and copies declared step assets into generated step version directories.
- Updates the example pipeline and tests to exercise copied helper assets and validation failures.
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
clarifai/runners/pipelines/codegen.py |
Adds asset validation and copying during step directory generation. |
clarifai/runners/pipelines/step.py |
Threads the new assets field through step definitions. |
examples/pipeline_dsl_text_pipeline.py |
Updates the example step to depend on a copied helper asset. |
examples/text_utils.py |
Adds the helper module used by the example pipeline. |
tests/cli/test_pipeline_dsl_cli.py |
Verifies CLI generation copies the example helper asset. |
tests/runners/test_pipeline_dsl.py |
Extends Pipeline DSL tests for copied assets and validation errors. |
tests/runners/sample_module.py |
Adds a helper asset used by runner tests. |
tests/runners/pipeline_step.py |
Adds a reserved-name asset fixture. |
tests/runners/invalid_reserved_asset_pipeline.py |
Adds a pipeline fixture for reserved asset-name validation. |
- Use dirs_exist_ok=True in copytree for idempotent reruns - Cache resolved assets list to avoid double resolution - Handle os.PathLike alongside str for single-asset values - Add regression test for duplicate asset basename Agent-Logs-Url: https://github.com/Clarifai/clarifai-python/sessions/d76e1973-72c2-47e6-81ef-99bd10a4e6e3 Co-authored-by: nitinbhojwani <9331380+nitinbhojwani@users.noreply.github.com>
Minimum allowed line rate is |
rizzip
left a comment
There was a problem hiding this comment.
This PR produces the intended behavior.
DevX could be better w.r.t. making use of the assets. I tested the import asset path directly and it works. The only other DevX issue I see related to this PR is upward cascading asset dependencies.
| def normalize_text(value: str) -> str: | ||
| """Small helper intentionally kept outside the step for codegen extraction.""" | ||
| return " ".join(value.strip().split()) | ||
| import importlib.util |
There was a problem hiding this comment.
This is not a clean Dev experience and introduces a dependency between this helper and any calling steps (e.g., all steps using this helper must include the text_utils asset.
Two options:
- avoid use of importlib directly, and just do
import text_utils. This is cleaner, but does not fix the cascading dependency issue - declare dependencies on this function, and have the step compiler collect assets from called functions
Why
Pipeline DSL steps can depend on local helper files or directories, but generated step directories only included the generated
pipeline_step.pyandrequirements.txt. That made asset-backed steps incomplete after generation because helper modules, text files, or directories referenced by the step were not packaged into the output. This change adds first-class asset support so generated step directories are self-contained, while also preventing assets from overwriting generated runtime files.What
assetsparameter to the@step(...)decorator andStepDefinition.pipeline_step.pyHow
clarifai.runners.pipelines.step, thread a newassetsfield through the@stepdecorator intoStepDefinition.clarifai.runners.pipelines.codegen:_resolve_step_assets(...)to normalize, validate, and deduplicate asset paths_copy_step_assets(...)to copy files withshutil.copy2(...)and directories withshutil.copytree(...)1/version directory after generatingpipeline_step.pypipeline_step.pyso user assets cannot overwrite generated runtime filesexamples/pipeline_dsl_text_pipeline.pyto load text normalization fromexamples/text_utils.pyand declare that helper as a step asset.Tests
pytest tests/runners/test_pipeline_dsl.py tests/cli/test_pipeline_dsl_cli.pypython examples/pipeline_dsl_text_pipeline.py --generate gen-copy-assets-tst-pl