8
8
9
9
from burr import tracking
10
10
from burr .core import Application , ApplicationBuilder , State , Action , default
11
- from burr .core .action import action
12
11
from burr .lifecycle import PostRunStepHook , PreRunStepHook
13
12
14
13
@@ -40,7 +39,7 @@ def reads(self) -> list[str]:
40
39
return parse_boolean_expression (self .node .input )
41
40
42
41
def run (self , state : State , ** run_kwargs ) -> dict :
43
- node_inputs = {key : state [key ] for key in self .reads }
42
+ node_inputs = {key : state [key ] for key in self .reads if key in state }
44
43
result_state = self .node .execute (node_inputs , ** run_kwargs )
45
44
return result_state
46
45
@@ -49,7 +48,7 @@ def writes(self) -> list[str]:
49
48
return self .node .output
50
49
51
50
def update (self , result : dict , state : State ) -> State :
52
- return state .update (** state )
51
+ return state .update (** result )
53
52
54
53
55
54
def parse_boolean_expression (expression : str ) -> List [str ]:
@@ -92,7 +91,8 @@ class BurrBridge:
92
91
def __init__ (self , base_graph , burr_config ):
93
92
self .base_graph = base_graph
94
93
self .burr_config = burr_config
95
- self .tracker = tracking .LocalTrackingClient (project = "smart-scraper-graph" )
94
+ self .project_name = burr_config .get ("project_name" , "default-project" )
95
+ self .tracker = tracking .LocalTrackingClient (project = self .project_name )
96
96
self .app_instance_id = burr_config .get ("app_instance_id" , "default-instance" )
97
97
self .burr_inputs = burr_config .get ("inputs" , {})
98
98
self .burr_app = None
@@ -111,7 +111,7 @@ def _initialize_burr_app(self, initial_state: Dict[str, Any] = {}) -> Applicatio
111
111
actions = self ._create_actions ()
112
112
transitions = self ._create_transitions ()
113
113
hooks = [PrintLnHook ()]
114
- burr_state = self . _convert_state_to_burr (initial_state )
114
+ burr_state = State (initial_state )
115
115
116
116
app = (
117
117
ApplicationBuilder ()
@@ -136,32 +136,10 @@ def _create_actions(self) -> Dict[str, Any]:
136
136
137
137
actions = {}
138
138
for node in self .base_graph .nodes :
139
- action_func = self . _create_action (node )
139
+ action_func = BurrNodeBridge (node )
140
140
actions [node .node_name ] = action_func
141
141
return actions
142
142
143
- def _create_action (self , node ) -> Any :
144
- """
145
- Create a Burr action function from a base graph node.
146
-
147
- Args:
148
- node (Node): The base graph node to convert to a Burr action.
149
-
150
- Returns:
151
- function: The Burr action function.
152
- """
153
-
154
- # @action(reads=parse_boolean_expression(node.input), writes=node.output)
155
- # def dynamic_action(state: State, **kwargs):
156
- # node_inputs = {key: state[key] for key in self._parse_boolean_expression(node.input)}
157
- # result_state = node.execute(node_inputs, **kwargs)
158
- # return result_state, state.update(**result_state)
159
- #
160
- # return dynamic_action
161
- # import pdb
162
- # pdb.set_trace()
163
- return BurrNodeBridge (node )
164
-
165
143
def _create_transitions (self ) -> List [Tuple [str , str , Any ]]:
166
144
"""
167
145
Create Burr transitions from the base graph edges.
@@ -175,22 +153,6 @@ def _create_transitions(self) -> List[Tuple[str, str, Any]]:
175
153
transitions .append ((from_node , to_node , default ))
176
154
return transitions
177
155
178
- def _convert_state_to_burr (self , state : Dict [str , Any ]) -> State :
179
- """
180
- Convert a dictionary state to a Burr state.
181
-
182
- Args:
183
- state (dict): The dictionary state to convert.
184
-
185
- Returns:
186
- State: The Burr state instance.
187
- """
188
-
189
- burr_state = State ()
190
- for key , value in state .items ():
191
- setattr (burr_state , key , value )
192
- return burr_state
193
-
194
156
def _convert_state_from_burr (self , burr_state : State ) -> Dict [str , Any ]:
195
157
"""
196
158
Convert a Burr state to a dictionary state.
@@ -223,7 +185,6 @@ def execute(self, initial_state: Dict[str, Any] = {}) -> Dict[str, Any]:
223
185
# TODO: to fix final nodes detection
224
186
final_nodes = [self .burr_app .graph .actions [- 1 ].name ]
225
187
226
- # TODO: fix inputs
227
188
last_action , result , final_state = self .burr_app .run (
228
189
halt_after = final_nodes ,
229
190
inputs = self .burr_inputs
0 commit comments