def _init_pdb(context=3): try: p = Pdb(def_colors, context=context) except TypeError: p = Pdb(def_colors) p.rcLines += def_exec_lines return p
def _init_pdb(context=3): if 'context' in getargspec(Pdb.__init__)[0]: p = Pdb(def_colors, context=context) else: p = Pdb(def_colors) p.rcLines += def_exec_lines return p
def debug(self, kind='ipdb'): """ Run callable in debug mode. Parameters ---------- kind : str ('ipdb' or 'pdb') Which debugger to use 'ipdb' for IPython debugger or 'pdb' for debugger from the standard library Notes ----- Be careful when debugging tasks. If the task has run successfully, you overwrite products but don't save the updated source code, your DAG will enter an inconsistent state where the metadata won't match the overwritten product. """ opts = {'ipdb', 'pdb'} if kind not in opts: raise ValueError('"kind" must be one of {}, got: "{}"'.format( opts, kind)) if self.exec_status == TaskStatus.WaitingRender: raise TaskBuildError('Error in task "{}". ' 'Cannot call task.debug() on a task that has ' 'not been ' 'rendered, call DAG.render() first'.format( self.name)) if 'upstream' in self.params and self._unserializer: params = _unserialize_params(self.params, self._unserializer) else: params = self.params.to_dict() if self._serializer: params.pop('product') if kind == 'ipdb': try: # this seems to only work in a Terminal ipdb = TerminalPdb() except AttributeError: # this works in a Jupyter notebook ipdb = Pdb() ipdb.runcall(self.source.primitive, **params) elif kind == 'pdb': pdb.runcall(self.source.primitive, **params)
def debug(self, kind='ipdb'): """ Opens the notebook (with injected parameters) in debug mode in a temporary location Parameters ---------- kind : str, default='ipdb' Debugger to use, 'ipdb' to use line-by-line IPython debugger, 'pdb' to use line-by-line Python debugger or 'pm' to to post-portem debugging using IPython Notes ----- Be careful when debugging tasks. If the task has run successfully, you overwrite products but don't save the updated source code, your DAG will enter an inconsistent state where the metadata won't match the overwritten product. """ if self.source.language != 'python': raise NotImplementedError( 'debug is not implemented for "{}" ' 'notebooks, only python is supported'.format( self.source.language)) opts = {'ipdb', 'pdb', 'pm'} if kind not in opts: raise ValueError('kind must be one of {}'.format(opts)) nb = _read_rendered_notebook(self.source.nb_str_rendered) fd, tmp_path = tempfile.mkstemp(suffix='.py') os.close(fd) code = jupytext.writes(nb, version=nbformat.NO_CONVERT, fmt='py') Path(tmp_path).write_text(code) if kind == 'pm': # post-mortem debugging try: subprocess.run(['ipython', tmp_path, '--pdb']) finally: Path(tmp_path).unlink() else: if kind == 'ipdb': from IPython.terminal.debugger import TerminalPdb, Pdb code = compile(source=code, filename=tmp_path, mode='exec') try: # this seems to only work in a Terminal debugger = TerminalPdb() except AttributeError: # this works in a Jupyter notebook debugger = Pdb() elif kind == 'pdb': debugger = pdb try: debugger.run(code) finally: Path(tmp_path).unlink()