def warmup_user_process(self): page_slug = page_slugs_list[0] step_name = pages[page_slug].step_names[0] entry_dict = dict( input="# dummy startup code", source="shell", page_slug=page_slug, step_name=step_name, user_id=self.user.id, ) worker_result(entry_dict)
def run_code(self, code, source, page_index, step_index): page_slug = page_slugs_list[page_index] page = pages[page_slug] step_name = pages[page_slug].step_names[step_index] step = getattr(page, step_name) entry_dict = dict( input=code, source=source, page_slug=page_slug, step_name=step_name, user_id=self.user.id, ) entry = None if settings.SAVE_CODE_ENTRIES: entry = CodeEntry.objects.create(**entry_dict) result = worker_result(entry_dict) if settings.SAVE_CODE_ENTRIES: entry.output = result["output"] entry.save() if result["error"]: return dict(error=result["error"]) if passed := result["passed"]: self.move_step(page_index, step_index + 1)
def run_code(self, code, source): entry_dict = dict( input=code, source=source, page_slug=self.user.page_slug, step_name=self.user.step_name, user_id=self.user.id, ) entry = None if settings.SAVE_CODE_ENTRIES: entry = CodeEntry.objects.create(**entry_dict) result = worker_result(entry_dict) if settings.SAVE_CODE_ENTRIES: entry.output = result["output"] entry.save() if result["error"]: return dict(error=result["error"]) if result["passed"]: self.move_step(1) output_parts = result["output_parts"] if not result["awaiting_input"]: output_parts.append(dict(text=">>> ", color="white")) birdseye_url = None birdseye_objects = result["birdseye_objects"] if birdseye_objects: functions = birdseye_objects["functions"] function_ids = [d.pop('id') for d in functions] functions = [eye.db.Function(**{**d, 'hash': uuid4().hex}) for d in functions] with eye.db.session_scope() as session: for func in functions: session.add(func) session.commit() function_ids = {old: func.id for old, func in zip(function_ids, functions)} for call in birdseye_objects["calls"]: call["function_id"] = function_ids[call["function_id"]] call["start_time"] = datetime.fromisoformat(call["start_time"]) call = eye.db.Call(**call) session.add(call) # TODO get correct call from top level call_id = call.id birdseye_url = f"/birdseye/ipython_call/{call_id}" return dict( result=output_parts, message=markdown(result["message"]), state=self.current_state(), birdseye_url=birdseye_url, )