| 1 |
# jupyter-cache |
| 2 |
|
| 3 |
[![Github-CI][github-ci]][github-link] |
| 4 |
[![Coverage Status][codecov-badge]][codecov-link] |
| 5 |
[![Documentation Status][rtd-badge]][rtd-link] |
| 6 |
[![Code style: black][black-badge]][black-link] |
| 7 |
[![PyPI][pypi-badge]][pypi-link] |
| 8 |
|
| 9 |
A defined interface for working with a cache of jupyter notebooks. |
| 10 |
|
| 11 |
## Why use jupyter-cache? |
| 12 |
|
| 13 |
If you have a number of notebooks whose execution outputs you want to ensure are kept up to date, without having to re-execute them every time (particularly for long running code, or text-based formats that do not store the outputs). |
| 14 |
|
| 15 |
The notebooks must have deterministic execution outputs: |
| 16 |
|
| 17 |
- You use the same environment to run them (e.g. the same installed packages) |
| 18 |
- They run no non-deterministic code (e.g. random numbers) |
| 19 |
- They do not depend on external resources (e.g. files or network connections) that change over time |
| 20 |
|
| 21 |
For example, it is utilised by [jupyter-book](https://jupyterbook.org/content/execute.html#caching-the-notebook-execution), to allow for fast document re-builds. |
| 22 |
|
| 23 |
## Install |
| 24 |
|
| 25 |
```bash |
| 26 |
pip install jupyter-cache |
| 27 |
``` |
| 28 |
|
| 29 |
For development: |
| 30 |
|
| 31 |
```bash |
| 32 |
git clone https://github.com/executablebooks/jupyter-cache |
| 33 |
cd jupyter-cache |
| 34 |
git checkout develop |
| 35 |
pip install -e .[cli,code_style,testing] |
| 36 |
``` |
| 37 |
|
| 38 |
See the documentation for usage. |
| 39 |
|
| 40 |
## Development |
| 41 |
|
| 42 |
Some desired requirements (not yet all implemented): |
| 43 |
|
| 44 |
- Persistent |
| 45 |
- Separates out "edits to content" from "edits to code cells". Cell |
| 46 |
rearranges and code cell changes should require a re-execution. Content changes should not. |
| 47 |
- Allow parallel access to notebooks (for execution) |
| 48 |
- Store execution statistics/reports |
| 49 |
- Store external assets: Notebooks being executed often require external assets: importing scripts/data/etc. These are prepared by the users. |
| 50 |
- Store execution artefacts: created during execution |
| 51 |
- A transparent and robust cache invalidation: imagine the user updating an external dependency or a Python module, or checking out a different git branch. |
| 52 |
|
| 53 |
## Contributing |
| 54 |
|
| 55 |
jupyter-cache follows the [Executable Book Contribution Guide](https://executablebooks.org/en/latest/contributing.html). We'd love your help! |
| 56 |
|
| 57 |
### Code Style |
| 58 |
|
| 59 |
Code style is tested using [flake8](http://flake8.pycqa.org), |
| 60 |
with the configuration set in `.flake8`, |
| 61 |
and code formatted with [black](https://github.com/ambv/black). |
| 62 |
|
| 63 |
Installing with `jupyter-cache[code_style]` makes the [pre-commit](https://pre-commit.com/) |
| 64 |
package available, which will ensure this style is met before commits are submitted, by reformatting the code |
| 65 |
and testing for lint errors. |
| 66 |
It can be setup by: |
| 67 |
|
| 68 |
```shell |
| 69 |
>> cd jupyter-cache |
| 70 |
>> pre-commit install |
| 71 |
``` |
| 72 |
|
| 73 |
Optionally you can run `black` and `flake8` separately: |
| 74 |
|
| 75 |
```shell |
| 76 |
>> black . |
| 77 |
>> flake8 . |
| 78 |
``` |
| 79 |
|
| 80 |
Editors like VS Code also have automatic code reformat utilities, which can adhere to this standard. |
| 81 |
|
| 82 |
[github-ci]: https://github.com/executablebooks/jupyter-cache/workflows/continuous-integration/badge.svg?branch=master |
| 83 |
[github-link]: https://github.com/executablebooks/jupyter-cache |
| 84 |
[codecov-badge]: https://codecov.io/gh/executablebooks/jupyter-cache/branch/master/graph/badge.svg |
| 85 |
[codecov-link]: https://codecov.io/gh/executablebooks/jupyter-cache |
| 86 |
[rtd-badge]: https://readthedocs.org/projects/jupyter-cache/badge/?version=latest |
| 87 |
[rtd-link]: https://jupyter-cache.readthedocs.io/en/latest/?badge=latest |
| 88 |
[black-badge]: https://img.shields.io/badge/code%20style-black-000000.svg |
| 89 |
[pypi-badge]: https://img.shields.io/pypi/v/jupyter-cache.svg |
| 90 |
[pypi-link]: https://pypi.org/project/jupyter-cache |
| 91 |
[black-link]: https://github.com/ambv/black |