11from pash_annotations .datatypes .BasicDatatypes import Flag , ArgStringType , Operand
22from pash_annotations .datatypes .BasicDatatypesWithIO import OptionWithIO
33from pash_annotations .datatypes .CommandInvocationInitial import CommandInvocationInitial
4- from pash_annotations .annotation_generation .datatypes .InputOutputInfo import InputOutputInfo
5- from pash_annotations .annotation_generation .datatypes .ParallelizabilityInfo import ParallelizabilityInfo
6- from pash_annotations .annotation_generation .datatypes .CommandProperties import CommandProperties
7- from pash_annotations .annotation_generation .AnnotationGeneration import get_input_output_info_from_cmd_invocation , \
8- get_parallelizability_info_from_cmd_invocation
9- from pash_annotations .datatypes .CommandInvocationWithIOVars import CommandInvocationWithIOVars
4+ from pash_annotations .annotation_generation .datatypes .InputOutputInfo import (
5+ InputOutputInfo ,
6+ )
7+ from pash_annotations .annotation_generation .datatypes .ParallelizabilityInfo import (
8+ ParallelizabilityInfo ,
9+ )
10+ from pash_annotations .annotation_generation .datatypes .CommandProperties import (
11+ CommandProperties ,
12+ )
13+ from pash_annotations .annotation_generation .AnnotationGeneration import (
14+ get_input_output_info_from_cmd_invocation ,
15+ get_parallelizability_info_from_cmd_invocation ,
16+ )
17+ from pash_annotations .datatypes .CommandInvocationWithIOVars import (
18+ CommandInvocationWithIOVars ,
19+ )
1020
1121from definitions .ir .arg import Arg
1222
1323# for typing
1424from pash_annotations .datatypes .CommandInvocationPrefix import CommandInvocationPrefix
1525
16- from shell_ast .ast_util import string_to_argument , redir_stdout_to_file , redir_file_to_stdin , make_command
26+ from shell_ast .ast_util import (
27+ string_to_argument ,
28+ redir_stdout_to_file ,
29+ redir_file_to_stdin ,
30+ make_command ,
31+ )
32+
1733
1834def get_command_invocation_prefix_from_dfg_node (dfg_node ):
19- return CommandInvocationPrefix (cmd_name = dfg_node .com_name ,
20- flag_option_list = dfg_node .flag_option_list ,
21- positional_config_list = dfg_node .positional_config_list )
35+ return CommandInvocationPrefix (
36+ cmd_name = dfg_node .com_name ,
37+ flag_option_list = dfg_node .flag_option_list ,
38+ positional_config_list = dfg_node .positional_config_list ,
39+ )
40+
2241
2342# TODO: ideally methods in the respective classes but requires refactoring of parsing infrastructure
2443# TODO: isn't this `to_ast`?
@@ -48,55 +67,70 @@ def to_node_cmd_inv_with_io_vars(cmd_inv, edges, redirs, assignments):
4867 node = make_command (cmd_asts , redirections = new_redirs , assignments = assignments )
4968 return node
5069
70+
5171def to_ast_flagoption (flagoption , edges ):
5272 if isinstance (flagoption , Flag ):
5373 return [string_to_argument (flagoption .get_name ())]
54- elif isinstance (flagoption , OptionWithIO ): # retype to IOVar
74+ elif isinstance (flagoption , OptionWithIO ): # retype to IOVar
5575 opt_name_ast = string_to_argument (flagoption .get_name ())
5676 opt_arg_ast = translate_io_var_if_applicable (flagoption .get_arg (), edges )
5777 return [opt_name_ast , opt_arg_ast ]
5878
79+
5980def to_ast_operand (operand , edges ):
6081 if isinstance (operand , Operand ):
6182 return translate_io_var_if_applicable (operand .get_name (), edges )
6283 return translate_io_var_if_applicable (operand , edges )
6384
85+
6486def translate_io_var_if_applicable (pot_io_var , edges ):
6587 # TODO: this is currently a hack but eventually every possible type gets their own to_ast-function
6688 if isinstance (pot_io_var , int ):
6789 return dereference_io_var (pot_io_var , edges )
6890 elif isinstance (pot_io_var , ArgStringType ):
6991 return to_ast_arg_string_type (pot_io_var )
7092 elif isinstance (pot_io_var , CommandInvocationWithIOVars ):
71- assert ( False )
93+ assert False
7294 # only happens as r-wrapped node
7395 return to_node_cmd_inv_with_io_vars (pot_io_var , edges , [], [])
7496 elif isinstance (pot_io_var , Arg ):
7597 return pot_io_var .to_ast ()
7698 else :
7799 raise Exception ("Unhandled type for operand in to_ast!" )
78100
101+
79102def to_ast_arg_string_type (arg_string_type ):
80- return arg_string_type .get_name ().arg_char_list # is of type Arg
103+ return arg_string_type .get_name ().arg_char_list # is of type Arg
104+
81105
82106# assumes io_var is an edge id
83107def dereference_io_var (io_var , edges ):
84108 fid , _ , _ = edges [io_var ]
85109 return fid .to_ast ()
86110
87- def get_input_output_info_from_cmd_invocation_util (cmd_invocationInitial : CommandInvocationInitial ) -> InputOutputInfo :
111+
112+ def get_input_output_info_from_cmd_invocation_util (
113+ cmd_invocationInitial : CommandInvocationInitial ,
114+ ) -> InputOutputInfo :
88115 return get_input_output_info_from_cmd_invocation (cmd_invocationInitial )
89116
90- def get_parallelizability_info_from_cmd_invocation_util (cmd_invocationInitial : CommandInvocationInitial ) -> ParallelizabilityInfo :
117+
118+ def get_parallelizability_info_from_cmd_invocation_util (
119+ cmd_invocationInitial : CommandInvocationInitial ,
120+ ) -> ParallelizabilityInfo :
91121 return get_parallelizability_info_from_cmd_invocation (cmd_invocationInitial )
92122
123+
93124def construct_property_container_from_list_of_properties (list_properties ):
94125 return CommandProperties (dict (list_properties ))
95126
127+
96128# this function is needed to wrap a node in `r_wrap`
97- def to_arg_from_cmd_inv_with_io_vars_without_streaming_inputs_or_outputs_for_wrapping (cmd_inv , edges ):
129+ def to_arg_from_cmd_inv_with_io_vars_without_streaming_inputs_or_outputs_for_wrapping (
130+ cmd_inv , edges
131+ ):
98132 # we already expand here
99- whole_cmd = Arg .string_to_arg ("\ ' " )
133+ whole_cmd = Arg .string_to_arg ("'" )
100134 arg_cmd_name = Arg .string_to_arg (cmd_inv .cmd_name )
101135 arg_flagoptions = []
102136 for flagoption in cmd_inv .flag_option_list :
@@ -107,9 +141,10 @@ def to_arg_from_cmd_inv_with_io_vars_without_streaming_inputs_or_outputs_for_wra
107141 all_cmd_parts_arg .extend (arg_operands )
108142 for part in all_cmd_parts_arg :
109143 whole_cmd .concatenate (part )
110- whole_cmd .concatenate (Arg .string_to_arg ("\ ' " ))
144+ whole_cmd .concatenate (Arg .string_to_arg ("'" ))
111145 return whole_cmd
112146
147+
113148def to_arg_flagoption (flagoption , edges ):
114149 if isinstance (flagoption , Flag ):
115150 return [Arg .string_to_arg (flagoption .get_name ())]
@@ -118,11 +153,13 @@ def to_arg_flagoption(flagoption, edges):
118153 opt_arg_arg = translate_io_var_to_arg_if_applicable (flagoption .get_arg (), edges )
119154 return [opt_name_arg , opt_arg_arg ]
120155
156+
121157def to_arg_operand (operand , edges ):
122158 if isinstance (operand , Operand ):
123159 return translate_io_var_to_arg_if_applicable (operand .get_name (), edges )
124160 return translate_io_var_to_arg_if_applicable (operand , edges )
125161
162+
126163def translate_io_var_to_arg_if_applicable (pot_io_var , edges ):
127164 if isinstance (pot_io_var , int ):
128165 return Arg (dereference_io_var (pot_io_var , edges ))
0 commit comments