-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'upstream/main'
- Loading branch information
Showing
5 changed files
with
59 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters