Skip to content

feat(scripts): add tutorial code sync tool#135

Merged
thephez merged 5 commits intodashpay:3.1.0from
thephez:feat/tutorial-sync
Mar 11, 2026
Merged

feat(scripts): add tutorial code sync tool#135
thephez merged 5 commits intodashpay:3.1.0from
thephez:feat/tutorial-sync

Conversation

@thephez
Copy link
Collaborator

@thephez thephez commented Mar 11, 2026

Summary

  • Add scripts/tutorial-sync/sync_tutorial_code.py — a Python script that keeps inline code blocks in tutorial docs synchronized with the runnable source files in dashpay/platform-tutorials
  • Add scripts/tutorial-sync/tutorial-code-map.yml — YAML config mapping 28 source files to their corresponding code blocks across 19 tutorial pages
  • Support three modes: sync (update docs in-place), --check (CI drift detection), --diff (show unified diffs)
  • Handle three code block patterns: {code-block} with :caption:, tab-items with :sync:, and tab-items matched by title
  • Add pyyaml dependency to requirements.txt

Context

Tutorial code in docs/tutorials/ was manually duplicated from dashpay/platform-tutorials. When the runnable code changed, both repos had to be updated independently, leading to drift. This script makes platform-tutorials the single source of truth — run it to pull code into the docs, or use --check in CI to catch when they diverge.

Usage

# Check for drift
python3 scripts/tutorial-sync/sync_tutorial_code.py --check --source /path/to/platform-tutorials

# Sync docs in-place
python3 scripts/tutorial-sync/sync_tutorial_code.py --source /path/to/platform-tutorials

# Show diffs
python3 scripts/tutorial-sync/sync_tutorial_code.py --diff --source /path/to/platform-tutorials

Preview build: https://dash-docs-platform--135.org.readthedocs.build/en/135/

Summary by CodeRabbit

  • New Features

    • Added tutorial code synchronization system to keep documentation code blocks aligned with external source files, with check and sync modes.
  • Documentation

    • Updated contributing guidelines with tutorial synchronization instructions.
    • Added project guidance documentation for code maintainers.
  • Chores

    • Updated version to 3.1.0.
    • Added required dependencies for tutorial synchronization functionality.

thephez and others added 3 commits March 11, 2026 16:52
Adds a script to sync inline code blocks in tutorial docs with
platform-tutorials source files, with check/diff modes for CI.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@coderabbitai
Copy link

coderabbitai bot commented Mar 11, 2026

📝 Walkthrough

Walkthrough

The pull request introduces a tutorial code synchronization system that automatically syncs code blocks in documentation with source files from a platform-tutorials repository. It includes a GitHub Actions workflow for CI validation, a Python utility script with multiple discovery strategies, YAML configuration mapping, and supporting documentation.

Changes

Cohort / File(s) Summary
CI/Workflow Setup
.github/workflows/check-tutorial-sync.yml
New GitHub Actions workflow triggering on PRs affecting docs/tutorials or scripts/tutorial-sync, checking out both main repo and platform-tutorials repo, then running sync validation in check mode.
Documentation & Configuration
CLAUDE.md, README.md, conf.py
Added Claude context file for repository guidance; updated README with tutorial sync commands and usage instructions; bumped github_version from "2.0.0" to "3.1.0" in conf.py and corrected exclude_patterns entry.
Dependencies
requirements.txt
Added pyyaml==6.0 dependency for YAML config parsing in sync script.
Tutorial Sync System
scripts/tutorial-sync/sync_tutorial_code.py, scripts/tutorial-sync/tutorial-code-map.yml
New Python utility script that reads YAML mappings and synchronizes embedded code blocks in markdown docs with platform-tutorials source files; supports three block discovery strategies (caption-based, sync-based, tab-based) and three modes (sync, check, diff). Accompanying YAML config defines source-to-doc mappings with flexible block locators across multiple tutorial categories.
Tutorial Content
docs/tutorials/create-and-fund-a-wallet.md
Minor formatting: converted ternary assignment to multiline conditional expression and reformatted console.log arguments across multiple lines; no behavioral changes.

Sequence Diagram(s)

sequenceDiagram
    participant GHA as GitHub Actions
    participant Script as sync_tutorial_code.py
    participant YML as tutorial-code-map.yml
    participant Src as platform-tutorials
    participant Doc as Documentation

    GHA->>Script: Execute with --check flag
    Script->>YML: Load YAML configuration
    YML-->>Script: Return source-to-doc mappings
    
    loop For each mapping
        Script->>Src: Read source file
        Src-->>Script: Source code content
        Script->>Doc: Locate code block (caption/sync/tab)
        Doc-->>Script: Code block content
        Script->>Script: Compare source vs doc block
        Script-->>GHA: Report MATCH/DIFF/DRIFT
    end
    
    Script-->>GHA: Exit with status (0 if check passes)
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Poem

🐰 Hop, hop! Code blocks now sync with delight,
Platform tutorials kept in sight,
YAML maps guide the way so clear,
No more drifts to fear, my dear!
GitHub Actions keeps docs tight! 📝

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title 'feat(scripts): add tutorial code sync tool' directly and clearly describes the main change: introducing a new Python script for synchronizing tutorial code.
Docstring Coverage ✅ Passed Docstring coverage is 85.71% which is sufficient. The required threshold is 80.00%.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.

@thephez thephez marked this pull request as ready for review March 11, 2026 21:16
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (3)
.github/workflows/check-tutorial-sync.yml (1)

24-24: Pin pyyaml version to match requirements.txt.

The workflow installs pyyaml without a version constraint, while requirements.txt pins pyyaml==6.0. This creates potential inconsistency between CI and local development.

Suggested fix
-      - run: pip install pyyaml
+      - run: pip install pyyaml==6.0

Or better yet, install from requirements.txt to ensure consistency:

-      - run: pip install pyyaml
+      - run: pip install -r requirements.txt
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In @.github/workflows/check-tutorial-sync.yml at line 24, The workflow step that
runs "pip install pyyaml" should be made deterministic: either pin the package
to the same version used in requirements.txt by changing it to "pip install
pyyaml==6.0" or (preferred) replace that step with installing from
requirements.txt via "pip install -r requirements.txt" so CI uses the exact
"pyyaml==6.0" specified in requirements.txt.
scripts/tutorial-sync/sync_tutorial_code.py (2)

187-188: Consider extracting error message to a constant or custom exception.

Static analysis (TRY003) flags the inline message. This is a minor style preference—you can optionally extract to a custom exception class for cleaner exception handling, but it's not critical.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@scripts/tutorial-sync/sync_tutorial_code.py` around lines 187 - 188, The
inline error message raised by ValueError in the else branch that checks
block_id (the raise ValueError(f"Unknown block_id type: {block_id}") in
sync_tutorial_code.py) should be extracted for cleaner handling: either move the
message string to a module-level constant (e.g., UNKNOWN_BLOCK_ID_MSG) and
reference it in the ValueError, or define a small custom exception class (e.g.,
UnknownBlockIDError) and raise that with the formatted message; update any
callers/tests to catch the new exception or the constant message as appropriate.

119-121: Potential off-by-one for empty code blocks.

code_start = fm.end() + 1 assumes a newline immediately follows the fence opener (e.g., ```javascript\n). If the fence opener is at EOF or the code block is malformed without a trailing newline, code_start could exceed the content length or produce incorrect offsets.

This is likely an edge case given the controlled document format, but consider adding a bounds check:

Optional defensive fix
         code_start = fm.end() + 1  # skip the newline after ```language
+        if code_start > len(content):
+            continue
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@scripts/tutorial-sync/sync_tutorial_code.py` around lines 119 - 121, The code
computes code_start = fm.end() + 1 and can exceed the document length for
malformed or EOF fence-openers; update the logic in the loop that uses fm and
code_start (where you parse fenced code blocks) to check the bounds after
computing code_start (compare code_start against len(content)) and skip/continue
if it is out of range so you don't index past the end of content or produce
incorrect offsets.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In @.github/workflows/check-tutorial-sync.yml:
- Line 24: The workflow step that runs "pip install pyyaml" should be made
deterministic: either pin the package to the same version used in
requirements.txt by changing it to "pip install pyyaml==6.0" or (preferred)
replace that step with installing from requirements.txt via "pip install -r
requirements.txt" so CI uses the exact "pyyaml==6.0" specified in
requirements.txt.

In `@scripts/tutorial-sync/sync_tutorial_code.py`:
- Around line 187-188: The inline error message raised by ValueError in the else
branch that checks block_id (the raise ValueError(f"Unknown block_id type:
{block_id}") in sync_tutorial_code.py) should be extracted for cleaner handling:
either move the message string to a module-level constant (e.g.,
UNKNOWN_BLOCK_ID_MSG) and reference it in the ValueError, or define a small
custom exception class (e.g., UnknownBlockIDError) and raise that with the
formatted message; update any callers/tests to catch the new exception or the
constant message as appropriate.
- Around line 119-121: The code computes code_start = fm.end() + 1 and can
exceed the document length for malformed or EOF fence-openers; update the logic
in the loop that uses fm and code_start (where you parse fenced code blocks) to
check the bounds after computing code_start (compare code_start against
len(content)) and skip/continue if it is out of range so you don't index past
the end of content or produce incorrect offsets.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: fa82123d-da3d-4167-b82d-8af1154fedb6

📥 Commits

Reviewing files that changed from the base of the PR and between c71143e and 7bd0da9.

📒 Files selected for processing (8)
  • .github/workflows/check-tutorial-sync.yml
  • CLAUDE.md
  • README.md
  • conf.py
  • docs/tutorials/create-and-fund-a-wallet.md
  • requirements.txt
  • scripts/tutorial-sync/sync_tutorial_code.py
  • scripts/tutorial-sync/tutorial-code-map.yml

@thephez thephez merged commit 3625eaa into dashpay:3.1.0 Mar 11, 2026
2 checks passed
@thephez thephez deleted the feat/tutorial-sync branch March 11, 2026 21:25
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