fix: remove id field in notebook cells created by nbformat, thereby increasing compatibility with different jupyter versions#3767
Conversation
📝 WalkthroughWalkthroughAdded module-level constant Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Pre-merge checks and finishing touches❌ Failed checks (3 warnings)
✨ Finishing touches
🧪 Generate unit tests
📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (44)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
Please format your code with black: |
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (1)
src/snakemake/notebook.py (1)
142-142: LGTM—also strip “id” from the default code cell in draft()
The cell created at line 39 vianbformat.v4.new_code_cell("# start coding here")may include an"id"field in its metadata—assign it to a variable, callpop("id", None), then append.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
src/snakemake/notebook.py(1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
**/*.py
⚙️ CodeRabbit configuration file
**/*.py: Do not try to improve formatting.
Do not suggest type annotations for functions that are defined inside of functions or methods.
Do not suggest type annotation of theselfargument of methods.
Do not suggest type annotation of theclsargument of classmethods.
Do not suggest return type annotation if a function or method does not contain areturnstatement.
Files:
src/snakemake/notebook.py
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (45)
- GitHub Check: tests (10, macos-latest, py313)
- GitHub Check: tests (10, ubuntu-latest, py311)
- GitHub Check: tests (10, ubuntu-latest, py312)
- GitHub Check: tests (9, ubuntu-latest, py312)
- GitHub Check: tests (9, windows-2022, py313)
- GitHub Check: tests (8, ubuntu-latest, py313)
- GitHub Check: tests (10, ubuntu-latest, py313)
- GitHub Check: tests (10, windows-2022, py313)
- GitHub Check: tests (9, ubuntu-latest, py311)
- GitHub Check: tests (8, windows-2022, py313)
- GitHub Check: tests (8, ubuntu-latest, py311)
- GitHub Check: tests (8, ubuntu-latest, py312)
- GitHub Check: tests (9, ubuntu-latest, py313)
- GitHub Check: tests (7, ubuntu-latest, py313)
- GitHub Check: tests (6, windows-2022, py313)
- GitHub Check: tests (4, windows-2022, py313)
- GitHub Check: tests (6, ubuntu-latest, py313)
- GitHub Check: tests (4, ubuntu-latest, py313)
- GitHub Check: tests (3, ubuntu-latest, py312)
- GitHub Check: tests (6, ubuntu-latest, py311)
- GitHub Check: tests (5, ubuntu-latest, py313)
- GitHub Check: tests (7, ubuntu-latest, py312)
- GitHub Check: tests (7, windows-2022, py313)
- GitHub Check: tests (7, ubuntu-latest, py311)
- GitHub Check: tests (5, ubuntu-latest, py312)
- GitHub Check: tests (6, ubuntu-latest, py312)
- GitHub Check: tests (5, ubuntu-latest, py311)
- GitHub Check: tests (5, windows-2022, py313)
- GitHub Check: tests (3, macos-latest, py313)
- GitHub Check: tests (4, ubuntu-latest, py311)
- GitHub Check: tests (2, windows-2022, py313)
- GitHub Check: tests (4, ubuntu-latest, py312)
- GitHub Check: tests (3, ubuntu-latest, py313)
- GitHub Check: tests (3, windows-2022, py313)
- GitHub Check: tests (2, macos-latest, py313)
- GitHub Check: tests (3, ubuntu-latest, py311)
- GitHub Check: tests (2, ubuntu-latest, py312)
- GitHub Check: tests (1, macos-latest, py313)
- GitHub Check: tests (2, ubuntu-latest, py311)
- GitHub Check: tests (1, windows-2022, py313)
- GitHub Check: tests (2, ubuntu-latest, py313)
- GitHub Check: tests (1, ubuntu-latest, py312)
- GitHub Check: tests (1, ubuntu-latest, py311)
- GitHub Check: tests (1, ubuntu-latest, py313)
- GitHub Check: apidocs
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (2)
src/snakemake/notebook.py (2)
23-28: Consider standardizing version handling inget_cell_sources.The
get_cell_sourcesfunction usesnbformat.NO_CONVERTwhen reading notebooks (line 26), while other read operations in this file now useas_version=NBFORMAT_VERSION.For consistency with the standardization effort in this PR, consider whether this function should also use
as_version=NBFORMAT_VERSION. IfNO_CONVERTis intentional here (to preserve the original notebook version structure), this is acceptable, but it creates an inconsistency.If consistency is desired, apply this diff:
def get_cell_sources(source): import nbformat - nb = nbformat.reads(source, as_version=nbformat.NO_CONVERT) + nb = nbformat.reads(source, as_version=NBFORMAT_VERSION) return [cell["source"] for cell in nb["cells"]]
20-21: Consider backwards compatibility with existing notebooks.Forcing all notebooks to version 5 might cause issues when reading notebooks created with older nbformat versions. While
as_version=NBFORMAT_VERSIONwill convert on read, this could potentially alter the notebook structure in unexpected ways for users with legacy notebooks.Consider documenting this change and its implications for users with existing notebooks, or provide a migration path if needed.
Consider adding a comment explaining the version choice and its implications:
+# nbformat version to use for all notebook I/O operations. +# Version 5 is used to ensure compatibility with modern Jupyter versions. +# Note: Notebooks in older formats will be automatically converted on read. NBFORMAT_VERSION = 5
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
src/snakemake/notebook.py(5 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
**/*.py
⚙️ CodeRabbit configuration file
**/*.py: Do not try to improve formatting.
Do not suggest type annotations for functions that are defined inside of functions or methods.
Do not suggest type annotation of theselfargument of methods.
Do not suggest type annotation of theclsargument of classmethods.
Do not suggest return type annotation if a function or method does not contain areturnstatement.
Files:
src/snakemake/notebook.py
🧠 Learnings (1)
📚 Learning: 2024-10-29T17:14:13.585Z
Learnt from: zmbc
PR: snakemake/snakemake#2857
File: snakemake/notebook.py:84-90
Timestamp: 2024-10-29T17:14:13.585Z
Learning: In `snakemake/notebook.py`, when suggesting enhancements to the `execute_script` method in the `JupyterNotebook` class, ensure that changes align with both papermill and nbconvert use cases.
Applied to files:
src/snakemake/notebook.py
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (43)
- GitHub Check: tests (8, ubuntu-latest, py313)
- GitHub Check: tests (10, ubuntu-latest, py312)
- GitHub Check: tests (7, ubuntu-latest, py312)
- GitHub Check: tests (10, ubuntu-latest, py311)
- GitHub Check: tests (9, windows-2022, py313)
- GitHub Check: tests (6, ubuntu-latest, py313)
- GitHub Check: tests (6, ubuntu-latest, py312)
- GitHub Check: tests (10, windows-2022, py313)
- GitHub Check: tests (10, ubuntu-latest, py313)
- GitHub Check: tests (9, ubuntu-latest, py311)
- GitHub Check: tests (9, ubuntu-latest, py313)
- GitHub Check: tests (9, ubuntu-latest, py312)
- GitHub Check: tests (5, ubuntu-latest, py313)
- GitHub Check: tests (7, windows-2022, py313)
- GitHub Check: tests (7, ubuntu-latest, py313)
- GitHub Check: tests (7, ubuntu-latest, py311)
- GitHub Check: tests (8, ubuntu-latest, py311)
- GitHub Check: tests (8, ubuntu-latest, py312)
- GitHub Check: tests (6, windows-2022, py313)
- GitHub Check: tests (5, windows-2022, py313)
- GitHub Check: tests (6, ubuntu-latest, py311)
- GitHub Check: tests (5, ubuntu-latest, py311)
- GitHub Check: tests (5, ubuntu-latest, py312)
- GitHub Check: tests (4, windows-2022, py313)
- GitHub Check: tests (4, macos-latest, py313)
- GitHub Check: tests (2, ubuntu-latest, py313)
- GitHub Check: tests (4, ubuntu-latest, py313)
- GitHub Check: tests (2, ubuntu-latest, py311)
- GitHub Check: tests (1, ubuntu-latest, py313)
- GitHub Check: tests (3, macos-latest, py313)
- GitHub Check: tests (4, ubuntu-latest, py312)
- GitHub Check: tests (3, ubuntu-latest, py311)
- GitHub Check: tests (3, windows-2022, py313)
- GitHub Check: tests (3, ubuntu-latest, py312)
- GitHub Check: tests (2, windows-2022, py313)
- GitHub Check: tests (3, ubuntu-latest, py313)
- GitHub Check: tests (1, ubuntu-latest, py311)
- GitHub Check: tests (4, ubuntu-latest, py311)
- GitHub Check: tests (2, macos-latest, py313)
- GitHub Check: tests (1, windows-2022, py313)
- GitHub Check: tests (2, ubuntu-latest, py312)
- GitHub Check: tests (1, ubuntu-latest, py312)
- GitHub Check: tests (1, macos-latest, py313)
🔇 Additional comments (3)
src/snakemake/notebook.py (3)
56-64: LGTM! Standardized version handling inwrite_script.The changes correctly standardize both the read (
as_version=NBFORMAT_VERSION) and write (version=NBFORMAT_VERSION) operations. This ensures consistent notebook format handling when generating script files.
46-47: Verify notebook format version compatibility and add tests
No existing tests cover theversion=NBFORMAT_VERSIONchange; confirm that current workflows support this notebook version or add tests to prevent regressions.
66-137: Standardizing to nbformat v5 is safe
Papermill 2.0+ (which uses nbclient requiring nbformat v5) and nbconvert 6+ (and all 7.x releases) support nbformat v5 without issues. No further changes needed.
🤖 I have created a release *beep* *boop* --- ## [9.11.9](v9.11.8...v9.11.9) (2025-10-03) ### Bug Fixes * Raise WorkflowError on empty file path in _IOFile.check ([#3769](#3769)) ([4249ff7](4249ff7)) * remove id field in notebook cells created by nbformat, thereby increasing compatibility with different jupyter versions ([#3767](#3767)) ([46cf3ed](46cf3ed)) * show failed logs in generated unit tests ([#3771](#3771)) ([61f4e9b](61f4e9b)) --- This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please).
…ncreasing compatibility with different jupyter versions (snakemake#3767) ### Description <!--Add a description of your PR here--> ### QC <!-- Make sure that you can tick the boxes below. --> * [x] The PR contains a test case for the changes or the changes are already covered by an existing test case. * [x] The documentation (`docs/`) is updated to reflect the changes or this is not necessary (e.g. if the change does neither modify the language nor the behavior or functionalities of Snakemake). <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Bug Fixes** * Standardized notebook read/write to a single, consistent nbformat version to reduce format mismatch issues and improve interoperability. * Added a stable, public notebook format version reference for consistent I/O behavior. * Improved compatibility with various Jupyter versions by omitting cell ID metadata when inserting the preamble cell, reducing related errors or warnings. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
🤖 I have created a release *beep* *boop* --- ## [9.11.9](snakemake/snakemake@v9.11.8...v9.11.9) (2025-10-03) ### Bug Fixes * Raise WorkflowError on empty file path in _IOFile.check ([snakemake#3769](snakemake#3769)) ([4249ff7](snakemake@4249ff7)) * remove id field in notebook cells created by nbformat, thereby increasing compatibility with different jupyter versions ([snakemake#3767](snakemake#3767)) ([46cf3ed](snakemake@46cf3ed)) * show failed logs in generated unit tests ([snakemake#3771](snakemake#3771)) ([61f4e9b](snakemake@61f4e9b)) --- This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please).
Description
QC
docs/) is updated to reflect the changes or this is not necessary (e.g. if the change does neither modify the language nor the behavior or functionalities of Snakemake).Summary by CodeRabbit