Skip to content

merge queue: embarking main (f6dcf95) and #1272 together#1303

Closed
mergify[bot] wants to merge 2 commits intomainfrom
mergify/merge-queue/eaa853d243
Closed

merge queue: embarking main (f6dcf95) and #1272 together#1303
mergify[bot] wants to merge 2 commits intomainfrom
mergify/merge-queue/eaa853d243

Conversation

@mergify
Copy link
Copy Markdown
Contributor

@mergify mergify Bot commented Apr 24, 2026

🎉 This pull request has been checked successfully and will be merged soon. 🎉

Branch main (f6dcf95) and #1272 are embarked together for merge.

This pull request has been created by Mergify to speculatively check the mergeability of #1272.
You don't need to do anything. Mergify will close this pull request automatically when it is complete.

Required conditions of queue rule default for merge:

Required conditions to stay in the queue:

---
checking_base_sha: f6dcf956fcea18094763d3187f3ba98b001fe55a
previous_failed_batches: []
pull_requests:
  - number: 1272
    scopes: []
scopes: []
...

jd and others added 2 commits April 23, 2026 17:45
Adds the Python shim that lets the Rust binary dispatch every
command to the existing Python implementation. Phase 1.1's
deliverable: a Rust binary that, from a user's perspective,
behaves identically to the Python CLI.

## What the shim does

1. Embeds the full ``mergify_cli/`` Python source at compile time
   via ``include_dir!``. Today the payload is ~400KB of .py files
   plus tests; Phase 1.5 will add a build-time filter to drop the
   tests tree and any ``__pycache__`` directories.
2. On first invocation, extracts to
   ``~/.cache/mergify/py/<CARGO_PKG_VERSION>/mergify_cli/`` under a
   file lock. Extraction is atomic: write to a temp dir, rename,
   then write a ``.complete`` sentinel. Concurrent first-runs
   serialize safely; the fast path (sentinel present) touches only
   one ``exists()`` syscall.
3. Invokes ``python3 -m mergify_cli <args>`` with the extracted
   directory prepended to ``PYTHONPATH`` and ``PYTHONSAFEPATH=1``
   so the cwd never shadows the extracted tree. Exit code and
   stdin/stdout/stderr are forwarded transparently.

## Cache keying

Today the cache is keyed on ``CARGO_PKG_VERSION``. Since that's
``0.0.0`` during dev, the cache is shared across builds — clear
``~/.cache/mergify/py/`` by hand when iterating on Python source
in a worktree. Phase 1.5 stamps a real version + git SHA, after
which every build invalidates cleanly.

## Binary wire-up

``crates/mergify-cli/src/main.rs`` now delegates every argv tail
to ``mergify_py_shim::run``. When Phase 1.3+ ports the first
command, native Rust dispatch intercepts it before falling back
to the shim for un-ported commands. Phase 6 deletes the shim
crate entirely.

## Known gap

``python3`` on PATH must have mergify_cli's runtime dependencies
(``httpx``, ``rich``, ``pydantic``, etc.) importable — the shim
embeds only the source, not site-packages. Locally you get this
via ``uv run``; in production the Python deps have to come from
somewhere (PyPI install, a bootstrap venv, or a ``pip``-backed
first-run step). Phase 1.5 decides the mechanism. For Phase 1.1
the shim mechanics are validated in isolation.

## Tests

Three unit tests in the shim crate cover the extraction logic:
files get written, nested directories preserved, second call is
idempotent (sentinel fast-path). End-to-end smoke: ``uv run
./target/release/mergify --help`` extracts and produces Python's
help output.

Binary size: 2.6 MB. Well under the 15 MB design target.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Change-Id: I0c73b039c98011716bc72a441e92e57c6fab9926
@mergify mergify Bot deployed to Mergify Merge Protections April 24, 2026 09:22 Active
@mergify mergify Bot closed this Apr 24, 2026
@mergify mergify Bot deleted the mergify/merge-queue/eaa853d243 branch April 24, 2026 09:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant