Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def run_tests():
tests = os.environ.get("tests", None)
if tests is not None:
with log.nested("running the VM test script"):
try:
exec(tests)
except Exception as e:
eprint("error: {}".format(str(e)))
sys.exit(1)
else:
ptpython.repl.embed(locals(), globals())
# TODO: Collect coverage data
for machine in machines:
if machine.is_up():
machine.execute("sync")
if nr_tests != 0:
log.log("{} out of {} tests succeeded".format(nr_succeeded, nr_tests))
exec_init(manage_dict, _vars)
exec_init_script(manage_dict, _vars)
atexit_functions = [
import_module(func_name)
for func_name in manage_dict["shell"].get("exit_hooks", [])
]
atexit_functions += exit_hooks or []
for atexit_function in atexit_functions:
atexit.register(atexit_function)
if console == "ptpython":
try:
from ptpython.repl import embed
embed({}, _vars)
except ImportError:
click.echo("ptpython is not installed!")
return
if console == "bpython":
try:
from bpython import embed
embed(locals_=_vars, banner=banner_msg)
except ImportError:
click.echo("bpython is not installed!")
return
try:
if console == "ipython":
from IPython import start_ipython
if os.path.exists(path):
with open(path, 'rb') as f:
code = compile(f.read(), path, 'exec')
six.exec_(code, user_ns, user_ns)
else:
print('File not found: {}\n\n'.format(path))
sys.exit(1)
# Apply config file
def configure(repl):
path = os.path.join(config_dir, 'config.py')
if os.path.exists(path):
run_config(repl, path)
# Run interactive shell.
embed(vi_mode=vi_mode,
history_filename=os.path.join(data_dir, 'history'),
configure=configure,
user_ns=user_ns,
title='IPython REPL (ptipython)')
startup_paths.append(os.environ["PYTHONSTARTUP"])
# exec scripts from startup paths
for path in startup_paths:
if Path(path).exists():
with Path(path).open("rb") as f:
code = compile(f.read(), path, "exec")
exec(code, self.context, self.context)
else:
print(f"File not found: {path}\n\n")
sys.exit(1)
ipy_config = load_default_config()
ipy_config.InteractiveShellEmbed = ipy_config.TerminalInteractiveShell
ipy_config["InteractiveShellApp"]["extensions"] = self.ipy_extensions
configure_ipython_prompt(ipy_config, prompt=self.prompt, output=self.output)
embed(
config=ipy_config,
configure=configure,
history_filename=config_dir / "history",
user_ns=self.context,
header=self.banner,
vi_mode=self.ptpy_vi_mode,
)
return None
SourceCodeMargin(self),
NumberredMargin(),
],
right_margins=[ScrollbarMargin()],
scroll_offsets=ScrollOffsets(top=2, bottom=2),
height=LayoutDimension(preferred=10))
# Callstack window.
callstack = CallStack(weakref.ref(self))
self.callstack_focussed = False # When True, show cursor there, and allow navigation through it.
self.callstack_selected_frame = 0 # Top frame.
show_pdb_content_filter = ~IsDone() & Condition(
lambda cli: not self.python_input.show_exit_confirmation)
self.python_input = PythonInput(
get_locals=lambda: self.curframe.f_locals,
get_globals=lambda: self.curframe.f_globals,
_completer=DynamicCompleter(lambda: self.completer),
_validator=DynamicValidator(lambda: self.validator),
_accept_action = self._create_accept_action(),
_extra_buffers={'source_code': Buffer(read_only=True)},
_input_buffer_height=LayoutDimension(min=2, max=4),
_lexer=PdbLexer(),
_extra_buffer_processors=[
ConditionalProcessor(
processor=CompletionHint(),
filter=~IsDone())
],
_extra_layout_body=ConditionalContainer(
HSplit([
VSplit([
from ptpython.prompt_style import PromptStyle
from pygments.token import Token
from pygments.lexers import PythonLexer
import linecache
import os
__all__ = (
'PdbPromptStyle',
'CallStack',
'format_stack_entry',
)
class PdbPromptStyle(PromptStyle):
"""
Pdb prompt.
Show "(pdb)" when we have a pdb command or '>>>' when the user types a
Python command.
"""
def __init__(self, pdb_commands):
self.pdb_commands = pdb_commands
def in_tokens(self, cli):
b = cli.buffers[DEFAULT_BUFFER]
command = b.document.text.lstrip()
if command:
command = command.split()[0]
from flask.globals import _app_ctx_stack
from ptpython.repl import embed
app = _app_ctx_stack.top.app
ctx = {}
# Support the regular Python interpreter startup script if someone
# is using it.
startup = os.environ.get('PYTHONSTARTUP')
if startup and os.path.isfile(startup):
with open(startup, 'r') as f:
eval(compile(f.read(), startup, 'exec'), ctx)
ctx.update(app.make_shell_context())
embed(globals=ctx)
def ptpython(cls, local_vars):
from ptpython.repl import embed
embed({}, local_vars)
"""
try:
game = PGZeroGame(mod)
if repl:
import asyncio
from ptpython.repl import embed
loop = asyncio.get_event_loop()
# Make sure the game runs
# NB. if the game exits, the REPL will keep running, which allows
# inspecting final state
game_task = loop.create_task(game.run_as_coroutine())
# Wait for the REPL to exit
loop.run_until_complete(embed(
globals=vars(mod),
return_asyncio_coroutine=True,
patch_stdout=True,
title="Pygame Zero REPL",
configure=configure_repl,
))
# Ask game loop to shut down (if it has not) and wait for it
if game.running:
pygame.event.post(pygame.event.Event(pygame.QUIT))
loop.run_until_complete(game_task)
else:
game.run()
finally:
storage.Storage.save_all()
def main():
embed(globals(), locals(), vi_mode=False)