Converts .ipynb into .py and vice-versa
Project description
vs_nb
Is a Python package that saves .ipynb as a .py and vice-versa in VS Code.
This is needed because currently the VS Code jupytext extension is broken and the standard jupytext library does not work with VS Code notebooks.
A working jupytext extension would be preferred because this package needs to be run manually in a .ipynb cell or an interactive .py cell (# %% syntax) to convert them, rather than happening after every save. You also need to manually type the name of the file into the convert function, rather than it picking it up automatically.
Installation
Use pip to install vs_nb from PyPi
pip install vs-nb
or from GitHub
pip install git+https://github.com/JamesHuckle/vs-nb.git
Usage
#Inside a .ipynb cell or .py file that is named "test"
from vs_nb import convert
convert(file_prefix='test', is_py='__file__' in globals())
(Recommendation)
Set up autosave on VS Code because it does not currently alert when an file open in a tab has been modified on disk (by vs-nb) until you attempt to save it, meaning you could be working on a stale file without knowing it!
To activate autosave put this in your settings.json file in VS Code and restart VS Code.
"files.autoSave": "onFocusChange",
Example Bug:
- Open
.ipynband runconvertfunction to build a.py - Make changes to
.ipynbin a VS Code tab but do not save. - Open the .py, make changes, save it, and run convert to build
.ipynb. - Navigating back to the
.ipynbin the VS Code tab will result in no warning that the.ipynbhas just been modified, instead it displays the old unsaved changes.
Contributing
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
License
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file vs-nb-0.5.0.tar.gz.
File metadata
- Download URL: vs-nb-0.5.0.tar.gz
- Upload date:
- Size: 3.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.26.0 requests-toolbelt/0.9.1 urllib3/1.26.7 tqdm/4.62.3 importlib-metadata/4.8.1 keyring/23.1.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d60e7b3004b4aae9d4868e952551b44e0d1cb96f219a4b37cee17f9cc8d89717
|
|
| MD5 |
0598c08239ae490b2ed91975fa73cab3
|
|
| BLAKE2b-256 |
4aafa98daad4d6e6f3e9af72b13691e900363ec892c0f5cb0cc85b3e4330902b
|