10
10
from typing import Union
11
11
12
12
import networkx as nx
13
- from _pytask .nodes import create_task_name
13
+ from _pytask .console import format_task_id
14
14
from _pytask .nodes import MetaNode
15
15
from _pytask .nodes import MetaTask
16
16
from _pytask .path import find_closest_ancestor
@@ -120,7 +120,7 @@ def parse_value_or_multiline_option(
120
120
elif isinstance (value , str ):
121
121
return value .strip ()
122
122
else :
123
- raise ValueError (f"Input ' { value } ' is neither a 'str' nor 'None'." )
123
+ raise ValueError (f"Input { value !r } is neither a 'str' nor 'None'." )
124
124
125
125
126
126
def convert_truthy_or_falsy_to_bool (x : Union [bool , str , None ]) -> bool :
@@ -133,7 +133,7 @@ def convert_truthy_or_falsy_to_bool(x: Union[bool, str, None]) -> bool:
133
133
out = None
134
134
else :
135
135
raise ValueError (
136
- f"Input ' { x } ' is neither truthy (True, true, 1) or falsy (False, false, 0)."
136
+ f"Input { x !r } is neither truthy (True, true, 1) or falsy (False, false, 0)."
137
137
)
138
138
return out
139
139
@@ -155,13 +155,10 @@ def reduce_node_name(node: "MetaNode", paths: Sequence[Union[str, Path]]) -> str
155
155
except ValueError :
156
156
ancestor = node .path .parents [- 1 ]
157
157
158
- if isinstance (node , MetaTask ):
159
- shortened_path = relative_to (node .path , ancestor )
160
- name = create_task_name (shortened_path , node .base_name )
161
- elif isinstance (node , MetaNode ):
158
+ if isinstance (node , MetaNode ):
162
159
name = relative_to (node .path , ancestor ).as_posix ()
163
160
else :
164
- raise TypeError (f"Unknown node { node } with type ' { type (node )} ' ." )
161
+ raise TypeError (f"Unknown node { node } with type { type (node )!r } ." )
165
162
166
163
return name
167
164
@@ -170,7 +167,21 @@ def reduce_names_of_multiple_nodes(
170
167
names : List [str ], dag : nx .DiGraph , paths : Sequence [Union [str , Path ]]
171
168
) -> List [str ]:
172
169
"""Reduce the names of multiple nodes in the DAG."""
173
- return [
174
- reduce_node_name (dag .nodes [n ].get ("node" ) or dag .nodes [n ].get ("task" ), paths )
175
- for n in names
176
- ]
170
+ short_names = []
171
+ for name in names :
172
+ node = dag .nodes [name ].get ("node" ) or dag .nodes [name ].get ("task" )
173
+
174
+ if isinstance (node , MetaTask ):
175
+ short_name = format_task_id (
176
+ node , editor_url_scheme = "no_link" , short_name = True
177
+ )
178
+ elif isinstance (node , MetaNode ):
179
+ short_name = reduce_node_name (node , paths )
180
+ else :
181
+ raise TypeError (
182
+ f"Requires 'MetaTask' or 'MetaNode' and not { type (node )!r} ."
183
+ )
184
+
185
+ short_names .append (short_name )
186
+
187
+ return short_names
0 commit comments