Package: watchmagic
watchmagicadds%%watchmagic to IPython. When added to a cell, it
watches a given directory for file changes. Once a file is changed, the cell is
re-evaluated.watchmagic’s real power lies in combining it with%autoreloadwhich
allows to edit code in an external editor while watching the changes in a
notebook in real-time on every save.LicenseCopyright 2020 Gunnar Voetwatchmagicis free software: you can redistribute it and/or modify it under
the terms of the GNU Lesser General Public License as published by the Free
Software Foundation, either version 3 of the License, or any later version.watchmagicis distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
details.You should have received a copy of the GNU Lesser General Public License along
withwatchmagic.  If not, see <http://www.gnu.org/licenses/>.InstallationInstall viapip:pipinstallwatchmagicUsageIn the notebook run%load_extwatchmagicNow you can use the magic by simply putting%%watchon the first line of the
cell you are working on. This will watch the current directory and its
subdirectories for file changes. For example:%%watchprint('hello world')will watch the current directory and run the print statement on any file
changes. Interrupt the kernel to quit watching for file changes.To make the magic available by default, addwatchmagicto youripython_config.py:c.InteractiveShellApp.extensions=['watchmagic']Note that this is not the jupyter config file, but it will work in jupyter
notebooks.The real power of the%%watchmagic lies in combining it with IPython’s%autoreloadmagic. It allows to develop code in an external editor while
watching the results in real time on every file save. For example, if working
on the new functionoverview_plot()in the packagescience_plots, runnig
the following in a jupyter notebook will provide a real time view of the
results:importscience_plots%load_extautoreload%autoreload2# reload all packages%load_extwatchmagic%%watch--ignore*.ipynbscience_plots.overview_plot()Note that here we are watching the current directory by default, soscience_plotsmust be either in the local directory or one of its
subdirectories.%%watchwill also ignore changes in jupyter notebook files
such that theoverview_plot()is not run when the notebook is saved (and no
changes have ocurred in the source code).OptionsSeveral command line options exist. Run%%watch?to display the following
help screen:%watch [-p PATH] [-r] [-nr]
            [--patterns [PATTERNS [PATTERNS ...]]]
            [--ignore [IGNORE_PATTERNS [IGNORE_PATTERNS ...]]]

Watch for file changes and re-evaluate current cell.

optional arguments:
-p PATH, --path PATH  provides the PATH to watch for file changes. If
                        not provided, the current directory will be
                        watched.
-r, --recursive       include subdirectories recursively when
                        watching for file changes. This is the default
                        behaviour.
-nr, --non-recursive  do not include subdirectories when watching for
                        file changes.
--patterns <[PATTERNS [PATTERNS ...]]>
                        look for files with these PATTERNS.
--ignore <[IGNORE_PATTERNS [IGNORE_PATTERNS ...]]>
                        ignore files containing IGNORE_PATTERNS when
                        watching for file changes.ConfigThe following default settings can be changed inipython_config.py:#---------------------------------------------------------------
# WatchMagics configuration
#---------------------------------------------------------------
c.WatchMagics.default_patterns = ['*.py']
c.WatchMagics.default_ignore_patterns = ['*.ipynb']
c.WatchMagics.default_case_sensitive = False
c.WatchMagics.default_ignore_directories = TrueCommand line options (if provided) will override the default settings.History0.1.1 (2020-06-20)Fix bug in dist build.0.1.0 (2020-06-18)Initial release.