Comments (3)
It seems as though you're wanting this to affect the shell in the debugger. Have you considered using pudb's custom shell feature?
from pudb.
I have not yet. If that is another way to go, then i will investigate it. Thank you!
from pudb.
hello again!
so i've hooked up the custom_shell and set up my file pudb_custom_shell.py
and started messing with it.
i've found that i need to use cons.push()
to "push" code to my custom shell. for example, if i have
cons.push("from pprint from pprint")
To use pprint in my console, i can just do `pprint("hello") and it comes out correctly.
is there a way i can run an entire .py file instead of just doing line by line in my pudb_custom_shell.py
file?
i've tried the following below and it will output a print statement but it won't import pprint.
See below for 2 versions of my pudb_custom_shell.py
file. one with cons.push('from pprint import pprint')
and then the one trying import a ipython_startup_script.py file and running everything in that.
This version below works:
here is what it looks like:
"""
This file shows how you can define a custom shell for PuDB. This is the
shell used when pressing the ! key in the debugger (it does not affect the
Ctrl-x shell that is built into PuDB).
To create a custom shell, create a file like this one with a function called
pudb_shell(_globals, _locals) defined at the module level. Note
that the file will be execfile'd.
Then, go to the PuDB preferences window (type Ctrl-p inside of PuDB) and add
the path to the file in the "Custom" field under the "Shell" heading.
The example in this file
"""
Define this a function with this name and signature at the module level.
def pudb_shell(_globals, _locals):
"""
This example shell runs a classic Python shell. It is based on
run_classic_shell in pudb.shell.
"""
# Many shells only let you pass in a single locals dictionary, rather than
# separate globals and locals dictionaries. In this case, you can use
# pudb.shell.SetPropagatingDict to automatically merge the two into a
# single dictionary. It does this in such a way that assignments propogate
# to _locals, so that when the debugger is at the module level, variables
# can be reassigned in the shell.
from pudb.shell import SetPropagatingDict
ns = SetPropagatingDict([_locals, _globals], _locals)
try:
import readline
import rlcompleter
HAVE_READLINE = True
except ImportError:
HAVE_READLINE = False
if HAVE_READLINE:
readline.set_completer(
rlcompleter.Completer(ns).complete)
readline.parse_and_bind("tab: complete")
readline.clear_history()
from code import InteractiveConsole
cons = InteractiveConsole(ns)
cons.push("from pprint import pprint") # this works.
other version trying to import and run an entire file.
"""
This file shows how you can define a custom shell for PuDB. This is the
shell used when pressing the ! key in the debugger (it does not affect the
Ctrl-x shell that is built into PuDB).
To create a custom shell, create a file like this one with a function called
pudb_shell(_globals, _locals) defined at the module level. Note
that the file will be execfile'd.
Then, go to the PuDB preferences window (type Ctrl-p inside of PuDB) and add
the path to the file in the "Custom" field under the "Shell" heading.
The example in this file
"""
Define this a function with this name and signature at the module level.
def pudb_shell(_globals, _locals):
"""
This example shell runs a classic Python shell. It is based on
run_classic_shell in pudb.shell.
"""
# Many shells only let you pass in a single locals dictionary, rather than
# separate globals and locals dictionaries. In this case, you can use
# pudb.shell.SetPropagatingDict to automatically merge the two into a
# single dictionary. It does this in such a way that assignments propogate
# to _locals, so that when the debugger is at the module level, variables
# can be reassigned in the shell.
from pudb.shell import SetPropagatingDict
ns = SetPropagatingDict([_locals, _globals], _locals)
try:
import readline
import rlcompleter
HAVE_READLINE = True
except ImportError:
HAVE_READLINE = False
if HAVE_READLINE:
readline.set_completer(
rlcompleter.Completer(ns).complete)
readline.parse_and_bind("tab: complete")
readline.clear_history()
from code import InteractiveConsole
cons = InteractiveConsole(ns)
# import code
import os
# Get the path to the .py file in your home directory
home_dir = os.path.expanduser("~")
module_path = os.path.join(home_dir, "ipython_startup_script.py")
# Import and execute the script
with open(module_path, 'r') as file:
script_code = file.read()
exec(script_code) # commenting out this or
cons.push(script_code) # commenting out this one.
cons.interact("Press Ctrl-D to return to the debugger")
# When the function returns, control will be returned to the debugger.
my ipython_startup_script file looks like this:
print("running ipython_startup_script.py") # <-- this will output to the console
from pprint import pprint # <-- this does not get imported.
i get this error if i dont put them in a function
SyntaxError: multiple statements found while compiling a single statement
I've also tried button both of those lines in a function called Load()
and then called Load()
at the end.
Any ideas on where to go from here or is cons.push()
line by line in the shell file the way to go?
from pudb.
Related Issues (20)
- remote debugging - Cannot disable application log message from garbling up the PuDB UI screen HOT 3
- Pudb UI Exception Encountered: Object 'A' appears to be a sequence, but does not behave like one: iteration over a 0-d tensor HOT 1
- Disable "view output" in remote debug HOT 1
- βI/O operation on closed fileβ when try with "Debugging from a separate terminal" HOT 12
- Error reported when exiting iPython and returning to UI on Mac OS X HOT 3
- Please make this marvel run well on a-Shell app for iPad HOT 1
- "Debugger instance already exists" when used in pytest HOT 5
- Greyscale Theme HOT 4
- New Release HOT 1
- Unable to use `--pdb --pdbcls=pudb.debugger:Debugger` with latest versions of urwid HOT 2
- telnetlib (used for remote debugger) is deprecated in Python 3.12 HOT 4
- Run to line in the same frame HOT 1
- Allow setting term size via env var HOT 1
- PUDB freezes at welcome screen HOT 2
- export PUDB_TTY=... not working HOT 1
- how can i see or get the current debugged file path?
- remote debugging with telnet fails: a Debugger instance already exists HOT 2
- 2024.1 display clobbered with internal pudb [DEBUG] messages. HOT 11
- Variable ListBox crashes for long variables repr HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. πππ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pudb.