Hatch: the uv-installer check reads the pyproject.toml environments that hatch.toml replaces, and refuses a pip project

未關閉 適合新手
#2,259 0 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

維護者通常 1 天內回覆

還沒有人認領這個 Issue。

評估

難度
2/5
預估耗時
1-3 小時
新手友好度
82/100
Issue 類型
缺陷
描述清晰度
描述清楚
活躍度
活躍
技術堆疊
rust
領域
backend, devtools

研究方向

從 crates/socket-patch-core/src/utils/hatch.rs 開始,閱讀 merged_key、require_pip_installer_documents 以及 issue 中提到的三個呼叫端。為 envs 被取代的情況新增一個單元測試,並確保兩個 fail-closed 情況仍有涵蓋。執行 socket-patch-core 函式庫測試。當被取代的 pyproject.toml 環境不再導致 uv 錯誤拒絕,而啟用中的 uv 設定仍會導致拒絕時,任務即完成。

由索引模型根據 Issue 內容生成。

描述

agent:triaged arch-audit bug priority:p1

[agent] Filed by the architecture refactor routine (lead L06, run on main at 9a2a946).

Kind: bug, a drifted copy of one rule. Low harm: the wrong answer is a refusal.

Problem

Hatch reads its settings from pyproject.toml ([tool.hatch]) and hatch.toml, and a top-level key in hatch.toml replaces the [tool.hatch] key of the same name. So when hatch.toml has an envs table, the environments under [tool.hatch.envs] in pyproject.toml are dead configuration.

merged_key implements that rule, and the lock detection and the dependency walk use it. require_pip_installer_documents does not: it looks for installer = "uv" or a uv-path in the envs table of every document. A project whose replaced pyproject.toml environments still say installer = "uv" is treated as a uv project although Hatch installs it with pip.

Two things follow, both refusals with the wrong reason:

  • Vendored mode refuses the project: pypi_hatch_unsupported, "vendored Hatch wheels require the pip installer: uv does not enforce local wheel fragment hashes" (pypi_hatch::preflight).
  • uv_source_names takes the same answer, so a hosted run refuses a project requirement that has a [tool.uv.sources] entry ("Hatch's uv installer resolves it through its [tool.uv.sources] entry…") in a project where pip ignores that table.

The check never fails open: a hatch.toml that selects uv, or a pyproject.toml that does with no envs in hatch.toml, is still refused.

Evidence

A throwaway test in utils/hatch.rs (not committed) feeds one project to both readers:

let uv = "\n[tool.hatch.envs.default]\ninstaller = \"uv\"\n";
// A: pyproject says uv; hatch.toml's `envs` replaces it, so Hatch uses pip.
let a = files(uv, Some("[envs.default]\ndependencies = []\n"));
// D: the same shape with `locked = true`, for the reader that follows the merge.
let d = files("\n[tool.hatch.envs.default]\nlocked = true\n", Some("[envs.default]\ndependencies = []\n"));
println!("PROBE A require_pip_installer = {:?}", require_pip_installer(&a));
println!("PROBE D is_hatch_lock = {:?}", is_hatch_lock(&d, "pylock.toml"));
$ cargo test -p socket-patch-core --lib probe_ -- --nocapture
PROBE A require_pip_installer = Err("vendored Hatch wheels require the pip installer: uv does not enforce local wheel fragment hashes")
PROBE D is_hatch_lock = false

is_hatch_lock ignores the replaced pyproject.toml environments (as hatch_lock_detection_follows_the_config_merge pins); require_pip_installer reads them.

Planned fix

require_pip_installer_documents reads the one envs table Hatch uses, through merged_key(pyproject, hatch_toml, "envs"), instead of walking each document. Its three callers (require_pip_installer, uv_source_names, run_round) keep their signatures or pass the two documents. A unit test gives project A to require_pip_installer and expects Ok, and keeps the two fail-closed cases refused.

About 20 changed production lines in crates/socket-patch-core/src/utils/hatch.rs.


Generated by Claude Code

主要語言
Rust
星號
9
分支
2
平均合併
1 天 8 小時
30 天內合併 PR
313

環境準備

  • 沒有 Dockerfile 或 Docker Compose 檔案
  • 沒有 Pull Request 範本
  • 閱讀貢獻指南

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

SocketDev/socket-patch 的其他 Issue

查看 SocketDev/socket-patch 的全部 Issue

相似的 Issue

更多 Rust Issue

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。