feat(core): the environment's pip version, out of a probe that already knew it

P0-10 wants pip's version on every Environments row. The obvious source is engine_info —
and it is the wrong one: it spawns two subprocesses per call, pip's --version and uv's, so
per row that is 2N spawns added to the landing screen on top of the N probe.py runs already
happening there.

The data was already computed and thrown away. pip is an ordinary distribution in
site-packages, `probe_row` holds `probed.dists`, and `packages` is that same list's length.
Reading one more field off it costs nothing and needs no probe.py change, so CLAUDE.md's
hot-path warning does not apply.

env_probe carries it too, and that is load-bearing rather than tidy: refreshing one row
after an upgrade is exactly what that command is for in the next commit, and a refresh
through a path that omitted the field would blank the thing it was refreshing to update.
The compiler caught it, which is the argument for the field not being Option-defaulted.

`pipdock env list --json` grows the same field off the same list, so the two heads cannot
disagree about which pip is installed.

Absent means the probe found no pip — a --without-pip venv, or -I hiding a user-site
install — which is a real state, not "not yet known".

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
poli0981andClaude Opus 5 committed 2026-08-12 22:45:02 +07:00
1 parent 5bd21de203
commit 3ccd93e9f1
4 files changed
+49 -4

No files matched your search

+3 -3
View File
@@ -16,9 +16,9 @@ dist-ssr/
# Environments (test venvs created by the integration suite / spikes)
.venv/
venv/
# Verifying an environment feature by hand needs a venv the GUI can *see*, and `env_add_manual`
# (Browse…) is still owed — so venv_scan's "below the working directory" is the only way in, which
# means the repo root. `.venv-oldpip` for the pip-upkeep floor, and whatever the next one needs.
# Scratch venvs for verifying by hand. Note that the GUI will only ever *see* one named exactly
# `.venv`, `venv`, `env` or `.env` in the working directory — `envs::venv_scan` matches that fixed
# list and `env_add_manual` (Browse…) is still owed — so a suffixed one here is CLI-only.
/.venv-*/
__pycache__/
*.py[cod]
+5
View File
@@ -197,6 +197,11 @@ pub async fn env_list(opts: &GlobalOpts) -> Result<Exit> {
"hiddenUserSite": p.env.hidden_user_site,
"packages": p.dists.len(),
"envHash": envs::env_hash(path),
// Same field the GUI's EnvRow carries, out of the same list, so `env list`
// and the Environments screen cannot disagree about which pip is installed.
"pipVersion": p.dists.iter()
.find(|d| d.name.as_str() == "pip")
.map(|d| d.version.0.clone()),
}),
Err(e) => serde_json::json!({
"interpreter": path,
+33 -1
View File
@@ -87,6 +87,19 @@ pub struct EnvRow {
/// How many distributions the probe saw.
#[serde(skip_serializing_if = "Option::is_none")]
pub packages: Option<usize>,
/// The environment's own pip, when it has one (PRD P0-10).
///
/// **Read out of the probe's distribution list, not from `engine_info`.** `engine_info` spawns
/// two subprocesses per call — pip's `--version` and uv's — so calling it per row would add
/// 2N spawns to the landing screen on top of the N `probe.py` runs already happening. pip is
/// an ordinary distribution in site-packages and the probe has already read it; this is the
/// same list `packages` counts.
///
/// `None` means the probe found no pip, which is a real state — a `--without-pip` venv, or a
/// system Python where `-I` hid a user-site install (ARCHITECTURE §4's trade-off, disclosed as
/// `hidden_user_site`). It is not "unknown".
#[serde(skip_serializing_if = "Option::is_none")]
pub pip_version: Option<String>,
/// Present when the probe failed; the row renders as unusable with this code.
#[serde(skip_serializing_if = "Option::is_none")]
pub error: Option<WireError>,
@@ -101,6 +114,7 @@ async fn probe_row(path: std::path::PathBuf, source: EnvSource) -> EnvRow {
source,
env_hash,
packages: Some(probed.dists.len()),
pip_version: pip_version_of(&probed.dists),
env: Some(probed.env),
error: None,
},
@@ -110,11 +124,23 @@ async fn probe_row(path: std::path::PathBuf, source: EnvSource) -> EnvRow {
env_hash,
env: None,
packages: None,
pip_version: None,
error: Some(e.into()),
},
}
}
/// pip's version out of a probed distribution list.
///
/// Names arrive PEP 503-normalized from `PkgName::parse`, so an exact match is enough — there is no
/// casing or separator variant of `pip` to worry about.
fn pip_version_of(dists: &[pipdock_core::Dist]) -> Option<String> {
dists
.iter()
.find(|d| d.name.as_str() == "pip")
.map(|d| d.version.0.clone())
}
/// Discover environments, streaming `scan-progress` as each source is read.
///
/// # Errors
@@ -135,7 +161,12 @@ pub async fn env_scan(app: tauri::AppHandle) -> Wire<Vec<EnvRow>> {
Ok(rows)
}
/// Probe one interpreter, for the manual *Browse…* path.
/// Probe one interpreter, for the manual *Browse…* path — and to refresh a single row.
///
/// The second use is what P0-10 needs: after `pip_upgrade` the Environments row must show the new
/// version without a full rescan, and one probe is the cheapest honest way to get it. That makes
/// carrying `pip_version` here load-bearing rather than tidy — a row refreshed through a path that
/// omitted it would blank the field it was refreshed to update.
///
/// # Errors
/// `PD-ENV-001` when there is no usable interpreter there, `PD-ENV-003` when the probe output
@@ -149,6 +180,7 @@ pub async fn env_probe(interpreter: String) -> Wire<EnvRow> {
source: EnvSource::Manual,
env_hash: envs::env_hash(&path),
packages: Some(probed.dists.len()),
pip_version: pip_version_of(&probed.dists),
env: Some(probed.env),
error: None,
})
+8
View File
@@ -124,6 +124,14 @@ export interface EnvRow {
envHash: string
env?: PyEnv
packages?: number
/**
* The environment's own pip, out of the probe's distribution list — not `engine_info`, which
* would add two subprocesses per row to the landing screen.
*
* Absent means the probe found no pip, which is a real state (`--without-pip`, or `-I` hiding a
* user-site install), not "not yet known".
*/
pipVersion?: string
error?: PdError
}