Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Instruction on jupytext_verify_pair.py script


Owner: Vadim Rudakov, rudakow.wadim@gmail.com Version: 0.1.0 Birth: 2026-01-26 Last Modified: 2026-01-26


1. Architectural Overview: The SVA Principle

This script verifies that when one file of a Jupytext pair (.md or .ipynb) is staged for commit, the other file is also staged.

This prevents partial commits where only one file of a pair is committed, which would break synchronization.

2. Key Capabilities & Logic

A. Pair Verification

For each staged .md or .ipynb file:

  1. Find the paired file (swap extension)

  2. Check if the pair exists on disk

  3. Verify both files are staged together

B. Unstaged Changes Detection

If both files are staged, also checks for unstaged changes that might be missed.

C. Automatic Sync on Failure

When one file is staged but not the other, the script automatically runs jupytext --sync on the staged file to update its pair.

D. Validation States

StateResult
Neither stagedOK (skip)
Both staged, no unstaged changesOK
One staged, other notFAIL (auto-sync attempted)
Both staged, has unstaged changesFAIL

3. Operational Guide

Basic Usage

# Verify specific files
uv run tools/scripts/jupytext_verify_pair.py file1.md file2.ipynb

# Typically called by pre-commit with changed files

Exit Codes

CodeMeaning
0All pairs properly staged
1One or more pairs incomplete

4. Validation Layers

Pre-commit Hook

- id: jupytext-verify-pair
  name: Jupytext Verify Pair
  entry: uv run tools/scripts/jupytext_verify_pair.py
  files: \.(md|ipynb)$
  pass_filenames: true

GitHub Actions

Runs as part of the jupytext job in quality.yml.

5. Test Suite

The test suite covers:

Test AreaCoverage
Pair detectionget_pair_path function
Staging checksis_staged, has_unstaged_changes
Auto-syncsync_pair function
Validation logicAll state combinations

Run tests with:

uv run pytest tools/tests/test_jupytext_verify_pair.py -v