Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/tangle-cli/src/tangle_cli/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@
try:
__version__ = metadata_version("tangle-cli")
except PackageNotFoundError:
__version__ = "0.1.37"
__version__ = "0.1.38"

__all__ = ["TangleDynamicDiscoveryClient", "__version__"]
26 changes: 21 additions & 5 deletions packages/tangle-cli/src/tangle_cli/pipeline_compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -1144,7 +1144,9 @@ def _process_subpipeline_children(
ambient_context=ambient_passthrough or None,
config_identity=child_identity,
task_annotations=child_task_annotations,
own_task_annotations=_own_task_annotations_for_key(child_fn, child_doc, effective),
own_task_annotations=_own_task_annotations_for_key(
child_fn, child_doc, effective, base_dir=child_base_dir, ctx=ctx
),
)

# Cycle detection (covers self-reference). active_stack holds the
Expand Down Expand Up @@ -1526,20 +1528,34 @@ def _own_task_annotations_for_key(
pipeline_fn: PipelineFn,
doc: CfgDocument | None,
overrides: Mapping[str, Any],
*,
base_dir: Path,
ctx: CompileContext,
) -> dict[str, Any]:
"""A child's own ``@pipeline(task_annotations=...)`` as its trace applies
them, for its compile key.

A function is resolved against the cfg :func:`_resolve_cfg_for_pipeline`
builds for the child (its config plus ``overrides``). Without a config
file it contributes nothing: the child's own compile then fails on the
missing file.
builds for the child (its config plus ``overrides``), under the import
setup :func:`_compile_pipeline_fn` traces the child with (``base_dir``
recorded for the after-compile purge, shadowing modules evicted, and
``base_dir`` on ``sys.path``), so a function importing a sibling of the
child resolves it as it does in the trace. Without a config file it
contributes nothing: the child's own compile then fails on the missing
file.
"""
if not callable(pipeline_fn.task_annotations):
return _own_task_annotations(pipeline_fn, None)
if doc is None:
return {}
return _own_task_annotations(pipeline_fn, build_cfg(doc.data, overrides=dict(overrides), coerce=False))
cfg = build_cfg(doc.data, overrides=dict(overrides), coerce=False)
try:
ctx.source_dirs.add(base_dir.resolve())
except OSError: # pragma: no cover — defensive
pass
_evict_shadowed_bundle_modules(base_dir)
with _temp_sys_path(base_dir):
return _own_task_annotations(pipeline_fn, cfg)


def _validate_artifact(artifact: SubgraphArtifact, ctx: CompileContext) -> None:
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "tangle-cli"
version = "0.1.37"
version = "0.1.38"
description = "CLI for Tangle, the open-source ML pipeline orchestration platform"
readme = "README.md"
authors = [
Expand Down
2 changes: 1 addition & 1 deletion tests/test_packaging.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ def test_tangle_cli_wheel_supports_expert_no_deps_import_path_without_tangle_api
requires_dist = [line for line in metadata.splitlines() if line.startswith("Requires-Dist: ")]
assert not any(name.startswith("tangle_api/") for name in names)
assert "tangle_cli/openapi/openapi.json" not in names
assert "Version: 0.1.37" in metadata
assert "Version: 0.1.38" in metadata
assert "Requires-Dist: tangle-api==0.1.1" in requires_dist
assert not any("extra == 'native'" in line for line in requires_dist)
assert "Provides-Extra: native" in metadata
Expand Down
47 changes: 47 additions & 0 deletions tests/test_task_annotation_defaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,53 @@ def root():
assert _annotations(_child(out, "First"), "Child Task") == {"team": "left"}


def test_a_child_defaults_function_imports_siblings_of_the_child(tmp_path):
src = tmp_path / "src"
child_dir = src / "child"
child_dir.mkdir(parents=True)
(child_dir / "child_annotation_helper.py").write_text(
"def annotations_for(cfg):\n return {'team': 'helper-' + cfg.team}\n", encoding="utf-8"
)
(child_dir / "config.yaml").write_text("team: child\n", encoding="utf-8")
(child_dir / "child_pipeline.py").write_text(
_HEADER
+ textwrap.dedent(
"""
def defaults(cfg):
from child_annotation_helper import annotations_for

return annotations_for(cfg)

@pipeline("Child", task_annotations=defaults)
def child():
op.named("Child Task")()
"""
),
encoding="utf-8",
)
(src / "pipeline.py").write_text(
_HEADER
+ textwrap.dedent(
"""
from child.child_pipeline import child

@pipeline("Root")
def root():
subpipeline(child).named("Run Child")()
"""
),
encoding="utf-8",
)
nested = tmp_path / "nested" / "compiled.yaml"
direct = tmp_path / "direct" / "compiled.yaml"

compile_pipeline(src / "pipeline.py", nested, None, pipeline_name="Root")
compile_pipeline(child_dir / "child_pipeline.py", direct, None, pipeline_name="Child")

assert _annotations(_child(nested, "Run Child"), "Child Task") == {"team": "helper-child"}
assert _annotations(direct, "Child Task") == {"team": "helper-child"}


@pytest.mark.parametrize("declared", ['"davies"', 'lambda cfg: "davies"'])
def test_pipeline_defaults_that_are_not_a_mapping_fail_the_compile(tmp_path, declared):
with pytest.raises(CompileError, match=r"'Root'.*must be a mapping or a function of cfg returning one, got str"):
Expand Down
2 changes: 1 addition & 1 deletion uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading