Skip to content

Commit 6f929ea

Browse files
committed
feat(pipe) CWD also on pipelines
1 parent b9a196f commit 6f929ea

File tree

3 files changed

+52
-5
lines changed

3 files changed

+52
-5
lines changed

docs/source/arch.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -531,7 +531,7 @@ Architecture
531531

532532
cwd
533533
current-working-document
534-
A `jsonp` prefix of an `operation` to prefix any non-root `dependency` defined for it.
534+
A `jsonp` prefix of an `operation` (or `pipeline`) to prefix any non-root `dependency` defined.
535535

536536
pandas concatenation
537537
A `jsonp` `dependency` in `provides` may `designate <modifier>` its respective

graphtik/pipeline.py

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ def _id_tristate_bool(b):
4343

4444
def build_network(
4545
operations,
46+
cwd=None,
4647
rescheduled=None,
4748
endured=None,
4849
parallel=None,
@@ -139,6 +140,7 @@ def __init__(
139140
*,
140141
outputs=None,
141142
predicate: "NodePredicate" = None,
143+
cwd: str = None,
142144
rescheduled=None,
143145
endured=None,
144146
parallel=None,
@@ -170,6 +172,7 @@ def __init__(
170172
# Prune network
171173
self.net = build_network(
172174
operations,
175+
cwd,
173176
rescheduled,
174177
endured,
175178
parallel,
@@ -211,6 +214,7 @@ def withset(
211214
predicate: "NodePredicate" = UNSET,
212215
*,
213216
name=None,
217+
cwd=None,
214218
rescheduled=None,
215219
endured=None,
216220
parallel=None,
@@ -238,6 +242,10 @@ def withset(
238242
- if ellipses(``...``), the name of the function where this function
239243
call happened is used,
240244
- otherwise, the given `name` is applied.
245+
:param cwd:
246+
The :term:`current-working-document`, when given, all non-root `dependencies`
247+
(`needs`, `provides` & `aliases`) on all contained operations become
248+
:term:`jsonp`\\s, prefixed with this.
241249
:param rescheduled:
242250
applies :term:`reschedule`\\d to all contained `operations`
243251
:param endured:
@@ -404,9 +412,10 @@ def compute(
404412
filter-out nodes before compiling
405413
If not given, those set by a previous call to :meth:`withset()` or cstor are used.
406414
:param callbacks:
407-
If given, a 2-tuple with (optional) x2 :term:`callbacks` to call before & after
408-
each operation, with :class:`.OpTask` as argument containing the op & solution.
409-
Less or no elements accepted.
415+
If given, a 4-tuple with (optional) x2 :term:`callbacks`,
416+
2 to call before & after each operation, and another 2 before/after batch,
417+
with :class:`.OpTask` as argument containing the op & solution.
418+
One (scalar), less than 4, or no elements accepted.
410419
:param solution_class:
411420
a custom solution factory to use
412421
:param layered_solution:
@@ -535,6 +544,7 @@ def compose(
535544
*operations: Operation,
536545
excludes=None,
537546
outputs: Items = None,
547+
cwd: str = None,
538548
rescheduled=None,
539549
endured=None,
540550
parallel=None,
@@ -610,6 +620,10 @@ def compose(
610620
- :ref:`operation-nesting` for examples
611621
- Default nesting applied by :func:`.nest_any_node()`
612622
623+
:param cwd:
624+
The :term:`current-working-document`, when given, all non-root `dependencies`
625+
(`needs`, `provides` & `aliases`) on all contained operations become
626+
:term:`jsonp`\\s, prefixed with this.
613627
:param rescheduled:
614628
applies :term:`reschedule`\\d to all contained `operations`
615629
:param endured:
@@ -688,6 +702,7 @@ def nest_wrapper(ren_args: RenArgs) -> str:
688702
operations,
689703
name,
690704
outputs=outputs,
705+
cwd=cwd,
691706
rescheduled=rescheduled,
692707
endured=endured,
693708
parallel=parallel,

test/test_op.py

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,7 @@ def test_keyword_jsonp():
422422
assert sol == {"a": "ciaociao"}
423423

424424

425-
def test_cwd():
425+
def test_cwd_fnop():
426426
op = operation(
427427
str,
428428
None,
@@ -471,6 +471,38 @@ def test_cwd():
471471
assert oneliner(op) == oneliner(exp)
472472

473473

474+
def test_cwd_pipeline():
475+
op = compose(
476+
...,
477+
operation(
478+
str,
479+
None,
480+
needs=[
481+
"a",
482+
"a/b",
483+
"/r/b",
484+
],
485+
provides=["A/B", "C", "/R"],
486+
aliases=[("A/B", "aa"), ("C", "CC"), ("/R", "RR")],
487+
),
488+
cwd="/root",
489+
)
490+
exp = """
491+
Pipeline('test_cwd_pipeline',
492+
needs=['/root/a'($),
493+
'/root/a/b'($),
494+
'/r/b'($)],
495+
provides=['/root/A/B'($),
496+
'/root/C'($),
497+
'/R'($),
498+
'/root/aa'($),
499+
'/root/CC'($),
500+
'/root/RR'($)],
501+
x1 ops: str)
502+
"""
503+
assert oneliner(op) == oneliner(exp)
504+
505+
474506
@pytest.mark.parametrize(
475507
"provide, aliases, exp",
476508
[

0 commit comments

Comments
 (0)