https://github.com/bdice/nb-strip-paths
Parse Jupyter notebook cell outputs and replace user paths "/home/user/..." with links relative to the project root.
https://github.com/bdice/nb-strip-paths
Last synced: about 1 year ago
JSON representation
Parse Jupyter notebook cell outputs and replace user paths "/home/user/..." with links relative to the project root.
- Host: GitHub
- URL: https://github.com/bdice/nb-strip-paths
- Owner: bdice
- License: mit
- Created: 2021-02-09T21:11:58.000Z (over 5 years ago)
- Default Branch: main
- Last Pushed: 2021-02-26T19:03:06.000Z (over 5 years ago)
- Last Synced: 2025-02-13T18:35:23.504Z (over 1 year ago)
- Language: Python
- Size: 27.3 KB
- Stars: 4
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# nb-strip-paths
This is a pre-commit hook that strips user paths from Jupyter notebooks. For example:
```
# When executing from a repository "my_awesome_code"
/home/bdice/my_awesome_code/some_directory/file.txt
# becomes...
some_directory/file.txt
```
This makes cleaner (and safer) examples for projects with tutorials that deal with filesystems and must print absolute paths.
Created for use with [signac-examples](https://github.com/glotzerlab/signac-examples).
Much of this project's code is copied from *nbqa* under the MIT license. [nbqa](https://github.com/nbQA-dev/nbQA/tree/master/nbqa) is a wonderful tool for using Python linters/formatters with Jupyter notebooks, and I strongly recommend trying it!
## Usage
Add this snippet to `.pre-commit-config.yaml`:
```yaml
- repo: https://github.com/bdice/nb-strip-paths
rev: 'v0.1.0'
hooks:
- id: nb-strip-paths
```
## Tests
The tests require [nbconvert](https://github.com/jupyter/nbconvert) and [nbstripout](https://github.com/kynan/nbstripout).
For now, there is only a regression test. The output must be verified manually for correctness if committing changes to the test file.
To run the tests, execute:
```bash
cd tests
./run_tests.sh
```
If the test notebook is updated, execute:
```bash
cd tests
./generate_reference_notebooks.sh
```
and verify the notebook looks correct before committing.