_interactive module
- class pyflyby._interactive.AutoImporter(arg=Ellipsis)
Auto importer enable state.
The state is attached to an IPython “application”.
- _advise(joinpoint)
-
_ast_transformer:
Any
-
_autoimported_this_cell:
Dict
[Any
,Any
]
- classmethod _construct(app)
Create a new AutoImporter for
app
.
- _continue_enable()
-
_disablers:
List
[Any
]
- _enable_ast_hook(ip)
Enable a hook somewhere in the source => parsed AST => compiled code pipeline.
- _enable_completer_hooks(completer)
- _enable_completion_hook(ip)
Enable a tab-completion hook.
- _enable_debugger_hook(ip)
- _enable_initializer_hooks(app)
- _enable_internal()
- _enable_ipython_shell_bugfixes(ip)
Enable some advice that’s actually just fixing bugs in IPython.
- _enable_kernel_manager_hook(app)
- _enable_ofind_hook(ip)
Enable a hook of _ofind(), which is used for pinfo, autocall, etc.
- _enable_prun_hook(ip)
Enable a hook so that %prun will autoimport.
- _enable_reset_hook(ip)
- _enable_run_hook(ip)
Enable a hook so that %run will autoimport.
- _enable_shell_hooks(app)
Enable hooks to run auto_import before code execution.
- _enable_start_kernel_hook(kernel_manager)
- _enable_time_hook(ip)
Enable a hook so that %time will autoimport.
- _enable_timeit_hook(ip)
Enable a hook so that %timeit will autoimport.
-
_errored:
bool
- classmethod _from_app(app)
- Return type:
-
_ip:
Any
- _safe_call(function, *args, **kwargs)
-
_state:
_EnableState
-
app:
Any
- auto_import(arg, namespaces=None, raise_on_error='if_debug', on_error=None)
- compile_with_autoimport(src, filename, mode, flags=0)
- complete_symbol(fullname, namespaces, raise_on_error='if_debug', on_error=None)
-
db:
ImportDB
- disable()
Turn off auto-importer in the current IPython session.
- enable(even_if_previously_errored=False)
Turn on the auto-importer in the current IPython session.
- reset_state_new_cell()
- pyflyby._interactive.InterceptPrintsDuringPromptCtx(ip)
Decorator that hooks our logger so that:
1. Before the first print, if any, print an extra newline. 2. Upon context exit, if any lines were printed, redisplay the prompt.
- exception pyflyby._interactive.NoActiveIPythonAppError
Exception raised when there is no current IPython application instance.
- exception pyflyby._interactive.NoIPythonPackageError
Exception raised when the IPython package is not installed in the system.
- pyflyby._interactive.UpdateIPythonStdioCtx()
Context manager that updates IPython’s cached stdin/stdout/stderr handles to match the current values of sys.stdin/sys.stdout/sys.stderr.
- class pyflyby._interactive._DummyIPythonEmbeddedApp(shell)
Small wrapper around an InteractiveShellEmbed.
- class pyflyby._interactive._EnableState
- DISABLED = 'DISABLED'
- DISABLING = 'DISABLING'
- ENABLED = 'ENABLED'
- ENABLING = 'ENABLING'
- pyflyby._interactive._app_is_initialized(app)
Return whether
app.initialize()
has been called.- Return type:
bool
- pyflyby._interactive._auto_import_in_pdb_frame(pdb_instance, arg)
- pyflyby._interactive._enable_pdb_hooks(pdb_instance)
- pyflyby._interactive._enable_terminal_pdb_hooks(pdb_instance, auto_importer=None)
- pyflyby._interactive._generate_enabler_code()
Generate code for enabling the auto importer.
- Return type:
str
- pyflyby._interactive._get_IPdb_class()
Get the IPython (core) Pdb class.
- pyflyby._interactive._get_TerminalPdb_class()
Get the IPython TerminalPdb class.
- pyflyby._interactive._get_ipython_app()
Get an IPython application instance, if we are inside an IPython session.
If there isn’t already an IPython application, raise an exception; don’t create one.
If there is a subapp, return it.
- Return type:
BaseIPythonApplication or an object that mimics some of its behavior
- pyflyby._interactive._get_ipython_color_scheme(app)
Get the configured IPython color scheme.
- Parameters:
app (TerminalIPythonApp) – An initialized IPython terminal application.
- Return type:
str
- pyflyby._interactive._get_or_create_ipython_kernel_app()
Create/get the singleton IPython kernel application.
- Return type:
callable
- Returns:
The function that can be called to start the kernel application.
- pyflyby._interactive._get_or_create_ipython_terminal_app()
Create/get the singleton IPython terminal application.
- Return type:
TerminalIPythonApp
- Raises:
NoIPythonPackageError – IPython is not installed in the system.
- pyflyby._interactive._get_pdb_if_is_in_pdb()
Return the current Pdb instance, if we’re currently called from Pdb.
- Return type:
pdb.Pdb
orNoneType
- pyflyby._interactive._initialize_and_start_app_with_autoimporter(app, argv)
Initialize and start an IPython app, with autoimporting enabled.
- pyflyby._interactive._install_in_ipython_config_file_40()
Implementation of install_in_ipython_config_file for IPython 4.0+.
- pyflyby._interactive._ipython_in_multiline(ip)
Return
False
if the user has entered only one line of input so far, including the current line, orTrue
if it is the second or later line.- Return type:
bool
- pyflyby._interactive._ipython_namespaces(ip)
Return the (global) namespaces used for IPython.
The ordering follows IPython convention of most-local to most-global.
- Return type:
list
- Returns:
List of (name, namespace_dict) tuples.
- pyflyby._interactive._list_members_for_completion(obj, ip)
Enumerate the existing member attributes of an object. This emulates the regular Python/IPython completion items.
It does not include not-yet-imported submodules.
- Parameters:
obj – Object whose member attributes to enumerate.
- Return type:
list
ofstr
- pyflyby._interactive._python_can_import_pyflyby(expected_path, sys_path_entry=None)
Try to figure out whether python (when started from scratch) can get the same pyflyby package as the current process.
- pyflyby._interactive._skip_frames(frame, ignore_pkgs)
- pyflyby._interactive.complete_symbol(fullname, namespaces, db=None, autoimported=None, ip=None, allow_eval=False)
Enumerate possible completions for
fullname
.Includes globals and auto-importable symbols.
>>> complete_symbol("threadi", [{}]) [...'threading'...]
Completion works on attributes, even on modules not yet imported - modules are auto-imported first if not yet imported:
>>> ns = {} >>> complete_symbol("threading.Threa", namespaces=[ns]) [PYFLYBY] import threading ['threading.Thread', 'threading.ThreadError'] >>> 'threading' in ns True >>> complete_symbol("threading.Threa", namespaces=[ns]) ['threading.Thread', 'threading.ThreadError']
We only need to import parent modules (packages) of the symbol being completed. If the user asks to complete “foo.bar.quu<TAB>”, we need to import foo.bar, but we don’t need to import foo.bar.quux.
- Parameters:
fullname (
str
) – String to complete. (“Full” refers to the fact that it should contain dots starting from global level.)namespaces (
dict
orlist
ofdict
) – Namespaces of (already-imported) globals.db (importDB) – Import database to use.
ip (
InteractiveShell
) – IPython shell instance if in IPython;None
to assume not in IPython.allow_eval – Whether to allow evaluating code, which is necessary to allow completing e.g. ‘foo[0].bar<TAB>’ or ‘foo().bar<TAB>’. Note that IPython will only pass such strings if IPCompleter.greedy is configured to True by the user.
- Return type:
list
ofstr
- Returns:
Completion candidates.
- pyflyby._interactive.get_global_namespaces(ip)
Get the global interactive namespaces.
- Parameters:
ip (
InteractiveShell
) – IPython shell orNone
to assume not in IPython.- Return type:
list
ofdict
- pyflyby._interactive.get_ipython_terminal_app_with_autoimporter()
Return an initialized
TerminalIPythonApp
.If a
TerminalIPythonApp
has already been created, then use it (whether we are inside that app or not). If there isn’t already one, then create one. Enable the auto importer, if it hasn’t already been enabled. If the app hasn’t been initialized yet, then initialize() it (but don’t start() it).- Return type:
TerminalIPythonApp
- Raises:
NoIPythonPackageError – IPython is not installed in the system.
- pyflyby._interactive.new_IPdb_instance()
Create a new Pdb instance.
If IPython is available, then use IPython’s Pdb. Initialize a new IPython terminal application if necessary.
If the IPython package is not installed in the system, then use regular Pdb.
Enable the auto importer.
- Return type:
Pdb
- pyflyby._interactive.print_verbose_tb(*exc_info)
Print a traceback, using IPython’s ultraTB if possible.
- Parameters:
exc_info – 3 arguments as returned by sys.exc_info().
- pyflyby._interactive.run_ipython_line_magic(arg)
Run IPython magic command. If necessary, start an IPython terminal app to do so.
- pyflyby._interactive.start_ipython_kernel_with_autoimporter(argv=None)
Start IPython kernel with autoimporter enabled.
- pyflyby._interactive.start_ipython_with_autoimporter(argv=None, app=None, _user_ns=None)
Start IPython (terminal) with autoimporter enabled.