Inheritance diagram for IPython.core.magics.script:
Magic functions for running cells in various scripts.
Bases: IPython.core.magic.Magics, IPython.config.configurable.Configurable
Magics for talking to scripts
This defines a base %%script cell magic for running a cell with a program in a subprocess, and registers a few top-level magics that call %%script with common interpreters.
Print docstring if incorrect arguments were passed
Get the config class config section
Get the help string for this class in ReST format.
If inst is given, it’s current trait values will be used in place of class defaults.
Get the help string for a single trait.
If inst is given, it’s current trait values will be used in place of the class default.
Get the help string for a single trait and print it.
Get a list of all the names of this classes traits.
This method is just like the trait_names() method, but is unbound.
Get a list of all the traits of this class.
This method is just like the traits() method, but is unbound.
The TraitTypes returned don’t know anything about the values that the various HasTrait’s instances are holding.
This follows the same algorithm as traits does and does not allow for any simple way of specifying merely that a metadata name exists, but has any value. This is because get_metadata returns None if a metadata key doesn’t exist.
A trait whose value must be an instance of a specified class.
The value can also be an instance of a subclass of the specified class.
Make an entry in the options_table for fn, with value optstr
Format a string for latex inclusion.
Kill all BG processes which are still running.
Kill all BG processes started by %%script and its family.
Setup a handler to be called when a trait changes.
This is used to setup dynamic notifications of trait changes.
Static handlers can be created by creating methods on a HasTraits subclass with the naming convention ‘_[traitname]_changed’. Thus, to create static handler for the trait ‘a’, create the method _a_changed(self, name, old, new) (fewer arguments can be used, see below).
Parameters : | handler : callable
name : list, str, None
remove : bool
|
---|
Parse options passed to an argument string.
The interface is similar to that of getopt(), but it returns back a Struct with the options as keys and the stripped argument string still as a string.
arg_str is quoted as a true sys.argv vector by using shlex.split. This allows us to easily expand variables, glob files, quote arguments, etc.
-mode: default ‘string’. If given as ‘list’, the argument string is returned as a list (split on whitespace) instead of a string.
-list_all: put all option values in lists. Normally only options appearing more than once are put in a list.
-posix (True): whether to split the input line in POSIX mode or not, as per the conventions outlined in the shlex module from the standard library.
An instance of a Python list.
An instance of a Python dict.
%shebang [–proc PROC] [–bg] [–err ERR] [–out OUT]
Run a cell via a shell command
The %%script line is like the #! line of script, specifying a program (bash, perl, ruby, etc.) with which to run.
The rest of the cell is run by that program.
Examples
In [1]: %%script bash
...: for i in 1 2 3; do
...: echo $i
...: done
1
2
3
--proc PROC | The variable in which to store Popen instance. This is used only when –bg option is given. |
--bg | Whether to run the script in the background. If given, the only way to see the output of the command is with –out/err. |
--err ERR | The variable in which to store stderr from the script. If the script is backgrounded, this will be the stderr pipe, instead of the stderr text itself. |
--out OUT | The variable in which to store stdout from the script. If the script is backgrounded, this will be the stdout pipe, instead of the stderr text itself. |
Get metadata values for trait by key.
Get a list of all the names of this classes traits.
Get a list of all the traits of this class.
The TraitTypes returned don’t know anything about the values that the various HasTrait’s instances are holding.
This follows the same algorithm as traits does and does not allow for any simple way of specifying merely that a metadata name exists, but has any value. This is because get_metadata returns None if a metadata key doesn’t exist.
Fire the traits events when the config is updated.
single decorator for adding script args