Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main'
Browse files Browse the repository at this point in the history
  • Loading branch information
firezym committed Nov 28, 2023
2 parents e15657d + 311c869 commit a13c1d4
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 15 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 0.1.2 2023 Nov 27

- expose command `split-cell-to-gridwidth` to convert notebooks

## 0.1.1 2023 Nov 27

- initial release
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,15 @@ there is no button (yet) in this extension to do the equivalent of the former 's
- or command `gridwidth:toggle-1-2`
- that you can bind to a keyboard shortcut of your choice

### to convert your notebooks

```bash
split-cell-to-gridwidth notebook1 .. notebookN
```

will replace the old `cell_style: split` with the new `gridwidth-1-2` tag in all
notebooks passed as arguments

### palette commands

- `gridwidth:toggle-1-2` and so on
Expand Down
39 changes: 39 additions & 0 deletions jupyterlab_gridwidth/splitcell_to_gridwidth.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
"""
a command line tool for en masse migration of notebooks
from the former classic notebook extension 'splitcell' to
the new JupyterLab extension 'gridwidth'
limitations: this assumes jupytext
"""

from argparse import ArgumentParser

import jupytext


def migrate_notebook(notebook):
print(f'migrating {notebook}')
with open(notebook, 'r') as f:
incoming = jupytext.read(f)
for cell in incoming['cells']:
if cell.get('metadata', {}).get('cell_style', None) == 'split':
del cell['metadata']['cell_style']
if 'tags' not in cell['metadata']:
cell['metadata']['tags'] = []
cell['metadata']['tags'].append('gridwidth-1-2')
# rewrite in same location
jupytext.write(incoming, notebook)


def main():
parser = ArgumentParser(
description='migrate notebooks from (classic)-splitcell to (lab)-gridwidth')
parser.add_argument('notebooks', nargs='+', help='notebooks to migrate')
args = parser.parse_args()
for notebook in args.notebooks:
migrate_notebook(notebook)
return 0


if __name__ == '__main__':
exit(main())
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "jupyterlab-gridwidth",
"version": "0.1.1",
"version": "0.1.2",
"description": "Jlab extension for showing course levels and structure",
"keywords": [
"jupyter",
Expand Down
20 changes: 6 additions & 14 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,16 @@ readme = "README.md"
license = { file = "LICENSE" }
requires-python = ">=3.8"
classifiers = [
"Framework :: Jupyter",
"Framework :: Jupyter :: JupyterLab",
"Framework :: Jupyter :: JupyterLab :: 4",
"Framework :: Jupyter :: JupyterLab :: Extensions",
"Framework :: Jupyter :: JupyterLab :: Extensions :: Prebuilt",
"License :: OSI Approved :: BSD License",
"Programming Language :: Python",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
]
dependencies = [
'jupyterlab-celltagsclasses',
"Framework :: Jupyter :: JupyterLab :: Extensions :: Prebuilt",
]
dependencies = ['jupyterlab-celltagsclasses']
dynamic = ["version", "description", "authors", "urls", "keywords"]

[project.scripts]
splitcell-to-gridwidth = "jupyterlab_gridwidth.splitcell_to_gridwidth:main"

[tool.hatch.version]
source = "nodejs"

Expand Down Expand Up @@ -69,7 +61,7 @@ version_cmd = "hatch version"
before-build-npm = [
"python -m pip install 'jupyterlab>=4.0.0,<5'",
"jlpm",
"jlpm build:prod"
"jlpm build:prod",
]
before-build-python = ["jlpm clean:all"]

Expand Down

0 comments on commit a13c1d4

Please sign in to comment.