nteract / hydrogen

:atom: Run code interactively, inspect data, and plot. All the power of Jupyter kernels, inside your favorite text editor.
https://nteract.gitbooks.io/hydrogen/
MIT License
3.92k stars 334 forks source link

ability to define watchers in source #614

Open nils-werner opened 7 years ago

nils-werner commented 7 years ago

It would be really nice to, instead of adding them manually using the GUI, add watchers in the source code, similar to how you can add code cells in the source code. e.g.:

# %%
%reload_ext autoreload
%autoreload 2
%matplotlib inline

import numpy
import matplotlib.pyplot as plt

data = numpy.random.rand(3, 3)

#watch: plt.show(data)

This has been added to the Hydrogen Wiki Plugins. If you close this issue please remove it from the Hydrogen Wiki.

lgeiger commented 7 years ago

Definitely a interesting idea though not trivial.

Could you elaborate a bit more? What would the desired workflow be? My first thought is, when should the file be parsed for possible watch statements?

nils-werner commented 7 years ago

The idea is to have different watchers in different cells and files and to show them accordingly whenever you execute a cell

E.g. if you need to work on a different project or go home for the day, the next day all your watchers are gone. Or you switch between two cells and need to manually change watchers every time you do.

It is probably non-trivial to add or even replace watchers when you execute a different cell.

BenRussert commented 7 years ago

I think this could be doable as a "macro" that adds watches based on some addition to the # %% cell methodology. This seems like a great idea for a hydrogen plugin so that it can be used/maintained by those who desire the feature (including me).

I have a minimal concept implemented as a hydrogen plugin, but it requires a small change to hydrogen's watch module. I'll try to post more on this soon.

My first thought is, when should the file be parsed for possible watch statements?

@lgeiger I was thinking as part of run-cell, but modified by a method inside the mentioned plugin.