Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support the debugger from the repl #1397

Closed
gilch opened this issue Aug 25, 2017 · 3 comments
Closed

Support the debugger from the repl #1397

gilch opened this issue Aug 25, 2017 · 3 comments

Comments

@gilch
Copy link
Member

gilch commented Aug 25, 2017

related #741 #1395

We can't get a code listing in the debugger if the function was defined at the repl.

=> (defn foo []
... (setv bar 42)
... (import pdb)(pdb.set-trace))
=> (foo)
--Return--
> <eval_body>(1)foo()->None
(Pdb) l
[EOF]
(Pdb) 

The usual Emacs workflow involves sending toplevel forms from the file buffer to the repl, so the lack of debugger support in this case is a pain.

The truth is, Python's repl can't do this either.

>>> def foo():
...   bar = 42
...   import pdb; pdb.set_trace()
...
>>> foo()
--Return--
> <stdin>(3)foo()->None
(Pdb) l
[EOF]
(Pdb) 

So maybe that's why no-one complained. But IPython can.

In [1]: def foo():
   ...:     bar = 42
   ...:     import pdb; pdb.set_trace()
   ...:

In [2]: foo()
--Return--
> <ipython-input-1-8e38ce8e3905>(3)foo()->None
-> import pdb; pdb.set_trace()
(Pdb) l
  1     def foo():
  2         bar = 42
  3  ->     import pdb; pdb.set_trace()
  4
[EOF]
(Pdb) bar
42
(Pdb) 

So I know it's possible in principle.

@ekaschalk
Copy link
Contributor

I also wanted to add, is it possible to have something like IPython's %pdb toggle in hy repl (when error is encountered set trace and pdb at point)? I have no idea how involved that feature would be.

@gilch
Copy link
Member Author

gilch commented Aug 28, 2017

I'm not sure about that either, but IPython is actually pretty extensible. I think it would be pretty easy to create a custom %hy magic to make IPython read Hy input for just that line. You'd just have to call Hy's compiler on that line, something like hy.eval(hy.read_str(line)) would probably work. Then you'd get %pdb and all the other IPython magic for free. Even without that, you can certainly import any Hy module during an IPython session.

I'm actually considering doing it the other way around: make an IHy that reads Hy by default, which would help with #1323 as well as these debugger issues. This would be quite a bit more involved, and use IPython's custom input transformation API. I'm reluctant to include this in Hy proper, at least at first. It would be a separate project. But it might be nicer to use than the default Hy repl, since we'd be able to get nice IPython features in Hy.

@gilch
Copy link
Member Author

gilch commented Aug 28, 2017

Basic line magic is not hard. Here's a basic proof of concept.

In [1]: from IPython.core.magic import register_line_magic

In [2]: @register_line_magic
   ...: def hy(line):
   ...:     "interprets line as Hy"
   ...:     import hy
   ...:     return hy.eval(hy.read_str(line), globals())
   ...:

In [3]: %hy(+ 1 2)
Out[3]: 3

In [4]: %hy(setv foo 42)

In [5]: foo
Out[5]: 42

It's pretty limited, but might already be useful. Cell magic would be about as easy.

brandonwillard added a commit to brandonwillard/hy that referenced this issue Nov 9, 2018
Source entered interactively can now be displayed in traceback output.  Also,
the REPL object is now available in its namespace, so that, for instance,
display options--like `spy`--can be turned on and off interactively.

Closes hylang#1397.
brandonwillard added a commit to brandonwillard/hy that referenced this issue Nov 10, 2018
Source entered interactively can now be displayed in traceback output.  Also,
the REPL object is now available in its namespace, so that, for instance,
display options--like `spy`--can be turned on and off interactively.

Closes hylang#1397.
brandonwillard added a commit to brandonwillard/hy that referenced this issue Nov 14, 2018
Source entered interactively can now be displayed in traceback output.  Also,
the REPL object is now available in its namespace, so that, for instance,
display options--like `spy`--can be turned on and off interactively.

Closes hylang#1397.
brandonwillard added a commit to brandonwillard/hy that referenced this issue Nov 27, 2018
Source entered interactively can now be displayed in traceback output.  Also,
the REPL object is now available in its namespace, so that, for instance,
display options--like `spy`--can be turned on and off interactively.

Closes hylang#1397.
brandonwillard added a commit to brandonwillard/hy that referenced this issue Nov 28, 2018
Source entered interactively can now be displayed in traceback output.  Also,
the REPL object is now available in its namespace, so that, for instance,
display options--like `spy`--can be turned on and off interactively.

Closes hylang#1397.
brandonwillard added a commit to brandonwillard/hy that referenced this issue Nov 29, 2018
Source entered interactively can now be displayed in traceback output.  Also,
the REPL object is now available in its namespace, so that, for instance,
display options--like `spy`--can be turned on and off interactively.

Closes hylang#1397.
brandonwillard added a commit to brandonwillard/hy that referenced this issue Dec 1, 2018
Source entered interactively can now be displayed in traceback output.  Also,
the REPL object is now available in its namespace, so that, for instance,
display options--like `spy`--can be turned on and off interactively.

Closes hylang#1397.
brandonwillard added a commit to brandonwillard/hy that referenced this issue Dec 2, 2018
Source entered interactively can now be displayed in traceback output.  Also,
the REPL object is now available in its namespace, so that, for instance,
display options--like `spy`--can be turned on and off interactively.

Closes hylang#1397.
brandonwillard added a commit to brandonwillard/hy that referenced this issue Dec 7, 2018
Source entered interactively can now be displayed in traceback output.  Also,
the REPL object is now available in its namespace, so that, for instance,
display options--like `spy`--can be turned on and off interactively.

Closes hylang#1397.
Kodiologist pushed a commit to brandonwillard/hy that referenced this issue Dec 8, 2018
Source entered interactively can now be displayed in traceback output.  Also,
the REPL object is now available in its namespace, so that, for instance,
display options--like `spy`--can be turned on and off interactively.

Closes hylang#1397.
Kodiologist pushed a commit to brandonwillard/hy that referenced this issue Dec 12, 2018
Source entered interactively can now be displayed in traceback output.  Also,
the REPL object is now available in its namespace, so that, for instance,
display options--like `spy`--can be turned on and off interactively.

Closes hylang#1397.
brandonwillard added a commit to brandonwillard/hy that referenced this issue Dec 17, 2018
Source entered interactively can now be displayed in traceback output.  Also,
the REPL object is now available in its namespace, so that, for instance,
display options--like `spy`--can be turned on and off interactively.

Closes hylang#1397.
brandonwillard added a commit to brandonwillard/hy that referenced this issue Jan 17, 2019
Source entered interactively can now be displayed in traceback output.  Also,
the REPL object is now available in its namespace, so that, for instance,
display options--like `spy`--can be turned on and off interactively.

Closes hylang#1397.
brandonwillard added a commit to brandonwillard/hy that referenced this issue Jan 17, 2019
Source entered interactively can now be displayed in traceback output.  Also,
the REPL object is now available in its namespace, so that, for instance,
display options--like `spy`--can be turned on and off interactively.

Closes hylang#1397.
Kodiologist pushed a commit to Kodiologist/hy that referenced this issue Jan 20, 2019
Source entered interactively can now be displayed in traceback output.  Also,
the REPL object is now available in its namespace, so that, for instance,
display options--like `spy`--can be turned on and off interactively.

Closes hylang#1397.
Kodiologist pushed a commit to Kodiologist/hy that referenced this issue Jan 26, 2019
Source entered interactively can now be displayed in traceback output.  Also,
the REPL object is now available in its namespace, so that, for instance,
display options--like `spy`--can be turned on and off interactively.

Closes hylang#1397.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants