@@ -40,10 +40,8 @@ def __init__(self, producers_and_getters, set_methods):
4040 self .getter_to_step_map = {}
4141
4242 self .terms = []
43- self .skipped = []
4443 for idx , (producers , getters ) in enumerate (self .producers_and_getters ):
4544 self .terms .append (- 1 )
46- self .skipped .append (False )
4745
4846 for prod in producers :
4947 self .producer_to_step_map [prod .__name__ ] = idx
@@ -96,25 +94,13 @@ def perform_producer_step(self, zephyr, method, *method_args, **method_kwargs):
9694 def try_log_skipping_steps_warning (self , name , next_step ):
9795 steps_skipped = self .get_steps_in_between (self .current_step , next_step )
9896 if len (steps_skipped ) > 0 :
99- for step in range (self .current_step + 1 , next_step ):
100- self .skipped [step ] = True
10197 necc_steps = self .join_steps (steps_skipped )
10298 LOGGER .warning (
10399 f"Performing { name } . You are skipping the following steps:\n { necc_steps } " )
104100
105- def try_log_using_stale_warning (self , name , next_step ):
106- latest_up_to_date = self .get_last_up_to_date (next_step )
107- steps_needed = self .get_steps_in_between (
108- latest_up_to_date - 1 , next_step )
109- if len (steps_needed ) > 0 :
110- LOGGER .warning (f"Performing { name } . You are in a stale state and \
111- using potentially stale data to perform this step. \
112- Re-run the following steps to return to a present state:\n : \
113- { steps_needed } " )
114-
115101 def try_log_making_stale_warning (self , name , next_step ):
116102 next_next_step = next_step + 1
117- prod_steps = f"{ next_next_step } . \
103+ prod_steps = f"step { next_next_step } : \
118104 { ' or ' .join (self .producers_and_getters [next_next_step ][0 ])} "
119105 # add later set methods
120106 get_steps = self .join_steps (
@@ -124,17 +110,7 @@ def try_log_making_stale_warning(self, name, next_step):
124110 LOGGER .warning (f"Performing { name } . You are beginning a new iteration.\
125111 Any data returned by the following get methods will be \
126112 considered stale:\n { get_steps } . To continue with this \
127- iteration, please perform:\n { prod_steps } " )
128-
129- # stale must be before b/c user must have regressed with progress that contains skips
130- # return set method, and next possible up to date key method
131- def try_log_inconsistent_warning (self , name , next_step ):
132- set_method_str = self .producers_and_getters [next_step ][0 ][1 ].__name__
133- latest_up_to_date = self .get_last_up_to_date (next_step )
134- LOGGER .warning (f"Unable to perform { name } because some steps have been\
135- skipped. You can call the corresponding set method: \
136- { set_method_str } or re run steps starting at or before \
137- { latest_up_to_date } " )
113+ iteration, please perform \n { prod_steps } " )
138114
139115 def log_get_inconsistent_warning (self , name , next_step ):
140116 prod_steps = f"{ next_step } . \
@@ -169,6 +145,7 @@ def try_perform_backward_producer_step(self, zephyr, method, *method_args, **met
169145 next_step = self .producer_to_step_map [name ]
170146 self .try_log_making_stale_warning (next_step )
171147 self .cur_term += 1
148+ # mark everything prior to next step as current term
172149 for i in range (0 , next_step ):
173150 if self .terms [i ] != - 1 :
174151 self .terms [i ] = self .cur_term
@@ -190,17 +167,51 @@ def try_perform_producer_step(self, zephyr, method, *method_args, **method_kwarg
190167
191168 # dont update current step or terms
192169
193- def try_perform_stale_or_inconsistent_producer_step (
170+ def try_perform_inconsistent_producer_step ( # add using stale and overwriting
194171 self , zephyr , method , * method_args , ** method_kwargs ):
195172 name = method .__name__
196173 next_step = self .producer_to_step_map [name ]
197- if self .terms [next_step - 1 ] == - 1 : # inconsistent
198- self .try_log_inconsistent_warning (name , next_step )
199- else :
200- self .try_log_using_stale_warning (name , next_step )
201- res = self .perform_producer_step (
202- zephyr , method , * method_args , ** method_kwargs )
203- return res
174+ # inconsistent forward step: performing key method but previous step is not up to date
175+ if next_step >= self .current_step and self .terms [next_step - 1 ] != self .cur_term :
176+ corr_set_method = self .producers_and_getters [next_step ][0 ][1 ].__name__
177+ prev_step = next_step - 1
178+ prev_set_method = self .producers_and_getters [prev_step ][0 ][1 ].__name__
179+ prev_key_method = self .producers_and_getters [prev_step ][0 ][0 ].__name__
180+ LOGGER .warning (f"Unable to perform { name } because you are performing a key method at\
181+ step { next_step } but the result of the previous step, \
182+ step { prev_step } , is not up to date.\
183+ If you already have the data for step { next_step } , \
184+ you can use the corresponding set method: { corr_set_method } .\
185+ Otherwise, please perform step { prev_step } \
186+ with { prev_key_method } or { prev_set_method } ." )
187+ # inconsistent backward step: performing set method at nonzero step
188+ elif next_step < self .current_step and name in self .set_method :
189+ first_set_method = self .producers_and_getters [0 ][0 ][1 ].__name__
190+ corr_key_method = self .producers_and_getters [next_step ][0 ][0 ].__name__
191+ LOGGER .warning (f"Unable to perform { name } because you are going backwards \
192+ and performing step { next_step } with a set method.\
193+ You can only perform a backwards step with a set \
194+ method at step 0: { first_set_method } .\
195+ If you would like to perform step { next_step } , \
196+ please use the corresponding key method: { corr_key_method } ." )
197+ # inconsistent backward step: performing key method but previous step is not up to date
198+ elif next_step < self .current_step and self .terms [next_step - 1 ] != self .cur_term :
199+ prev_step = next_step - 1
200+ prev_key_method = self .producers_and_getters [prev_step ][0 ][0 ].__name__
201+ corr_set_method = self .producers_and_getters [next_step ][0 ][1 ].__name__
202+ LOGGER .warning (f"Unable to perform { name } because you are going \
203+ backwards and starting a new iteration by\
204+ performing a key method at step { next_step } \
205+ but the result of the previous step,\
206+ step { prev_step } , is not up to date.\
207+ Please perform step { prev_step } with { prev_key_method } first.\
208+ If you already have the data for \
209+ step { next_step } from the previous iteration,\
210+ re-performing { prev_key_method } with the same \
211+ arguments should generate the same result.\
212+ Otherwise, if the data is unrelated, \
213+ please create a new Zephyr instance\
214+ and use its { corr_set_method } method." )
204215
205216 def try_perform_getter_step (self , zephyr , method , * method_args , ** method_kwargs ):
206217 name = method .__name__
@@ -222,13 +233,20 @@ def guide_step(self, zephyr, method, *method_args, **method_kwargs):
222233 if method_name in self .producer_to_step_map :
223234 # up-todate
224235 next_step = self .producer_to_step_map [method_name ]
225- if (method_name in self .set_methods or next_step == 0 or
226- self .terms [next_step - 1 ] == self .cur_term ):
236+ if (next_step == 0 or # 0 step always valid, starting new iteration
237+ # forward step only valid if set method or key method w/ no skips
238+ (next_step >= self .current_step and
239+ (method_name in self .set_methods or
240+ self .terms [next_step - 1 ] == self .cur_term )) or
241+ # backward step only valid if key method w/ previous step up to date
242+ (next_step < self .current_step and
243+ (method_name not in self .set_methods and
244+ self .terms [next_step - 1 ] == self .cur_term ))):
227245 res = self .try_perform_producer_step (
228246 zephyr , method , * method_args , ** method_kwargs )
229247 return res
230248 else : # stale or inconsistent
231- res = self .try_perform_stale_or_inconsistent_producer_step (
249+ res = self .try_perform_inconsistent_producer_step (
232250 zephyr , method , * method_args , ** method_kwargs )
233251 return res
234252 elif method_name in self .getter_to_step_map :
0 commit comments