module documentation

Tools for jupyter/ipython-style notebooks, and detection that you are, or are _not_, using one right now.

Class etree_visualize_selection Produces a colorized representation of selection within an XML document. (works only within IPython/jupyter style notebooks, via a HTML representation.)
Class ProgressBar A sequence-iterating progress bar (like tqdm) that supports both notebooks and console, and prefers notebook over console style in notebooks.
Function detect_env Use this to detect what kind of environment the calling code is running in.
Function is_interactive returns whether we are using an interactive thing (see detect_env)
Function is_ipython returns whether IPython is available (see detect_env) - note that you might want to combine this with is_interactive (depending on what you are really testing )
Function is_ipython_interactive return whether this seems to be interactive in the REPL-like sense (is_ipython and is_interactive)
Function is_notebook returns whether we are running in a notebook (see detect_env)
Function progress_bar A progress bar that should work in notebooks -- but also outside them if you have tqdm installed
Function set_proctitle Might throw an exception, e.g. an ImportError'
def detect_env():

Use this to detect what kind of environment the calling code is running in.

Returns a dict with keys that map to booleans:

  • 'interactive' - whether it's interactive (e.g. regular python REPL, ipython REPL, notebook, or qtconsole)
  • 'notebook' - whether it's a notebook (also including colab, qtconsole)
  • 'ipython' - whether IPython is available (note this will also return True if the module just happens to be installed and available)

(when we see pytest, we fake all False, because that's probably closer -- probably better than noticing the IPython that pytest seems to mock)

def is_interactive():

returns whether we are using an interactive thing (see detect_env)

def is_ipython():

returns whether IPython is available (see detect_env) - note that you might want to combine this with is_interactive (depending on what you are really testing )

def is_ipython_interactive():

return whether this seems to be interactive in the REPL-like sense (is_ipython and is_interactive)

def is_notebook():

returns whether we are running in a notebook (see detect_env)

def progress_bar(maxval, description='', display=True):

A progress bar that should work in notebooks -- but also outside them if you have tqdm installed

More precisely:

  • wraps tqdm and ipywidgets's IntProgress progress bar;
  • prefers tqdm if installed, falls back to IntProgress.

CONSIDER: parameter to force text mode

Compared to ProgressBar, this one is more typing but also does a little more, letting you set (and get) .value and .description on the fly, so e.g. usable like:

    prog = progress_bar( 10, 'overall' )
    for i in range(10):
        prog.value += 1
        time.sleep(1)
    prog.description = 'finished'
Parameters
maxvalmaximum value to count towards (required)
descriptiontext to also show in the progress bar
displayif True, (default), then in a notebook we will call display() on the IPython widget, so you don't have to do so to get it visible.
Returns
an object representing a progress bar, that you can set the .value and .description on.
def set_proctitle(proctitle='wetsuite-notebook'):

Might throw an exception, e.g. an ImportError'