Skip to content

pipe node decorator#97

Merged
jucordero merged 7 commits intoFixOurFood:mainfrom
jucordero:pipe_decorator
Apr 22, 2026
Merged

pipe node decorator#97
jucordero merged 7 commits intoFixOurFood:mainfrom
jucordero:pipe_decorator

Conversation

@jucordero
Copy link
Copy Markdown
Collaborator

@jucordero jucordero commented Apr 20, 2026

Description

This PR addresses #96 by adding a decorator which converts arbitrary functions into node functions which can work inside a pipeline

Checklist

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds a pipeline_node decorator intended to wrap regular Python functions so they can be executed as pipeline nodes (reading inputs from a datablock and writing outputs back), addressing issue #96.

Changes:

  • Introduces pipeline_node decorator in pipeline.py using get_dict/set_dict datablock helpers.
  • Fixes Pipeline.add_node to avoid a mutable default argument (params={}params=None).
  • Updates pipeline tests and package exports to reflect the new decorator/import patterns.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 6 comments.

File Description
agrifoodpy/pipeline/pipeline.py Adds pipeline_node, imports get_dict/set_dict, and fixes add_node default params handling.
agrifoodpy/pipeline/tests/test_pipeline.py Adds unit tests covering pipeline_node behavior (single/multiple inputs, return key, external function, error cases) and adjusts imports.
agrifoodpy/pipeline/__init__.py Changes re-exports (drops dict_utils wildcard export; keeps pipeline exports).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread agrifoodpy/pipeline/pipeline.py Outdated
Comment thread agrifoodpy/pipeline/__init__.py
Comment thread agrifoodpy/pipeline/tests/test_pipeline.py Outdated
Comment thread agrifoodpy/pipeline/pipeline.py Outdated
Comment thread agrifoodpy/pipeline/pipeline.py Outdated
Comment on lines +355 to +359
pipeline_kwargs = dict(bound.arguments)
for key in input_keys:
pipeline_kwargs[key] = get_dict(datablock,
pipeline_kwargs[key])
result = func(**pipeline_kwargs)
Copy link

Copilot AI Apr 22, 2026

Choose a reason for hiding this comment

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

In pipeline mode the wrapper calls func(**pipeline_kwargs). This will fail for arbitrary functions that have positional-only parameters (common in builtins and some C-extension APIs), which undermines the stated goal of supporting external functions. A more robust approach is to update the existing bound.arguments values for input_keys and then invoke func(*bound.args, **bound.kwargs) so positional-only parameters are passed correctly.

Suggested change
pipeline_kwargs = dict(bound.arguments)
for key in input_keys:
pipeline_kwargs[key] = get_dict(datablock,
pipeline_kwargs[key])
result = func(**pipeline_kwargs)
for key in input_keys:
bound.arguments[key] = get_dict(datablock,
bound.arguments[key])
result = func(*bound.args, **bound.kwargs)

Copilot uses AI. Check for mistakes.
Comment thread agrifoodpy/pipeline/pipeline.py Outdated
jucordero and others added 3 commits April 22, 2026 14:20
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@jucordero jucordero merged commit 0fd7d58 into FixOurFood:main Apr 22, 2026
4 checks passed
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