Skip to content

Expose top-level pack/unpack helpers from the Rust extension#1

Draft
Copilot wants to merge 8 commits into
mainfrom
copilot/replace-cython-with-rust
Draft

Expose top-level pack/unpack helpers from the Rust extension#1
Copilot wants to merge 8 commits into
mainfrom
copilot/replace-cython-with-rust

Conversation

Copilot AI commented May 29, 2026

Copy link
Copy Markdown

The Rust _cmsgpack module still routed top-level helper behavior through Python-side wrappers, so the fast path stopped at the class boundary. This change makes the module provide the public helper surface directly, so msgpack.pack* / msgpack.unpack* use the extension implementation when available.

  • Rust module API

    • Added module-level pack, packb, unpack, and unpackb to /tmp/workspace/methane/msgpack-python/src/lib.rs
    • Kept behavior aligned with existing Python semantics, including stream handling and unpackb error translation
  • Top-level binding

    • Updated /tmp/workspace/methane/msgpack-python/msgpack/__init__.py to import the helper functions from _cmsgpack when the extension is active
    • Preserved the existing pure-Python fallback path unchanged when MSGPACK_PUREPYTHON is set or the extension is unavailable
  • Coverage

    • Extended /tmp/workspace/methane/msgpack-python/test/test_rust_backend.py to verify the extension exports the helper functions and that the top-level API resolves to them in extension mode

Example:

import io
import msgpack

buf = io.BytesIO()
msgpack.pack({"value": 1}, buf)   # uses Rust helper when _cmsgpack is available

payload = msgpack.packb([1, 2, 3])
obj = msgpack.unpackb(payload)
Original prompt

methane/msgpack-python リポジトリに対して、Cythonで実装されている部分をRustで再実装し、可能な限り既存のPython向け公開API・挙動・テスト互換性を維持してください。

目的:

  • リポジトリ内のCython由来の拡張実装(例: .pyx, .pxd, cythonize 対象、Cythonベースの高速化コード)を特定する。
  • それらをRustで置き換える。
  • Python から利用可能な拡張モジュールとしてビルドできるようにする。
  • 既存テストが通るように調整する。

要件:

  1. まず現在のCython実装の範囲と、Python公開APIとの対応を調査する。
  2. Rust実装にはPythonバインディングを用いること。リポジトリの既存構成に適した方法(たとえば PyO3 / maturin / setuptools-rust 等)を選定する。
  3. 既存の配布・ビルド構成(pyproject.toml, setup.py, setup.cfg, CI など)があれば、それに整合するよう最小限の変更で統合する。
  4. 既存の挙動・例外・シリアライズ/デシリアライズ結果・性能上重要な経路について、できるだけ互換性を保つ。
  5. Cythonコードが複数箇所に分かれている場合は、すべてRustに移行する。ただし、互換性やビルド上の制約で完全移行が難しい箇所がある場合は、PR説明に未移行箇所・理由・次のステップを明記する。
  6. 必要に応じてテストやベンチ、ドキュメント、ビルド設定を更新する。
  7. 実装後、変更内容・移行方針・既知の制約をPR本文に明記する。

期待成果:

  • Rustベースの実装
  • 必要なビルド設定変更
  • テスト更新
  • PR作成

PRタイトルは、CythonからRustへの移行であることが分かる簡潔なものにしてください。

The following is the prior conversation context from the user's chat exploration (may be truncated):

User: Cythonで書かれている部分を全部Rustで再実装してみて。

Assistant: 対象のリポジトリがまだ分からないので、先にそれだけ教えてください。

必要なのは少なくともこれです。

  • GitHub リポジトリ: owner/repo 形式
  • 可能なら 対象ブランチ
  • 「全部」の範囲確認:
    • Cython の .pyx / .pxd / cythonize 対象をすべてRust化するのか
    • まずは一部を段階的に置き換えるのか
  • 期待する成果物:
    • PRを作る ところまでやる
    • まずは 調査して移行計画を出す だけにする

もしそのまま実装まで進めたいなら、例えばこう指定してください。

  • owner/repo: your-org/your-repo
  • branch: main
  • やること: Cython実装をRustへ全面移行、Pythonバインディングも維持
  • 成果物: PR作成まで

リポジトリが分かれば、こちらでコードを調べて Cython 部分を洗い出し、Rust 実装方針をまとめたうえで進めます。

User: methane/msgpack-python

Assistant: 承認待ちです。確認ダイアログで許可してもらえれば、そのまま実装とPR作成に進めます。

This pull request was created from Copilot chat.

Copilot AI changed the title [WIP] Replace Cython implementation with Rust while maintaining compatibility Migrate msgpack._cmsgpack build path from Cython/C to Rust (PyO3) with API-compatible shim May 29, 2026
Copilot AI requested a review from methane May 29, 2026 05:05
Copilot AI changed the title Migrate msgpack._cmsgpack build path from Cython/C to Rust (PyO3) with API-compatible shim Implement _cmsgpack.Packer as a Rust-backed class with fallback parity May 29, 2026
Copilot AI changed the title Implement _cmsgpack.Packer as a Rust-backed class with fallback parity Port _cmsgpack.Unpacker to Rust wrapper with fallback parity May 29, 2026
Copilot AI changed the title Port _cmsgpack.Unpacker to Rust wrapper with fallback parity Expose top-level pack/unpack helpers from the Rust extension May 29, 2026
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.

2 participants