Comments (2)
Hi @agriyakhetarpal , thank you for opening this issue, and sharing this use case with such level of detail!
I will be happy to look further into this, and right now I only have time to give a few global comments, but this is what came to my mind:
- Thanks for the links, I'll take more time to explore them, indeed JupyterLite is promising and it's really great to see it loading so fast (but I don't know yet how to make it works with Jupytext)
- Is it possible that the code that you want to filter from the notebook would be at a better place somewhere else, e.g. in a Sphinx or a Jupyter Book plugin (if such a concept exists, I am not directly familiar with Sphinx) ?
- In Jupytext we put a strong emphasis on the round trip conversion so there is no option to remove any cell inputs, but...
- I would be happy to help you write a short Python script that removes some specific cells (see below)
- Maybe you could also share your use case with the MyST-NB developers (see also 2. above)
Now re a script that would remove the cells with an "ignore"
tag:
import nbformat
notebook = nbformat.read('notebook_with_an_ignore_tag_in_some_cells.ipynb', as_version=4)
notebook.cells = [cell for cell in notebook.cells if 'ignore' not in cell.metadata.get('tags', [])]
nbformat.write(notebook, 'filtered_notebook.ipynb')
from jupytext.
Hi @agriyakhetarpal , thank you for opening this issue, and sharing this use case with such level of detail!
Thank you for a warm-hearted response to my query, @mwouts!
Thanks for the links, I'll take more time to explore them, indeed JupyterLite is promising and it's really great to see it loading so fast (but I don't know yet how to make it works with Jupytext)
Ah, JupyterLite is most likely embedding the interface for JupyterLab in a web browser, which already supports Jupytext notebooks. The kernel is WASM-powered; that is the difference more or less (I might not be completely correct about this, however).
Is it possible that the code that you want to filter from the notebook would be at a better place somewhere else, e.g. in a Sphinx or a Jupyter Book plugin (if such a concept exists, I am not directly familiar with Sphinx) ?
Maybe you could also share your use case with the MyST-NB developers
It should be possible to include the notebook from a different location or pair up the notebook from elsewhere. However, that would most likely require duplicating the contents of the notebook, and then inserting a cell that contains the directives for it to be able to host the notebook onto the webpage – I do not think that would be trivial. Interacting with the MyST-NB developers would be a good idea, sure!
In Jupytext we put a strong emphasis on the round trip conversion so there is no option to remove any cell inputs, but...
I understand, I didn't think about that aspect at all when writing this even when I knew it – based on that, this feature request could also be a bit out of scope, considering that this is a pretty unique one, haha! Please feel free to close this if you feel so, or keep it open for visibility out of the chance that someone else might need this feature someday.
I would be happy to help you write a short Python script that removes some specific cells (see below)
Now re a script that would remove the cells with an
"ignore"
tag:
I was able to manage loading this short snippet (with a minor change/fix) as a very minimal Sphinx extension coupled with a subprocess – here's a brief in case it would be interesting to other readers:
Tap to expand code
from sphinx.application import Sphinx
from pathlib import Path
HERE = Path(__file__).parent
def preprocess_notebooks(app: Sphinx, *args, **kwargs):
"""Preprocess notebooks to convert them to IPyNB and remove Sphinx directives."""
import subprocess
import sys
import nbformat
print("Converting Markdown files to IPyNB...")
subprocess.check_call(
[
sys.executable,
"-m",
"jupytext",
"--to",
"ipynb",
f"{HERE / '*.md'}",
]
)
for notebook in Path(HERE).glob('*.ipynb'):
print(f"Removing Sphinx directives from {notebook}...")
converted_notebook = nbformat.read(notebook, as_version=4)
converted_notebook.cells = [
cell for cell in converted_notebook.cells
if "true" not in cell.metadata.get("ignore", [])
]
print(f"Removed Sphinx directives from {notebook}.")
nbformat.write(converted_notebook, notebook)
def setup(app):
app.connect("builder-inited", preprocess_notebooks)
and it works perfectly (edit: there is another error, which is unrelated to this process and is more about how the notebooks are copied to the built docs). Thank you!
from jupytext.
Related Issues (20)
- Unable to unpair ipynb in jupyter notebook HOT 7
- Add Galata UI tests for notebook
- Replace toml package with tomli HOT 3
- Panel widget event triggers are not working in py:percent notebooks HOT 2
- Write temporary notebooks to a `TemporaryDirectory` rather than `NamedTemporaryFile`
- feature request: automatic creation of missing notebooks for use after git clone HOT 2
- Using jupytext in a nested project can result in re-import of the current module HOT 2
- Enable the discussions section for the repository HOT 2
- The Jupytext pre-commit hook fails to install when node is not available HOT 2
- Ability to specify jupytext as the viewer via URL HOT 5
- --sync: avoid updating timestamp of *.py if nothing changes HOT 11
- jupytext-config set-default-viewer failing with a miniconda install on Windows 10 HOT 2
- Convert Jupyter Notebooks with R code cells to ```r code cells
- Automatic code cell detection HOT 3
- Jupytext corrupts original notebook with base64 of pair HOT 1
- Allow to provide the output argument when providing multiple files with --set-formats HOT 1
- indented magic commands block all magic commands HOT 1
- jupytext and jupyter lite ? HOT 4
- Add CI workflow to update playwright snapshots automatically
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from jupytext.