-
Notifications
You must be signed in to change notification settings - Fork 605
fix: dag mermaid-js edges (bug:#3556) #3669
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: dag mermaid-js edges (bug:#3556) #3669
Conversation
I noticed that `DAG._dot()` renders the edges correctly, but `DAG._mermaid_js()` makes a mess out of it. - I copied the bit from the _dot part to the _mermaid_js part - modified the f"" stretch to use the correct numbers This fixed the mermaid output so it matches the dor one.
📝 WalkthroughWalkthroughThe internal logic of the Additionally, a new test workflow and corresponding Mermaid diagram were added to verify the correct behavior related to GitHub issues #3556 and #946. A new test function was introduced to run Snakemake with the Mermaid.js DAG output for this workflow. Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant DAG
participant MermaidJS
User->>DAG: Request Mermaid.js graph
DAG->>DAG: Map nodes to indices (ids)
DAG->>DAG: Iterate over nodes and dependencies
DAG->>MermaidJS: Generate edges as dep --> node using ids
DAG->>User: Return Mermaid.js graph string
Possibly related PRs
Suggested reviewers
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (3)
✅ Files skipped from review due to trivial changes (1)
🧰 Additional context used📓 Path-based instructions (1)**/*.pyInstructions used from: Sources: 🧠 Learnings (3)📓 Common learnings
tests/tests.py (8)
tests/test_github_issue3556/Snakefile (10)
🧬 Code Graph Analysis (1)tests/tests.py (1)
🔇 Additional comments (2)
✨ Finishing Touches
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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed 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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
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/dag.py (1)
2668-2674
: Avoid triple enumeration ofgraph
for index consistency & micro-perf
graph
is enumerated three times (headers, styles,ids
). Any mutation of the dict between calls would desynchronise indices. A single pass keeps things deterministic and shaves a bit of work:- nodes_headers = [ - f"\tid{index}[{node2label(node)}]" for index, node in enumerate(graph) - ] - nodes_styles = [ - f"\tstyle id{index} fill:{rulecolor[str(node)]},stroke-width:2px,color:#333333{node2style(node)}" - for index, node in enumerate(graph) - ] - # node ids - ids = {node: i for i, node in enumerate(graph)} + nodes = list(graph.keys()) + ids = {node: i for i, node in enumerate(nodes)} + nodes_headers = [f"\tid{ids[node]}[{node2label(node)}]" for node in nodes] + nodes_styles = [ + f"\tstyle id{ids[node]} " + f"fill:{rulecolor[str(node)]},stroke-width:2px,color:#333333{node2style(node)}" + for node in nodes + ]Keeps all index look-ups consistent and makes intent clearer.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
src/snakemake/dag.py
(1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
`**/*.py`: Do not try to improve formatting. Do not suggest type annotations for...
**/*.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 theself
argument of methods.
Do not suggest type annotation of thecls
argument of classmethods.
Do not suggest return type annotation if a function or method does not contain areturn
statement.
⚙️ Source: CodeRabbit Configuration File
List of files the instruction was applied to:
src/snakemake/dag.py
🧠 Learnings (2)
📓 Common learnings
Learnt from: johanneskoester
PR: snakemake/snakemake#3148
File: snakemake/dag.py:1332-1336
Timestamp: 2024-11-12T12:08:20.342Z
Learning: In `snakemake/dag.py`, when code is outdated and will disappear upon resolving merge conflicts, avoid making code review suggestions on that code.
Learnt from: johanneskoester
PR: snakemake/snakemake#3140
File: snakemake/dag.py:1308-1308
Timestamp: 2024-10-14T09:42:11.571Z
Learning: In `snakemake/dag.py`, avoid flagging missing lines or indentation issues when there is no clear syntax or logical error to prevent false positives.
Learnt from: leoschwarz
PR: snakemake/snakemake#3176
File: tests/test_output_index.py:99-157
Timestamp: 2025-01-17T12:00:09.368Z
Learning: New test dependencies for Snakemake should be introduced in separate PRs rather than being added as part of feature or refactoring PRs.
src/snakemake/dag.py (2)
<retrieved_learning>
Learnt from: johanneskoester
PR: #3148
File: snakemake/dag.py:1332-1336
Timestamp: 2024-11-12T12:08:20.342Z
Learning: In snakemake/dag.py
, when code is outdated and will disappear upon resolving merge conflicts, avoid making code review suggestions on that code.
</retrieved_learning>
<retrieved_learning>
Learnt from: johanneskoester
PR: #3140
File: snakemake/dag.py:1308-1308
Timestamp: 2024-10-14T09:42:11.571Z
Learning: In snakemake/dag.py
, avoid flagging missing lines or indentation issues when there is no clear syntax or logical error to prevent false positives.
</retrieved_learning>
🔇 Additional comments (1)
src/snakemake/dag.py (1)
2671-2673
: Edge direction now matches DOT output – good fix
Changing the arrow toid{ids[dep]} --> id{ids[node]}
aligns Mermaid with the DOT representation and renders dependencies in the expected upstream → downstream direction.
I have managed to get a test that passes with the fix and fails without the fix. I don't know how to integrate it using PRs, but here is the link to my commit: b-brankovics/snakemake@e715f3e |
@b-brankovics just commit your test to the same branch as that of this PR. Then, it will automatically appear here. |
Add the test for the issue and fix
Thank you @johanneskoester! Merged the test commit and updated the PR to show that there is a test included. |
🤖 I have created a release *beep* *boop* --- ## [9.9.0](v9.8.2...v9.9.0) (2025-07-29) ### Features * python 3.13 support ([#3602](#3602)) ([429cff4](429cff4)) ### Bug Fixes * dag mermaid-js edges (bug:[#3556](#3556)) ([#3669](#3669)) ([c6e2e71](c6e2e71)) * if asset is present and no sha256 provided assume pass ([#3685](#3685)) ([7731175](7731175)) --- This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please).
fixes #3556
I noticed that
DAG._dot()
renders the edges correctly, butDAG._mermaid_js()
makes a mess out of it.This fixed the mermaid output so it matches the dot one.
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