Skip to content

Commit

Permalink
debugshell: make globals() match locals() in interactive shell
Browse files Browse the repository at this point in the history
Summary: This fixes issues like ipython/ipython#62.

Reviewed By: zzl0

Differential Revision: D44759311

fbshipit-source-id: 5ce94040cef09ac67962c147e86711971c545f91
  • Loading branch information
quark-zju authored and facebook-github-bot committed Apr 7, 2023
1 parent 6076c34 commit af8ac9b
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 10 deletions.
11 changes: 8 additions & 3 deletions eden/scm/edenscm/ext/debugshell.py
Expand Up @@ -159,10 +159,15 @@ def _startipython(ui, repo, env) -> None:
config.InteractiveShell.banner2 = bannermsg
config.InteractiveShell.confirm_exit = False

shell = InteractiveShellEmbed.instance(config=config)
_configipython(ui, shell)
if util.istest():
# Disable history during tests.
config.HistoryAccessor.enabled = False

locals().update(env)
globals().update(env)
shell = InteractiveShellEmbed.instance(
config=config, user_ns=globals(), user_module=sys.modules[__name__]
)
_configipython(ui, shell)
shell()


Expand Down
25 changes: 18 additions & 7 deletions eden/scm/tests/test-debugshell-namespace.t
Expand Up @@ -3,18 +3,29 @@

$ eagerepo
$ cat >> foo.py << EOF
> def f(x): return x + 1
> ui.write('%r\n' % [f(i) for i in [1]])
> def f1(x): return x + 1
> ui.write('OUT: %r\n' % [f1(i) for i in [1]])
> EOF

$ hg debugshell < foo.py
[2]
OUT: [2]

$ hg debugshell foo.py
[2]
OUT: [2]

$ hg debugshell -c 'def f(x):
$ hg debugshell -c 'def f2(x):
> return x+1
> ui.write("%r\n" % [f(i) for i in [1]])
> ui.write("OUT: %r\n" % [f2(i) for i in [1]])
> '
[2]
OUT: [2]

$ hg debugshell --config ui.interactive=true << 'EOF' | dos2unix
> def f3(x): return x + 1
> ui.write('OUT: %r\n' % [f3(i) for i in [1]])
> ui.flush()
> exit()
> EOF
...
In [1]:
In [2]: OUT: [2]
...

0 comments on commit af8ac9b

Please sign in to comment.