nikkie-ftnextの日記

イベントレポートや読書メモを発信

pnpmはどんな目的でPythonパッケージ管理もサポートしたのでしょう?

はじめに

なんとか福岡にたどり着いたnikkie (UUID 28fb3f96-a221-462c-93bd-567b431715b9) です。

直近リリースされたpnpm 12.4がなんと、JavaScript以外にRustとPythonのパッケージ管理をオプトインでサポートしました!

この変更の背景について、Astra(軽)のサポートを受けつつ、issueやpull requestの確認ログを残します。

目次

RFC: Cargo ecosystem — pnpm for Rust crates, pnpr as a crate registry - pnpm/rfcs#34 (Draft)

pnpm 12.4のリリースからリンクされている#14566(後述)に出てくるRFCをまず確認します。

Rust crateサポートのプロポーザルです。

Why: since the CLI rewrite in Rust, pnpm no longer dogfoods itself.

Rustで書き直したpnpm自身をドッグフーディングできていないことから提起しています。
pnpm CLI本体の依存管理がCargoに任され、pnpm自身の依存解決やストアなどを実地に検証できなくなったそうです。

提案内容(What the RFC proposes)の1つに、Rustの後にもさらに別のプログラミング言語をサポートしようと、Pythonが登場します

Independent ecosystem installers run concurrently and share one configured HTTP client, preserving the aggregate network limits; the coordinator is designed for later languages such as Python/PyPI.

Track multi-ecosystem install architecture hardening #14566

リリースで言及されてるissueです。

rfcs#34で見たように、Rust実装した後のドッグフーディングとして始まっていますが、このissueではJavaScriptとRust以外も見込んでいます(multi-ecosystem

Evolve the Cargo integration from #14547 into a multi-ecosystem install architecture that can add Python and other package ecosystems without coupling their resolver, manifest, or lockfile semantics. (Goal)

発想が野心的です。
そして3言語目としてPythonが選ばれました。

abstractions are extracted from working integrations; a working Python integration validates them before a stable adapter API is introduced (Invariants)

multi-ecosystem統合の内部APIを安定化する前に、Pythonサポートを実際に動かして、共通化の設計を検証する方針です。

feat(cli): integrate python with shared install and artifact lifecycles - #14586

先述のrfcの中でも言及されているpull requestです。

The architecture section records the real Python integration in pnpm/pnpm#14586: opt-in install/add/run/exec support, PEP 440/508 resolution, native wheels, shared HTTP/auth/CAS, and staged environment publication. (rfcs#34)

Replaces the fixture-only Python spike with an opt-in Python integration through the real pnpm v12 CLI, then extracts the shared install lifecycle exercised by npm, Cargo and Python.

私が手元で確認したようなpnpm add pypi:sampleprojectが、このプルリクエストでサポートされました!
変更内容については記事を改めます。

このプルリクエストからはplans/PYTHON_SPIKE.mdの存在を知りました。

終わりに

pnpm 12.4がPythonパッケージ管理もサポートした目的。
Python使いからすると「なぜ突然Pythonを?」となるかもしれませんが

  • pnpmは自身をRustで書き直した(v12.0〜)
  • 結果、pnpm CLIの依存管理がCargoになってpnpm自身はドッグフーディングできなくなった
    • そこでRust crateサポートが立ち上がった
  • Rust crateのサポートはさらに他のプログラミング言語のパッケージもサポートできるように進み、その中でPythonがまず実装された

pnpm自身の発展を踏まえると、multi-ecosystemという野心は突飛なものではないように思いますね。
そこに向かう過程として今はPythonサポートなんです。
今後、さらに別の言語のパッケージ管理へ広がることも期待してしまいます(どれくらいの難易度なのか私からは判断つきませんが)