Skip to content

feat: Prefer papermill to nbconvert#2857

Merged
johanneskoester merged 30 commits into
snakemake:mainfrom
zmbc:papermill
Jun 11, 2025
Merged

feat: Prefer papermill to nbconvert#2857
johanneskoester merged 30 commits into
snakemake:mainfrom
zmbc:papermill

Conversation

@zmbc

@zmbc zmbc commented May 2, 2024

Copy link
Copy Markdown
Contributor

As described in #348, the current notebook integration has some downsides, and they are due to limitations in the nbconvert tool. papermill is a more feature-rich alternative. In particular, it outputs the executed notebook incrementally for progress tracking, and outputs the notebook (with errors) even when it fails.

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).

I didn't see nbconvert anywhere in the docs, so I think this was always an implementation detail.

Summary by CodeRabbit

  • Tests

    • Added new test functions for verifying Jupyter notebook execution in various scenarios.
  • Documentation

    • Updated guidance to clarify headless notebook execution and expectations during errors.
  • Refactor

    • Improved notebook execution logic by conditionally using Papermill or nbconvert based on availability and updated command parameters for better handling.

@zmbc zmbc requested a review from johanneskoester as a code owner May 2, 2024 17:23
@zmbc zmbc changed the title Prefer papermill to nbconvert feat: Prefer papermill to nbconvert May 2, 2024
Comment thread tests/test_jupyter_notebook/env.yaml Outdated
@zmbc

zmbc commented May 14, 2024

Copy link
Copy Markdown
Contributor Author

@johanneskoester Any concerns with this PR?

@sanjaynagi

Copy link
Copy Markdown

Awesome. Have wanted to do this for a while, I use papermill + notebooks implemented manually for most of my workflows.

@sonarqubecloud

Copy link
Copy Markdown

Quality Gate Passed Quality Gate passed

Issues
0 New issues
0 Accepted issues

Measures
0 Security Hotspots
No data about Coverage
0.0% Duplication on New Code

See analysis details on SonarCloud

@cmeesters

Copy link
Copy Markdown
Member

Just triggered the update from main. I am curious what this will look like, once ready, and will try to incorporate it into some teaching material.

@zmbc

zmbc commented Jun 14, 2024

Copy link
Copy Markdown
Contributor Author

@cmeesters What do you mean by "once ready"? This should be ready and is waiting for review. I see a CI failure but it doesn't look like anything I touched?

@cmeesters

Copy link
Copy Markdown
Member

@zmbc my bad. I should have written "released" instead of "ready".

The CI-error is indeed weird. I triggered the merge from main to give this PR a little push. Alas, I don't understand the cause of the error either.

@zmbc

zmbc commented Jun 17, 2024

Copy link
Copy Markdown
Contributor Author

@cmeesters are you able to review this PR, or poke a maintainer who can? Also could you try re-running the CI?

@cmeesters

Copy link
Copy Markdown
Member

Just did the re-trigger: The tests keep failing and produce output for a test, which should fail. It requires set -e to be set in bash and I don't quite understand, what the site effect of your contribution could be to let this "failure succeed", I'm afraid.

@zmbc

zmbc commented Jun 18, 2024

Copy link
Copy Markdown
Contributor Author

@cmeesters How sure are we that this test passes on main?

@cmeesters

Copy link
Copy Markdown
Member

I am pretty sure that it will not pass - after all, I merged main into this branch to subject it to testing (and re-requested review). But I know we are all busy with our little sidelines, being researchers ...

@coderabbitai

coderabbitai Bot commented Sep 12, 2024

Copy link
Copy Markdown
Contributor
📝 Walkthrough

"""

Walkthrough

This pull request introduces three new test functions in the testing module to validate Jupyter notebook execution in a conda environment, updates documentation to clarify the use of Papermill and nbconvert for notebook execution, and refines the execute_script method in the JupyterNotebook class. The changes include additional error handling, command construction based on papermill availability, and updated logging for edit mode sessions.

Changes

File Change Summary
tests/tests.py Added three new test functions: test_jupyter_notebook, test_jupyter_notebook_nbconvert, and test_jupyter_notebook_draft, each executing notebook tests using a conda environment.
docs/snakefiles/rules.rst Updated documentation to explain that notebooks run in headless mode using Papermill if available, or nbconvert otherwise, including details about error handling during execution.
src/snakemake/notebook.py Modified the execute_script method in the JupyterNotebook class: added subprocess-based papermill detection, adjusted command construction for notebook execution, and updated logging for edit sessions.

Sequence Diagram(s)

sequenceDiagram
    participant Test
    participant JupyterNotebook
    participant Subprocess

    Test->>JupyterNotebook: call execute_script(fname, edit, fname_out)
    JupyterNotebook->>Subprocess: Execute "papermill --version"
    Subprocess-->>JupyterNotebook: Return version info or error
    alt Papermill available
        JupyterNotebook->>Subprocess: Execute notebook with papermill (using fname or fname_out)
    else Papermill unavailable
        JupyterNotebook->>Subprocess: Execute notebook with jupyter-nbconvert
    end
    JupyterNotebook-->>Test: Return execution result
Loading

Possibly related PRs

  • fix: notebook execution for apptainer #3131: Enhances the execute_script method in JupyterNotebook by adding is_python_script=True to internal command execution for Apptainer compatibility, closely related to notebook execution improvements.
    """

📜 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 48c4e71 and b9dcb50.

📒 Files selected for processing (2)
  • docs/snakefiles/rules.rst (1 hunks)
  • tests/tests.py (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • tests/tests.py
  • docs/snakefiles/rules.rst
⏰ Context from checks skipped due to timeout of 90000ms (36)
  • GitHub Check: tests (9, windows-latest, py312)
  • GitHub Check: tests (10, ubuntu-latest, py311)
  • GitHub Check: tests (10, windows-latest, py312)
  • GitHub Check: tests (10, ubuntu-latest, py312)
  • GitHub Check: tests (9, ubuntu-latest, py312)
  • GitHub Check: tests (9, ubuntu-latest, py311)
  • GitHub Check: tests (8, ubuntu-latest, py312)
  • GitHub Check: tests (8, macos-latest, py312)
  • GitHub Check: tests (8, windows-latest, py312)
  • GitHub Check: tests (8, ubuntu-latest, py311)
  • GitHub Check: tests (7, macos-latest, py312)
  • GitHub Check: tests (7, ubuntu-latest, py311)
  • GitHub Check: tests (7, ubuntu-latest, py312)
  • GitHub Check: tests (7, windows-latest, py312)
  • GitHub Check: tests (6, ubuntu-latest, py312)
  • GitHub Check: tests (6, windows-latest, py312)
  • GitHub Check: tests (6, ubuntu-latest, py311)
  • GitHub Check: tests (5, windows-latest, py312)
  • GitHub Check: tests (4, ubuntu-latest, py312)
  • GitHub Check: tests (5, ubuntu-latest, py312)
  • GitHub Check: tests (5, ubuntu-latest, py311)
  • GitHub Check: tests (4, windows-latest, py312)
  • GitHub Check: tests (3, ubuntu-latest, py312)
  • GitHub Check: tests (3, macos-latest, py312)
  • GitHub Check: tests (1, ubuntu-latest, py312)
  • GitHub Check: tests (2, macos-latest, py312)
  • GitHub Check: tests (4, ubuntu-latest, py311)
  • GitHub Check: tests (3, ubuntu-latest, py311)
  • GitHub Check: tests (2, ubuntu-latest, py312)
  • GitHub Check: tests (3, windows-latest, py312)
  • GitHub Check: tests (1, ubuntu-latest, py311)
  • GitHub Check: tests (2, ubuntu-latest, py311)
  • GitHub Check: tests (2, windows-latest, py312)
  • GitHub Check: tests (1, windows-latest, py312)
  • GitHub Check: tests (1, macos-latest, py312)
  • GitHub Check: apidocs
✨ Finishing Touches
  • 📝 Generate Docstrings

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@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

Outside diff range and nitpick comments (1)
snakemake/notebook.py (1)

82-96: LGTM, but consider using a ternary operator.

The updates to the command construction for executing notebooks look good:

  • The conditional logic based on papermill availability ensures the appropriate execution command is used.
  • Falling back to jupyter-nbconvert when papermill is not available maintains compatibility.

However, consider simplifying the code by using a ternary operator for setting output_parameter, as suggested by the static analysis hint from Ruff:

-if fname_out is None:
-    output_parameter = fname
-else:
-    output_parameter = "{fname_out}"
+output_parameter = fname if fname_out is None else "{fname_out}"

This change makes the code more concise without sacrificing readability.

Tools
Ruff

83-86: Use ternary operator output_parameter = fname if fname_out is None else "{fname_out}" instead of if-else-block

Replace if-else-block with output_parameter = fname if fname_out is None else "{fname_out}"

(SIM108)

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between e9ce4a3 and 0a55433.

Files selected for processing (9)
  • snakemake/notebook.py (2 hunks)
  • tests/test_jupyter_notebook/env.yaml (1 hunks)
  • tests/test_jupyter_notebook_draft/env.yaml (1 hunks)
  • tests/test_jupyter_notebook_nbconvert/Notebook.ipynb (1 hunks)
  • tests/test_jupyter_notebook_nbconvert/Snakefile (1 hunks)
  • tests/test_jupyter_notebook_nbconvert/env.yaml (1 hunks)
  • tests/test_jupyter_notebook_nbconvert/expected-results/result_final.txt (1 hunks)
  • tests/test_jupyter_notebook_nbconvert/expected-results/result_intermediate.txt (1 hunks)
  • tests/tests.py (1 hunks)
Files skipped from review due to trivial changes (1)
  • tests/test_jupyter_notebook_draft/env.yaml
Additional context used
Path-based instructions (2)
snakemake/notebook.py (1)

Pattern **/*.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.

tests/tests.py (1)

Pattern **/*.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.

LanguageTool
tests/test_jupyter_notebook_nbconvert/expected-results/result_intermediate.txt

[style] ~1-~1: Using many exclamation marks might seem excessive (in this case: 3 exclamation marks for a text that’s 32 characters long)
Context: result of serious computation!!!

(EN_EXCESSIVE_EXCLAMATION)

tests/test_jupyter_notebook_nbconvert/expected-results/result_final.txt

[style] ~1-~1: Using many exclamation marks might seem excessive (in this case: 6 exclamation marks for a text that’s 35 characters long)
Context: result of serious computation!!!!!!

(EN_EXCESSIVE_EXCLAMATION)

yamllint
tests/test_jupyter_notebook_nbconvert/env.yaml

[error] 6-6: no new line character at the end of file

(new-line-at-end-of-file)

Ruff
snakemake/notebook.py

83-86: Use ternary operator output_parameter = fname if fname_out is None else "{fname_out}" instead of if-else-block

Replace if-else-block with output_parameter = fname if fname_out is None else "{fname_out}"

(SIM108)

Additional comments not posted (15)
tests/test_jupyter_notebook_nbconvert/expected-results/result_intermediate.txt (1)

1-1: The file content is appropriate for an expected test result.

The text "result of serious computation!!!" seems to be an intentionally emphatic expected output for a test case. In this context, the use of multiple exclamation marks is acceptable.

While the static analysis tool flagged this as excessive, it's a false positive in this case since the exact content of the expected output file needs to match the actual output for the test to pass.

Tools
LanguageTool

[style] ~1-~1: Using many exclamation marks might seem excessive (in this case: 3 exclamation marks for a text that’s 32 characters long)
Context: result of serious computation!!!

(EN_EXCESSIVE_EXCLAMATION)

tests/test_jupyter_notebook_nbconvert/expected-results/result_final.txt (1)

1-1: Skip the style issue flagged by the static analysis tool.

The use of multiple exclamation marks in this expected result file is not a concern, as it seems to be intentional to convey emphasis or excitement. The style of the text in an expected result file is not critical as long as it matches the actual output of the test.

Tools
LanguageTool

[style] ~1-~1: Using many exclamation marks might seem excessive (in this case: 6 exclamation marks for a text that’s 35 characters long)
Context: result of serious computation!!!!!!

(EN_EXCESSIVE_EXCLAMATION)

tests/test_jupyter_notebook/env.yaml (1)

7-7: LGTM!

The addition of the papermill dependency aligns with the PR objective of preferring papermill to nbconvert for notebook execution.

The existing comments discussing the removal of the nbformat dependency are still valid and applicable here. No additional comments are necessary.

tests/test_jupyter_notebook_nbconvert/env.yaml (1)

1-6: LGTM!

The Conda environment configuration looks good. It specifies the appropriate channels (conda-forge and bioconda) and includes the necessary dependencies (Python >=3.5 and jupyter) for the notebook execution functionality.

Tools
yamllint

[error] 6-6: no new line character at the end of file

(new-line-at-end-of-file)

tests/test_jupyter_notebook_nbconvert/Snakefile (5)

3-6: LGTM!

The all rule correctly specifies the final output files of the workflow.


8-13: LGTM!

The foo rule correctly generates the intermediate data file used by subsequent rules.


15-23: LGTM!

The bar rule correctly processes the intermediate data file using a Jupyter notebook with the specified conda environment.


25-35: LGTM!

The baz rule correctly processes the intermediate result file using a Jupyter notebook with the specified conda environment and log file.


38-46: LGTM!

The wild rule correctly demonstrates the use of wildcards in notebook execution with the specified conda environment.

tests/test_jupyter_notebook_nbconvert/Notebook.ipynb (3)

9-10: LGTM!

The code changes are approved.


19-19: LGTM!

The code changes are approved.


28-29: LGTM!

The code changes are approved.

snakemake/notebook.py (2)

69-73: LGTM!

The changes to introduce papermill support look good:

  • Checking papermill availability by executing papermill --version is a reasonable approach.
  • Setting the has_papermill flag allows for clear conditional logic based on papermill support.
  • Falling back to jupyter-nbconvert when papermill is not available ensures backward compatibility.

77-81: LGTM!

The updates to the command construction for editing notebooks look good:

  • Including the IP address and port in the logging message enhances clarity and aids in debugging.
  • Switching to --ServerApp.quit_button=True reflects the change in the underlying server application.
tests/tests.py (1)

1507-1511: LGTM!

The new test_jupyter_notebook_nbconvert test function looks good. It is properly decorated with @conda and calls run with the appropriate arguments to test the nbconvert functionality in a conda environment.

Comment thread tests/test_jupyter_notebook_nbconvert/env.yaml Outdated
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
@cmeesters

Copy link
Copy Markdown
Member

@johanneskoester can you give this PR another look? Seems fine to me.

Comment thread tests/test_jupyter_notebook_nbconvert/env.yaml
@fgvieira fgvieira requested a review from cmeesters March 10, 2025 18:42

@johanneskoester johanneskoester 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.

Thanks! Looks good in principle. However, can you please also extend the notebook section in the docs to mention that if papermill is available (e.g. in the conda env), snakemake will use papermill instead of jupyter-nbconvert to run the notebook in non-edit mode (and maybe shortly mention there the rationale why this is considered to be advantageous)?

@sonarqubecloud

Copy link
Copy Markdown

@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)
docs/snakefiles/rules.rst (1)

1693-1699: Clarify the Advantages of Papermill over nbconvert

The revised text now explains the standard headless execution mode for notebooks. However, given that this PR aims to prefer Papermill over nbconvert, it would be beneficial to briefly mention Papermill’s advantages (such as incremental output and error retention) to guide users on why its usage is preferred. For example, you might add a phrase that emphasizes that Papermill not only executes notebooks headlessly but also provides incremental output and preserves outputs even in error cases.

Suggested Diff:

-Normally, notebooks are executed headlessly (without a Jupyter interface being presented to you).
-This is achieved with Papermill_ if that is installed in your software environment,
-or `nbconvert`_ otherwise.
-The latter will be installed automatically along with Jupyter, but will not output
-an executed (logfile) notebook until the entire execution is complete, and won't output
-a notebook if execution encounters an error.
+Normally, notebooks are executed headlessly (without a Jupyter interface being presented to you).
+This is achieved with Papermill_ if that is installed in your software environment, which additionally
+provides incremental output and retains notebook output even upon execution errors,
+or `nbconvert`_ otherwise.
+Note that while nbconvert is automatically installed alongside Jupyter, it only produces
+an executed notebook after complete success and will omit output if execution fails.
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 856c30f and 875ddd6.

📒 Files selected for processing (1)
  • docs/snakefiles/rules.rst (1 hunks)
🧰 Additional context used
🧠 Learnings (2)
📓 Common learnings
Learnt from: zmbc
PR: snakemake/snakemake#2857
File: snakemake/notebook.py:84-90
Timestamp: 2025-03-14T16:09:08.165Z
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.
docs/snakefiles/rules.rst (1)
Learnt from: zmbc
PR: snakemake/snakemake#2857
File: snakemake/notebook.py:84-90
Timestamp: 2025-03-14T16:09:08.165Z
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.
🔇 Additional comments (1)
docs/snakefiles/rules.rst (1)

1700-1703: Verify Reference Links for Papermill and nbconvert

The reference hyperlinks for both Papermill and nbconvert are now explicitly defined. They appear accurate and well integrated with the text. Make sure that these links remain up-to-date as new releases occur.

@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 (3)
src/snakemake/notebook.py (3)

70-75: Add logging when falling back to nbconvert

The code elegantly checks for papermill availability, but there's no notification to the user when falling back to nbconvert.

            try:
                self._execute_cmd("papermill --version", read=True)
                has_papermill = True
            except sp.CalledProcessError:
                has_papermill = False
+               logger.debug("Papermill not available, falling back to nbconvert.")

83-91: Consider adding a timeout parameter to papermill command

The nbconvert command includes --ExecutePreprocessor.timeout=-1 to prevent timeouts, but the papermill command doesn't have an equivalent parameter. For consistency and to prevent potential timeouts with long-running notebooks, consider adding a timeout parameter.

                cmd = (
                    "papermill --log-level ERROR {{fname:q}} "
-                    "{output_parameter}".format(output_parameter=output_parameter)
+                    "{output_parameter} --execution-timeout -1".format(output_parameter=output_parameter)
                )
🧰 Tools
🪛 Ruff (0.8.2)

84-87: Use ternary operator output_parameter = fname if fname_out is None else "{fname_out}" instead of if-else-block

Replace if-else-block with output_parameter = fname if fname_out is None else "{fname_out}"

(SIM108)


84-87: Simplify output parameter logic with a ternary operator

The static analysis tool suggests using a ternary operator for better readability.

-                if fname_out is None:
-                    output_parameter = fname
-                else:
-                    output_parameter = "{fname_out}"
+                output_parameter = fname if fname_out is None else "{fname_out}"
🧰 Tools
🪛 Ruff (0.8.2)

84-87: Use ternary operator output_parameter = fname if fname_out is None else "{fname_out}" instead of if-else-block

Replace if-else-block with output_parameter = fname if fname_out is None else "{fname_out}"

(SIM108)

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 875ddd6 and 7013ee7.

📒 Files selected for processing (3)
  • docs/snakefiles/rules.rst (1 hunks)
  • src/snakemake/notebook.py (2 hunks)
  • tests/tests.py (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • tests/tests.py
  • docs/snakefiles/rules.rst
🧰 Additional context used
📓 Path-based instructions (1)
`**/*.py`: Do not try to improve formatting. Do not suggest ...

**/*.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.

  • src/snakemake/notebook.py
🧠 Learnings (1)
src/snakemake/notebook.py (1)
Learnt from: zmbc
PR: snakemake/snakemake#2857
File: snakemake/notebook.py:84-90
Timestamp: 2025-03-14T16:09:08.165Z
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.
🪛 Ruff (0.8.2)
src/snakemake/notebook.py

84-87: Use ternary operator output_parameter = fname if fname_out is None else "{fname_out}" instead of if-else-block

Replace if-else-block with output_parameter = fname if fname_out is None else "{fname_out}"

(SIM108)

⏰ Context from checks skipped due to timeout of 90000ms (36)
  • GitHub Check: tests (10, macos-latest, py312)
  • GitHub Check: tests (10, windows-latest, py312)
  • GitHub Check: tests (10, ubuntu-latest, py312)
  • GitHub Check: tests (10, ubuntu-latest, py311)
  • GitHub Check: tests (9, windows-latest, py312)
  • GitHub Check: tests (9, ubuntu-latest, py312)
  • GitHub Check: tests (9, ubuntu-latest, py311)
  • GitHub Check: tests (8, windows-latest, py312)
  • GitHub Check: tests (8, ubuntu-latest, py312)
  • GitHub Check: tests (8, ubuntu-latest, py311)
  • GitHub Check: tests (7, windows-latest, py312)
  • GitHub Check: tests (7, ubuntu-latest, py312)
  • GitHub Check: tests (7, ubuntu-latest, py311)
  • GitHub Check: tests (6, windows-latest, py312)
  • GitHub Check: tests (6, ubuntu-latest, py312)
  • GitHub Check: tests (6, ubuntu-latest, py311)
  • GitHub Check: tests (5, windows-latest, py312)
  • GitHub Check: tests (5, ubuntu-latest, py312)
  • GitHub Check: tests (5, ubuntu-latest, py311)
  • GitHub Check: tests (4, macos-latest, py312)
  • GitHub Check: tests (4, windows-latest, py312)
  • GitHub Check: tests (4, ubuntu-latest, py312)
  • GitHub Check: tests (4, ubuntu-latest, py311)
  • GitHub Check: tests (3, macos-latest, py312)
  • GitHub Check: tests (3, windows-latest, py312)
  • GitHub Check: tests (3, ubuntu-latest, py312)
  • GitHub Check: tests (3, ubuntu-latest, py311)
  • GitHub Check: tests (2, macos-latest, py312)
  • GitHub Check: tests (2, windows-latest, py312)
  • GitHub Check: tests (2, ubuntu-latest, py312)
  • GitHub Check: tests (2, ubuntu-latest, py311)
  • GitHub Check: tests (1, macos-latest, py312)
  • GitHub Check: tests (1, windows-latest, py312)
  • GitHub Check: tests (1, ubuntu-latest, py312)
  • GitHub Check: tests (1, ubuntu-latest, py311)
  • GitHub Check: apidocs
🔇 Additional comments (3)
src/snakemake/notebook.py (3)

4-4: LGTM: Import subprocess for checking papermill availability

Adding the subprocess import is necessary for executing shell commands to check if papermill is available.


78-82: LGTM: Improved logging and updated Jupyter server configuration

The logging now provides more detailed information by including the IP and port. The change from --NotebookApp.quit_button=True to --ServerApp.quit_button=True reflects updates in the Jupyter API.


70-104: LGTM: Great implementation of papermill with fallback to nbconvert

The implementation aligns perfectly with the PR objective of preferring papermill while maintaining backward compatibility with nbconvert. This approach ensures seamless execution regardless of the environment setup while taking advantage of papermill's features when available.

🧰 Tools
🪛 Ruff (0.8.2)

84-87: Use ternary operator output_parameter = fname if fname_out is None else "{fname_out}" instead of if-else-block

Replace if-else-block with output_parameter = fname if fname_out is None else "{fname_out}"

(SIM108)

@zmbc

zmbc commented Mar 14, 2025

Copy link
Copy Markdown
Contributor Author

@johanneskoester I've added something to the docs. Feel free to make edits directly!

@zmbc zmbc requested a review from johanneskoester March 14, 2025 21:32
@zmbc

zmbc commented Mar 18, 2025

Copy link
Copy Markdown
Contributor Author

The CI failures look completely unrelated, having to do with internet access on the CI runner.

@johanneskoester johanneskoester enabled auto-merge (squash) June 11, 2025 12:51
@johanneskoester johanneskoester merged commit 4263b03 into snakemake:main Jun 11, 2025
49 checks passed
@github-project-automation github-project-automation Bot moved this from In review to Done in Snakemake Hackathon March 2025 Jun 11, 2025
@mschilli87

mschilli87 commented Jun 11, 2025

Copy link
Copy Markdown
Contributor

Thank you for working this in. Looking forward to giving this a try.

@zmbc zmbc deleted the papermill branch June 11, 2025 17:18
johanneskoester pushed a commit that referenced this pull request Jun 16, 2025
🤖 I have created a release *beep* *boop*
---


##
[9.6.0](v9.5.1...v9.6.0)
(2025-06-16)


### Features

* Prefer papermill to nbconvert
([#2857](#2857))
([4263b03](4263b03))


### Bug Fixes

* DeprecationWarning when using snakemake.utils.validate
([#3420](#3420))
([cf72427](cf72427))
* display group jobs on dryrun
([#3435](#3435))
([3bebef4](3bebef4))
* expandvars for special profile keys
([#3597](#3597))
([4020188](4020188))
* fix bug causing --precommand to not being executed before each remote
job ([#3625](#3625))
([e59d125](e59d125))
* improved toggle switch behavior in reports
([#3623](#3623))
([0c4bd23](0c4bd23))
* pass envvars defined via the envvars directive to remote jobs
([#3626](#3626))
([d4890b4](d4890b4))
* remove wms arg, update logging cli docs
([#3622](#3622))
([3a9a5ac](3a9a5ac))
* typo in CondaEnvDirSpec.__eq__ (issue
[#3192](#3192))
([#3613](#3613))
([f4c107f](f4c107f))
* Unclear handling of params overriding with inheritance
([#3624](#3624))
([077ac4a](077ac4a))


### Documentation

* Added snakemake command to execute the rule plot_with_python
([#3608](#3608))
([bd99c11](bd99c11))
* Updated Reporting Section of The Tutorial(Interaction, Visualization,
and Reporting with Snakemake)
([#3606](#3606))
([91e90ba](91e90ba))
* Updated Requirement Section of The Tutorial With Warning of Not
Installing The Tools Manually
([#3607](#3607))
([3bd114b](3bd114b))
* Updated Wrapper Version in Tutorial and Used Simple Rule For
Consistency & Ease
([#3605](#3605))
([b3bcc21](b3bcc21))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).
@zmbc

zmbc commented Jun 20, 2025

Copy link
Copy Markdown
Contributor Author

Thanks @johanneskoester! 🎉

@mschilli87

mschilli87 commented Jun 25, 2025

Copy link
Copy Markdown
Contributor

Thank you for working this in. Looking forward to giving this a try.

Turns out I cannot since this regression has me stuck at 9.5.x for now. So if anyone has an idea what I could try to get around that, I would greatly appreciate it as this feature would be very convenient for debugging notebooks.

kjohnsen pushed a commit to kjohnsen/snakemake that referenced this pull request Dec 15, 2025
As described in snakemake#348, the current notebook integration has some
downsides, and they are due to limitations in the `nbconvert` tool.
[`papermill`](https://papermill.readthedocs.io/en/latest/index.html) is
a more feature-rich alternative. In particular, it outputs the executed
notebook incrementally for progress tracking, and outputs the notebook
(with errors) even when it fails.

### QC
* [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).

I didn't see `nbconvert` anywhere in the docs, so I think this was
always an implementation detail.


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

- **Tests**
- Added new test functions for verifying Jupyter notebook execution in
various scenarios.

- **Documentation**
- Updated guidance to clarify headless notebook execution and
expectations during errors.

- **Refactor**
- Enhanced error handling and improved command execution logic for more
reliable Jupyter notebook processing.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Co-authored-by: Christian Meesters <cmeesters@users.noreply.github.com>
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Co-authored-by: Filipe G. Vieira <1151762+fgvieira@users.noreply.github.com>
Co-authored-by: Johannes Köster <johannes.koester@tu-dortmund.de>
kjohnsen pushed a commit to kjohnsen/snakemake that referenced this pull request Dec 15, 2025
🤖 I have created a release *beep* *boop*
---


##
[9.6.0](snakemake/snakemake@v9.5.1...v9.6.0)
(2025-06-16)


### Features

* Prefer papermill to nbconvert
([snakemake#2857](snakemake#2857))
([4263b03](snakemake@4263b03))


### Bug Fixes

* DeprecationWarning when using snakemake.utils.validate
([snakemake#3420](snakemake#3420))
([cf72427](snakemake@cf72427))
* display group jobs on dryrun
([snakemake#3435](snakemake#3435))
([3bebef4](snakemake@3bebef4))
* expandvars for special profile keys
([snakemake#3597](snakemake#3597))
([4020188](snakemake@4020188))
* fix bug causing --precommand to not being executed before each remote
job ([snakemake#3625](snakemake#3625))
([e59d125](snakemake@e59d125))
* improved toggle switch behavior in reports
([snakemake#3623](snakemake#3623))
([0c4bd23](snakemake@0c4bd23))
* pass envvars defined via the envvars directive to remote jobs
([snakemake#3626](snakemake#3626))
([d4890b4](snakemake@d4890b4))
* remove wms arg, update logging cli docs
([snakemake#3622](snakemake#3622))
([3a9a5ac](snakemake@3a9a5ac))
* typo in CondaEnvDirSpec.__eq__ (issue
[snakemake#3192](snakemake#3192))
([snakemake#3613](snakemake#3613))
([f4c107f](snakemake@f4c107f))
* Unclear handling of params overriding with inheritance
([snakemake#3624](snakemake#3624))
([077ac4a](snakemake@077ac4a))


### Documentation

* Added snakemake command to execute the rule plot_with_python
([snakemake#3608](snakemake#3608))
([bd99c11](snakemake@bd99c11))
* Updated Reporting Section of The Tutorial(Interaction, Visualization,
and Reporting with Snakemake)
([snakemake#3606](snakemake#3606))
([91e90ba](snakemake@91e90ba))
* Updated Requirement Section of The Tutorial With Warning of Not
Installing The Tools Manually
([snakemake#3607](snakemake#3607))
([3bd114b](snakemake@3bd114b))
* Updated Wrapper Version in Tutorial and Used Simple Rule For
Consistency & Ease
([snakemake#3605](snakemake#3605))
([b3bcc21](snakemake@b3bcc21))

---
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

Development

Successfully merging this pull request may close these issues.

7 participants