Skip to content

extract f-string backslash to _safe_json for Python 3.10/3.11 compat#11

Merged
ypriverol merged 3 commits intobigbio:devfrom
Shen-YuFei:dev
Mar 16, 2026
Merged

extract f-string backslash to _safe_json for Python 3.10/3.11 compat#11
ypriverol merged 3 commits intobigbio:devfrom
Shen-YuFei:dev

Conversation

@Shen-YuFei
Copy link
Contributor

@Shen-YuFei Shen-YuFei commented Mar 16, 2026

This is a Python version compatibility issue: Python 3.12+ (PEP 701) allows backslashes inside f-string expressions, but CI runs Python 3.10/3.11 which does not.

Root Cause: 7 instances of json.dumps(obj).replace('</', '<\\/') inside f-string expressions in:

  • mokume/reports/qc_report.py (3 occurrences)
  • mokume/reports/workflow_comparison.py (4 occurrences)

Fix: Extract json.dumps() + replace() into a new _safe_json() helper function (defined outside f-strings), replace all 7 inline calls with _safe_json(obj).

Problem 2: CI not triggering on dev branch

Workflow trigger only listed main and develop, but develop branch doesn't exist — the actual development branch is dev.

Fix: Replace develop with dev in .github/workflows/python-app.yml.

Problem 3: test_pride_aggregation_comparison KeyError

PRIDE FTP updated the PXD063291.zip structure — report.tsv moved from PXD063291/ to PXD063291/DiaNN/, and 13 new TSV files (e.g. report.gg_matrix.tsv) were added. The fuzzy "report" in f.name match picked up the wrong file.

Fix: Use exact f.name == "report.tsv" matching in download_pride_dataset().

Copilot AI review requested due to automatic review settings March 16, 2026 09:00
@coderabbitai
Copy link

coderabbitai bot commented Mar 16, 2026

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 673d6b05-b239-447e-86ea-f9a409c1f06e

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
📝 Coding Plan
  • Generate coding plan for human review comments

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.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR refactors inline json.dumps(...).replace(...) usage in HTML-generating report code into a shared helper to maintain Python 3.10/3.11 f-string compatibility when embedding JSON into <script> blocks.

Changes:

  • Introduced a _safe_json() helper in qc_report.py to serialize JSON and escape </ for safe HTML <script> embedding.
  • Updated QC and workflow comparison report HTML generation to use _safe_json(...) instead of inline json.dumps(...).replace(...).
  • Updated imports in workflow_comparison.py to pull in the new helper.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
mokume/reports/workflow_comparison.py Switches embedded JS data blocks to _safe_json(...) and imports the helper from qc_report.
mokume/reports/qc_report.py Adds _safe_json() and uses it for embedded PCA/t-SNE/correlation JSON payloads.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

Comment on lines +21 to 23
from mokume.reports.qc_report import compute_qc_metrics, _safe_json
from mokume.core.logger import get_logger

import pandas as pd

from mokume.reports.qc_report import compute_qc_metrics
from mokume.reports.qc_report import compute_qc_metrics, _safe_json
Comment on lines +499 to +505
def _safe_json(obj):
"""Serialize to JSON and escape closing script tags for safe HTML embedding."""
import json

return json.dumps(obj).replace("</", "<\\/")


@ypriverol ypriverol merged commit 9310a76 into bigbio:dev Mar 16, 2026
4 checks passed
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.

3 participants