Skip to content

fix: remove id field in notebook cells created by nbformat, thereby increasing compatibility with different jupyter versions#3767

Merged
johanneskoester merged 3 commits into
mainfrom
fix/ci
Oct 3, 2025
Merged

fix: remove id field in notebook cells created by nbformat, thereby increasing compatibility with different jupyter versions#3767
johanneskoester merged 3 commits into
mainfrom
fix/ci

Conversation

@johanneskoester

@johanneskoester johanneskoester commented Oct 2, 2025

Copy link
Copy Markdown
Contributor

Description

QC

  • The PR contains a test case for the changes or the changes are already covered by an existing test case.
  • 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).

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.

@coderabbitai

coderabbitai Bot commented Oct 2, 2025

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

Added module-level constant NBFORMAT_VERSION = 4 to src/snakemake/notebook.py and standardized all nbformat read/write calls in that module to use this version (reads use as_version=NBFORMAT_VERSION, writes use version=NBFORMAT_VERSION).

Changes

Cohort / File(s) Summary
Notebook nbformat versioning
src/snakemake/notebook.py
Added NBFORMAT_VERSION = 4. Standardized nbformat I/O: reads use as_version=NBFORMAT_VERSION and writes use version=NBFORMAT_VERSION across draft, write_script, and execute_script notebook operations.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Pre-merge checks and finishing touches

❌ Failed checks (3 warnings)
Check name Status Explanation Resolution
Title Check ⚠️ Warning The pull request title claims to remove the id field from notebook cells, but the changeset instead adds an NBFORMAT_VERSION constant and standardizes nbformat I/O versioning without mentioning id removal, making the title misleading. Please update the title to clearly reflect the main change, for example “standardize notebook I/O to NBFORMAT_VERSION constant (version 4)” or similar that highlights the versioning update.
Description Check ⚠️ Warning The pull request description still contains the placeholder prompt and does not include an actual summary of the changes made, so it fails to inform reviewers of the modifications. Please replace the placeholder in the Description section with a concise overview of the new NBFORMAT_VERSION constant addition and how notebook I/O was standardized to that version.
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✨ Finishing touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/ci

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 2ede3fb and b64db38.

📒 Files selected for processing (1)
  • src/snakemake/notebook.py (5 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • 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). (44)
  • GitHub Check: tests (10, ubuntu-latest, py311)
  • GitHub Check: tests (10, ubuntu-latest, py312)
  • GitHub Check: tests (9, windows-2022, py313)
  • GitHub Check: tests (10, ubuntu-latest, py313)
  • GitHub Check: tests (10, windows-2022, py313)
  • GitHub Check: tests (9, ubuntu-latest, py313)
  • GitHub Check: tests (9, ubuntu-latest, py312)
  • GitHub Check: tests (8, windows-2022, py313)
  • GitHub Check: tests (7, windows-2022, py313)
  • GitHub Check: tests (8, ubuntu-latest, py311)
  • GitHub Check: tests (9, ubuntu-latest, py311)
  • GitHub Check: tests (8, ubuntu-latest, py312)
  • GitHub Check: tests (6, windows-2022, py313)
  • GitHub Check: tests (8, ubuntu-latest, py313)
  • GitHub Check: tests (7, macos-latest, py313)
  • GitHub Check: tests (7, ubuntu-latest, py312)
  • GitHub Check: tests (7, ubuntu-latest, py313)
  • GitHub Check: tests (6, ubuntu-latest, py313)
  • GitHub Check: tests (7, ubuntu-latest, py311)
  • GitHub Check: tests (6, ubuntu-latest, py311)
  • GitHub Check: tests (4, macos-latest, py313)
  • GitHub Check: tests (6, ubuntu-latest, py312)
  • GitHub Check: tests (5, ubuntu-latest, py312)
  • GitHub Check: tests (5, ubuntu-latest, py313)
  • GitHub Check: tests (4, windows-2022, py313)
  • GitHub Check: tests (3, ubuntu-latest, py311)
  • GitHub Check: tests (5, windows-2022, py313)
  • GitHub Check: tests (3, macos-latest, py313)
  • GitHub Check: tests (4, ubuntu-latest, py313)
  • GitHub Check: tests (5, ubuntu-latest, py311)
  • GitHub Check: tests (3, ubuntu-latest, py313)
  • GitHub Check: tests (4, ubuntu-latest, py312)
  • GitHub Check: tests (2, windows-2022, py313)
  • GitHub Check: tests (4, ubuntu-latest, py311)
  • GitHub Check: tests (3, ubuntu-latest, py312)
  • GitHub Check: tests (2, ubuntu-latest, py313)
  • GitHub Check: tests (3, windows-2022, py313)
  • GitHub Check: tests (2, ubuntu-latest, py311)
  • GitHub Check: tests (2, ubuntu-latest, py312)
  • GitHub Check: tests (2, macos-latest, py313)
  • GitHub Check: tests (1, ubuntu-latest, py312)
  • GitHub Check: tests (1, ubuntu-latest, py313)
  • GitHub Check: tests (1, windows-2022, py313)
  • GitHub Check: tests (1, ubuntu-latest, py311)

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions

github-actions Bot commented Oct 2, 2025

Copy link
Copy Markdown
Contributor

Please format your code with black: black snakemake tests/*.py.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 via nbformat.v4.new_code_cell("# start coding here") may include an "id" field in its metadata—assign it to a variable, call pop("id", None), then append.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 1549c8b and cdf17d8.

📒 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 the self argument of methods.
Do not suggest type annotation of the cls argument of classmethods.
Do not suggest return type annotation if a function or method does not contain a return statement.

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

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (2)
src/snakemake/notebook.py (2)

23-28: Consider standardizing version handling in get_cell_sources.

The get_cell_sources function uses nbformat.NO_CONVERT when reading notebooks (line 26), while other read operations in this file now use as_version=NBFORMAT_VERSION.

For consistency with the standardization effort in this PR, consider whether this function should also use as_version=NBFORMAT_VERSION. If NO_CONVERT is 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_VERSION will 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

📥 Commits

Reviewing files that changed from the base of the PR and between cdf17d8 and 2ede3fb.

📒 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 the self argument of methods.
Do not suggest type annotation of the cls argument of classmethods.
Do not suggest return type annotation if a function or method does not contain a return statement.

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 in write_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 the version=NBFORMAT_VERSION change; 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.

Comment thread src/snakemake/notebook.py Outdated
@johanneskoester johanneskoester merged commit 46cf3ed into main Oct 3, 2025
54 of 60 checks passed
@johanneskoester johanneskoester deleted the fix/ci branch October 3, 2025 09:49
johanneskoester pushed a commit that referenced this pull request Oct 3, 2025
🤖 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).
kjohnsen pushed a commit to kjohnsen/snakemake that referenced this pull request Dec 15, 2025
…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 -->
kjohnsen pushed a commit to kjohnsen/snakemake that referenced this pull request Dec 15, 2025
🤖 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).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant