@@ -71,16 +71,30 @@ def produces(objects: PyTree[Any]) -> PyTree[Any]:
71
71
return objects
72
72
73
73
74
- def parse_nodes (
75
- session : Session , path : Path , name : str , obj : Any , parser : Callable [..., Any ]
74
+ def parse_nodes ( # noqa: PLR0913
75
+ session : Session ,
76
+ task_path : Path ,
77
+ task_name : str ,
78
+ node_path : Path ,
79
+ obj : Any ,
80
+ parser : Callable [..., Any ],
76
81
) -> Any :
77
82
"""Parse nodes from object."""
78
83
arg_name = parser .__name__
79
84
objects = _extract_nodes_from_function_markers (obj , parser )
80
85
nodes = _convert_objects_to_node_dictionary (objects , arg_name )
81
86
return tree_map (
82
87
lambda x : _collect_decorator_node (
83
- session , path , name , NodeInfo (arg_name , (), x )
88
+ session ,
89
+ node_path ,
90
+ task_name ,
91
+ NodeInfo (
92
+ arg_name = arg_name ,
93
+ path = (),
94
+ value = x ,
95
+ task_path = task_path ,
96
+ task_name = task_name ,
97
+ ),
84
98
),
85
99
nodes ,
86
100
)
@@ -226,7 +240,7 @@ def _merge_dictionaries(list_of_dicts: list[dict[Any, Any]]) -> dict[Any, Any]:
226
240
227
241
228
242
def parse_dependencies_from_task_function (
229
- session : Session , path : Path , name : str , obj : Any
243
+ session : Session , task_path : Path , task_name : str , node_path : Path , obj : Any
230
244
) -> dict [str , Any ]:
231
245
"""Parse dependencies from task function."""
232
246
has_depends_on_decorator = False
@@ -235,7 +249,7 @@ def parse_dependencies_from_task_function(
235
249
236
250
if has_mark (obj , "depends_on" ):
237
251
has_depends_on_decorator = True
238
- nodes = parse_nodes (session , path , name , obj , depends_on )
252
+ nodes = parse_nodes (session , task_path , task_name , node_path , obj , depends_on )
239
253
dependencies ["depends_on" ] = nodes
240
254
241
255
task_kwargs = obj .pytask_meta .kwargs if hasattr (obj , "pytask_meta" ) else {}
@@ -248,7 +262,16 @@ def parse_dependencies_from_task_function(
248
262
has_depends_on_argument = True
249
263
dependencies ["depends_on" ] = tree_map (
250
264
lambda x : _collect_decorator_node (
251
- session , path , name , NodeInfo (arg_name = "depends_on" , path = (), value = x )
265
+ session ,
266
+ node_path ,
267
+ task_name ,
268
+ NodeInfo (
269
+ arg_name = "depends_on" ,
270
+ path = (),
271
+ value = x ,
272
+ task_path = task_path ,
273
+ task_name = task_name ,
274
+ ),
252
275
),
253
276
kwargs ["depends_on" ],
254
277
)
@@ -284,9 +307,15 @@ def parse_dependencies_from_task_function(
284
307
nodes = tree_map_with_path (
285
308
lambda p , x : _collect_dependency (
286
309
session ,
287
- path ,
288
- name ,
289
- NodeInfo (parameter_name , p , x ), # noqa: B023
310
+ node_path ,
311
+ task_name ,
312
+ NodeInfo (
313
+ arg_name = parameter_name , # noqa: B023
314
+ path = p ,
315
+ value = x ,
316
+ task_path = task_path ,
317
+ task_name = task_name ,
318
+ ),
290
319
),
291
320
value ,
292
321
)
@@ -297,7 +326,10 @@ def parse_dependencies_from_task_function(
297
326
isinstance (x , PythonNode ) and not x .hash for x in tree_leaves (nodes )
298
327
)
299
328
if not isinstance (nodes , PNode ) and are_all_nodes_python_nodes_without_hash :
300
- dependencies [parameter_name ] = PythonNode (value = value , name = parameter_name )
329
+ prefix = task_path .as_posix () + "::" + task_name if task_path else task_name
330
+ node_name = prefix + "::" + parameter_name
331
+
332
+ dependencies [parameter_name ] = PythonNode (value = value , name = node_name )
301
333
else :
302
334
dependencies [parameter_name ] = nodes
303
335
return dependencies
@@ -352,7 +384,7 @@ def task_example(produces: Annotated[..., Product]):
352
384
353
385
354
386
def parse_products_from_task_function (
355
- session : Session , path : Path , name : str , obj : Any
387
+ session : Session , task_path : Path , task_name : str , node_path : Path , obj : Any
356
388
) -> dict [str , Any ]:
357
389
"""Parse products from task function.
358
390
@@ -372,7 +404,7 @@ def parse_products_from_task_function(
372
404
# Parse products from decorators.
373
405
if has_mark (obj , "produces" ):
374
406
has_produces_decorator = True
375
- nodes = parse_nodes (session , path , name , obj , produces )
407
+ nodes = parse_nodes (session , task_path , task_name , node_path , obj , produces )
376
408
out = {"produces" : nodes }
377
409
378
410
task_kwargs = obj .pytask_meta .kwargs if hasattr (obj , "pytask_meta" ) else {}
@@ -388,9 +420,15 @@ def parse_products_from_task_function(
388
420
collected_products = tree_map_with_path (
389
421
lambda p , x : _collect_product (
390
422
session ,
391
- path ,
392
- name ,
393
- NodeInfo (arg_name = "produces" , path = p , value = x ),
423
+ node_path ,
424
+ task_name ,
425
+ NodeInfo (
426
+ arg_name = "produces" ,
427
+ path = p ,
428
+ value = x ,
429
+ task_path = task_path ,
430
+ task_name = task_name ,
431
+ ),
394
432
is_string_allowed = True ,
395
433
),
396
434
kwargs ["produces" ],
@@ -412,8 +450,8 @@ def parse_products_from_task_function(
412
450
and parameter_name in parameters_with_node_annot
413
451
):
414
452
msg = (
415
- f"The value for the parameter { name !r} is defined twice in "
416
- "'@pytask.mark.task(kwargs=...)' and in the type annotation. "
453
+ f"The value for the parameter { parameter_name !r} is defined twice "
454
+ "in '@pytask.mark.task(kwargs=...)' and in the type annotation. "
417
455
"Choose only one option."
418
456
)
419
457
raise ValueError (msg )
@@ -425,9 +463,15 @@ def parse_products_from_task_function(
425
463
collected_products = tree_map_with_path (
426
464
lambda p , x : _collect_product (
427
465
session ,
428
- path ,
429
- name ,
430
- NodeInfo (parameter_name , p , x ), # noqa: B023
466
+ node_path ,
467
+ task_name ,
468
+ NodeInfo (
469
+ arg_name = parameter_name , # noqa: B023
470
+ path = p ,
471
+ value = x ,
472
+ task_path = task_path ,
473
+ task_name = task_name ,
474
+ ),
431
475
is_string_allowed = False ,
432
476
),
433
477
value ,
@@ -439,9 +483,15 @@ def parse_products_from_task_function(
439
483
collected_products = tree_map_with_path (
440
484
lambda p , x : _collect_product (
441
485
session ,
442
- path ,
443
- name ,
444
- NodeInfo ("return" , p , x ),
486
+ node_path ,
487
+ task_name ,
488
+ NodeInfo (
489
+ arg_name = "return" ,
490
+ path = p ,
491
+ value = x ,
492
+ task_path = task_path ,
493
+ task_name = task_name ,
494
+ ),
445
495
is_string_allowed = False ,
446
496
),
447
497
parameters_with_node_annot ["return" ],
@@ -454,9 +504,15 @@ def parse_products_from_task_function(
454
504
collected_products = tree_map_with_path (
455
505
lambda p , x : _collect_product (
456
506
session ,
457
- path ,
458
- name ,
459
- NodeInfo ("return" , p , x ),
507
+ node_path ,
508
+ task_name ,
509
+ NodeInfo (
510
+ arg_name = "return" ,
511
+ path = p ,
512
+ value = x ,
513
+ task_path = task_path ,
514
+ task_name = task_name ,
515
+ ),
460
516
is_string_allowed = False ,
461
517
),
462
518
task_produces ,
0 commit comments