mirror of
https://github.com/l0ng-ai/openidea.git
synced 2026-11-24 16:04:21 +00:00
feat(python): show the latest version of installed packages (#5433)
Settings › Python › Dependencies listed installed packages with their versions only, so finding out what can be upgraded meant running `pip list --outdated` in a terminal. The page now has a **Latest** column: once the installed list is shown, it asks the interpreter's package manager for newer releases in the background (`pip list --outdated --format json`, or `uv pip list --outdated` for uv environments) and marks the packages that can be upgraded. Asking pip instead of the PyPI JSON API gives the newest release this interpreter can install, from the index pip is configured to use, in one command. Co-authored-by: wildcatDownstairs <26499420+wildcatDownstairs@users.noreply.github.com>
This commit is contained in:
co-authored by
wildcatDownstairs
parent
e5f078913c
commit
b5bff2fdfa
@@ -411,12 +411,14 @@ pub async fn sdk_python_packages(
|
||||
host: &Host,
|
||||
window: &str,
|
||||
python: PathBuf,
|
||||
outdated: bool,
|
||||
request: RequestId,
|
||||
) -> IdeResult<Vec<PythonPackage>> {
|
||||
host.require_trust_if_project(window)?;
|
||||
let cancel = host.begin_project_request(window, request);
|
||||
let result =
|
||||
tokio::task::spawn_blocking(move || ide_sdk::python::list_packages(&python, &cancel)).await.map_err(join_err);
|
||||
let result = tokio::task::spawn_blocking(move || ide_sdk::python::list_packages(&python, outdated, &cancel))
|
||||
.await
|
||||
.map_err(join_err);
|
||||
host.end_request(request);
|
||||
result?
|
||||
}
|
||||
|
||||
@@ -225,7 +225,7 @@ fn package_of(metadata: &str) -> Option<PythonPackage> {
|
||||
.find_map(|l| l.strip_prefix(key).and_then(|v| v.strip_prefix(':')))
|
||||
.map(|v| v.trim().to_owned())
|
||||
};
|
||||
Some(PythonPackage { name: header("Name")?, version: header("Version").unwrap_or_default() })
|
||||
Some(PythonPackage { name: header("Name")?, version: header("Version").unwrap_or_default(), latest_version: None })
|
||||
}
|
||||
|
||||
/// The neutral interpreter for a container Python of `version`: an empty virtualenv in
|
||||
|
||||
@@ -14,6 +14,9 @@ use std::time::Duration;
|
||||
pub struct PythonPackage {
|
||||
pub name: String,
|
||||
pub version: String,
|
||||
/// The newest release the interpreter can install; only [`list_packages`] with `outdated` sets it.
|
||||
#[specta(optional)]
|
||||
pub latest_version: Option<String>,
|
||||
}
|
||||
|
||||
/// The tool that creates a new Python environment in "Add Python Interpreter".
|
||||
@@ -343,24 +346,97 @@ fn pip_env(python: &Path) -> Vec<(String, String)> {
|
||||
venv_of(python).map(|v| vec![("VIRTUAL_ENV".to_owned(), v.to_string_lossy().into_owned())]).unwrap_or_default()
|
||||
}
|
||||
|
||||
/// Installed packages (`pip list --format=json`), sorted by name.
|
||||
pub fn list_packages(python: &Path, cancel: &CancellationToken) -> IdeResult<Vec<PythonPackage>> {
|
||||
/// How long the check for newer releases may take in all: offline, pip waits for every
|
||||
/// package in turn.
|
||||
const OUTDATED_LIMIT: Duration = Duration::from_secs(120);
|
||||
|
||||
/// Installed packages (`pip list --format=json`), sorted by name. With `outdated`, only the
|
||||
/// ones the configured index has a newer release of (`--outdated`, which goes to the network).
|
||||
pub fn list_packages(python: &Path, outdated: bool, cancel: &CancellationToken) -> IdeResult<Vec<PythonPackage>> {
|
||||
if !python.is_file() {
|
||||
return Err(IdeError::not_found(format!("{} does not exist", python.display())));
|
||||
}
|
||||
let installer = installer(python)?;
|
||||
let (program, args) = pip_command(python, &installer, &["list", "--format", "json"]);
|
||||
let mut env = pip_env(python);
|
||||
if matches!(installer, Installer::Pip) {
|
||||
// Quiet mode suppresses the JSON package list, including with --format json.
|
||||
env.push(("PIP_QUIET".into(), "0".into()));
|
||||
}
|
||||
let mut sub = vec!["list", "--format", "json"];
|
||||
if outdated {
|
||||
sub.push("--outdated");
|
||||
// One retry, so a request that fails always prints pip's retry warning (`retries = 0`
|
||||
// in pip.conf would hide it); the command line wins over pip.conf and `PIP_RETRIES`.
|
||||
if matches!(installer, Installer::Pip) {
|
||||
sub.extend(["--retries", "1", "--timeout", "5"]);
|
||||
}
|
||||
}
|
||||
let (program, args) = pip_command(python, &installer, &sub);
|
||||
let dir = neutral_dir();
|
||||
let out = stream(&program, &args, dir.as_ref().map(|d| d.path()), &pip_env(python), cancel, &|_| {})?;
|
||||
let run =
|
||||
|cancel: &CancellationToken| stream(&program, &args, dir.as_ref().map(|d| d.path()), &env, cancel, &|_| {});
|
||||
let out = if outdated { with_deadline(cancel, OUTDATED_LIMIT, run)? } else { run(cancel)? };
|
||||
if outdated && pip_request_failed(&out) {
|
||||
return Err(IdeError::unavailable("pip could not reach the package index for every package"));
|
||||
}
|
||||
let mut packages = parse_pip_list(&out)?;
|
||||
packages.sort_by_key(|p| p.name.to_lowercase());
|
||||
Ok(packages)
|
||||
}
|
||||
|
||||
/// Runs `work` with a token that is also cancelled after `limit`; that is reported as timed out.
|
||||
pub(crate) fn with_deadline<T>(
|
||||
cancel: &CancellationToken,
|
||||
limit: Duration,
|
||||
work: impl FnOnce(&CancellationToken) -> IdeResult<T>,
|
||||
) -> IdeResult<T> {
|
||||
let token = cancel.child_token();
|
||||
let (done, finished) = std::sync::mpsc::channel::<()>();
|
||||
let timer = std::thread::spawn({
|
||||
let token = token.clone();
|
||||
move || {
|
||||
if finished.recv_timeout(limit) == Err(std::sync::mpsc::RecvTimeoutError::Timeout) {
|
||||
token.cancel();
|
||||
}
|
||||
}
|
||||
});
|
||||
let result = work(&token);
|
||||
drop(done);
|
||||
let _ = timer.join();
|
||||
match result {
|
||||
Err(e) if token.is_cancelled() && !cancel.is_cancelled() => Err(IdeError::new(
|
||||
ide_core::error::ErrorKind::TimedOut,
|
||||
format!("timed out after {} s: {e}", limit.as_secs()),
|
||||
)),
|
||||
other => other,
|
||||
}
|
||||
}
|
||||
|
||||
/// pip reports a package it could not look up as up to date: exit 0, the package left out of
|
||||
/// the list, and only its retry warnings. A warning means a request failed, so the list may
|
||||
/// be missing newer releases. (uv fails instead.)
|
||||
pub(crate) fn pip_request_failed(out: &str) -> bool {
|
||||
out.lines().any(|l| l.starts_with("WARNING: Retrying ("))
|
||||
}
|
||||
|
||||
pub(crate) fn parse_pip_list(out: &str) -> IdeResult<Vec<PythonPackage>> {
|
||||
#[derive(Deserialize)]
|
||||
struct Listed {
|
||||
name: String,
|
||||
version: String,
|
||||
latest_version: Option<String>,
|
||||
}
|
||||
// Skip the echoed command line and any warnings before the JSON array.
|
||||
let json = out.lines().find(|l| l.trim_start().starts_with('[')).unwrap_or("[]");
|
||||
serde_json::from_str(json).map_err(|e| IdeError::internal(format!("unexpected pip output: {e}")))
|
||||
let json = out
|
||||
.lines()
|
||||
.find(|l| l.trim_start().starts_with('['))
|
||||
.ok_or_else(|| IdeError::internal("unexpected pip output: missing package list"))?;
|
||||
let listed: Vec<Listed> =
|
||||
serde_json::from_str(json).map_err(|e| IdeError::internal(format!("unexpected pip output: {e}")))?;
|
||||
Ok(listed
|
||||
.into_iter()
|
||||
.map(|p| PythonPackage { name: p.name, version: p.version, latest_version: p.latest_version })
|
||||
.collect())
|
||||
}
|
||||
|
||||
/// A requirement naming a local path (`.`, `./pkg`, `../lib[dev]`) made absolute
|
||||
|
||||
@@ -1470,6 +1470,58 @@ fn pip_list_output_is_parsed() {
|
||||
let pkgs = parse_pip_list(out).unwrap();
|
||||
assert_eq!(pkgs[0].name, "requests");
|
||||
assert_eq!(pkgs[0].version, "2.32.0");
|
||||
assert_eq!(pkgs[0].latest_version, None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn outdated_pip_list_carries_the_latest_version() {
|
||||
// pip, then uv (compact JSON after a line about the environment).
|
||||
for out in [
|
||||
"$ python -m pip list --outdated\n[{\"name\": \"six\", \"version\": \"1.15.0\", \"latest_version\": \"1.17.0\", \"latest_filetype\": \"wheel\"}]\n",
|
||||
"Using Python 3.14.7 environment at: /venv\n[{\"name\":\"six\",\"version\":\"1.15.0\",\"latest_version\":\"1.17.0\",\"latest_filetype\":\"wheel\"}]\n",
|
||||
] {
|
||||
let pkgs = parse_pip_list(out).unwrap();
|
||||
assert_eq!(pkgs.len(), 1, "{out}");
|
||||
assert_eq!(pkgs[0].latest_version.as_deref(), Some("1.17.0"));
|
||||
}
|
||||
assert!(parse_pip_list("$ python -m pip list --outdated\n[]\n").unwrap().is_empty());
|
||||
assert!(parse_pip_list("$ python -m pip list --outdated\n").is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn pip_retry_warnings_mean_the_check_is_incomplete() {
|
||||
let warning = "WARNING: Retrying (Retry(total=0, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError(…)': /simple/six/";
|
||||
// Offline: nothing listed. Partly offline: some packages listed, others silently left out.
|
||||
for out in [
|
||||
format!("$ python -m pip list --outdated\n{warning}\n[]\n"),
|
||||
format!("{warning}\n[{{\"name\": \"idna\", \"version\": \"3.6\", \"latest_version\": \"3.20\"}}]\n"),
|
||||
] {
|
||||
assert!(crate::python::pip_request_failed(&out), "{out}");
|
||||
}
|
||||
assert!(!crate::python::pip_request_failed("$ python -m pip list --outdated\n[]\n"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_outdated_check_stops_at_its_deadline() {
|
||||
let cancel = ide_core::CancellationToken::new();
|
||||
let started = std::time::Instant::now();
|
||||
let result: ide_core::IdeResult<()> =
|
||||
crate::python::with_deadline(&cancel, std::time::Duration::from_millis(100), |token| {
|
||||
while !token.is_cancelled() {
|
||||
std::thread::sleep(std::time::Duration::from_millis(10));
|
||||
}
|
||||
Err(ide_core::IdeError::cancelled())
|
||||
});
|
||||
assert_eq!(result.unwrap_err().kind, ide_core::error::ErrorKind::TimedOut);
|
||||
assert!(started.elapsed() < std::time::Duration::from_secs(5));
|
||||
// Finishing in time, or being cancelled by the caller, is reported as such.
|
||||
assert!(crate::python::with_deadline(&cancel, std::time::Duration::from_secs(60), |_| Ok(())).is_ok());
|
||||
cancel.cancel();
|
||||
let result: ide_core::IdeResult<()> =
|
||||
crate::python::with_deadline(&cancel, std::time::Duration::from_secs(60), |_| {
|
||||
Err(ide_core::IdeError::cancelled())
|
||||
});
|
||||
assert_eq!(result.unwrap_err().kind, ide_core::error::ErrorKind::Cancelled);
|
||||
}
|
||||
|
||||
/// A directory whose `typing.py` breaks any interpreter that imports it from there.
|
||||
|
||||
@@ -81,7 +81,7 @@ You can also select an existing interpreter or environment folder. The new inter
|
||||
|
||||
### Packages
|
||||
|
||||
The same page lists the installed packages of the selected interpreter. You can search them, **Install** a package by name, **Upgrade** and **Uninstall**. The IDE uses the interpreter's pip, or `uv pip` for environments without pip (uv creates them that way).
|
||||
The same page lists the installed packages of the selected interpreter. You can search them, **Install** a package by name, **Upgrade** and **Uninstall**. The IDE uses the interpreter's pip, or `uv pip` for environments without pip (uv creates them that way). The **Latest** column marks the packages that have a newer release: after the list loads, the IDE asks the same tool (`pip list --outdated`, or `uv pip list --outdated`), so the answer comes from the index that tool is configured to use (pip's configuration for pip, uv's for uv) and is the newest release that the interpreter can install. When the index cannot be reached for every package, or the check takes more than two minutes, the page says the check failed rather than show a list that may be missing upgrades.
|
||||
|
||||
Other options on the page:
|
||||
|
||||
|
||||
@@ -81,7 +81,7 @@ Ruff 只为位于 Ruff 配置之下的文件启动:`ruff.toml`、`.ruff.toml`
|
||||
|
||||
### 软件包
|
||||
|
||||
同一页面会列出所选解释器已安装的软件包,可以搜索、按名称 **安装**、**升级** 和 **卸载**。IDE 使用解释器自带的 pip;没有 pip 的环境(uv 创建的环境默认如此)改用 `uv pip`。
|
||||
同一页面会列出所选解释器已安装的软件包,可以搜索、按名称 **安装**、**升级** 和 **卸载**。IDE 使用解释器自带的 pip;没有 pip 的环境(uv 创建的环境默认如此)改用 `uv pip`。**最新版本** 列会标出有新版本的软件包:列表加载后,IDE 用同一工具查询(`pip list --outdated` 或 `uv pip list --outdated`),因此结果来自该工具配置的索引(pip 用 pip 的配置,uv 用 uv 的配置),并且是该解释器可以安装的最新版本。如果有软件包无法访问索引,或者检查超过两分钟,页面会提示检查失败,而不是显示一份可能漏掉升级的列表。
|
||||
|
||||
页面上的其他选项:
|
||||
|
||||
|
||||
+3
-1
@@ -1678,7 +1678,7 @@ export const commands = {
|
||||
/** Rust standard library sources, Go default GOPATH. */
|
||||
extra: IpcPath | null,
|
||||
} | null, IdeError>(__TAURI_INVOKE("sdk_python_interpreter", { path })),
|
||||
sdkPythonPackages: (python: string, request: RequestId) => typedError<PythonPackage[], IdeError>(__TAURI_INVOKE("sdk_python_packages", { python, request })),
|
||||
sdkPythonPackages: (python: string, outdated: boolean, request: RequestId) => typedError<PythonPackage[], IdeError>(__TAURI_INVOKE("sdk_python_packages", { python, outdated, request })),
|
||||
/** Installs (`uninstall = false`) or removes a package; output streams through `on_output`. */
|
||||
sdkPythonPip: (python: string, requirement: string, uninstall: boolean, upgrade: boolean, request: RequestId, onOutput: Channel<string>) => typedError<null, IdeError>(__TAURI_INVOKE("sdk_python_pip", { python, requirement, uninstall, upgrade, request, onOutput })),
|
||||
/** The Python interpreters of the recently opened projects, each with its project. */
|
||||
@@ -11370,6 +11370,8 @@ export type PythonMethodFacts = {
|
||||
export type PythonPackage = {
|
||||
name: string,
|
||||
version: string,
|
||||
/** The newest release the interpreter can install; only [`list_packages`] with `outdated` sets it. */
|
||||
latestVersion?: string | null,
|
||||
};
|
||||
|
||||
export type PythonRequirements = {
|
||||
|
||||
@@ -7,6 +7,7 @@ const mocks = vi.hoisted(() => ({
|
||||
refresh: vi.fn(),
|
||||
packages: vi.fn(),
|
||||
effective: vi.fn(),
|
||||
cancel: vi.fn(),
|
||||
}));
|
||||
vi.mock("@/platform/ipc", async (importOriginal) => {
|
||||
const real = await importOriginal<typeof import("@/platform/ipc")>();
|
||||
@@ -20,6 +21,7 @@ vi.mock("@/platform/ipc", async (importOriginal) => {
|
||||
sdkContainerPythonRefresh: mocks.refresh,
|
||||
sdkPythonPackages: mocks.packages,
|
||||
sdkPythonEffective: mocks.effective,
|
||||
cancelRequest: mocks.cancel,
|
||||
},
|
||||
};
|
||||
});
|
||||
@@ -105,6 +107,53 @@ describe("run target interpreter", () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe("newer versions", () => {
|
||||
const INSTALLED = [
|
||||
{ name: "requests", version: "2.34.2" },
|
||||
{ name: "six", version: "1.15.0" },
|
||||
];
|
||||
const listing = (outdated: () => Promise<unknown>) =>
|
||||
mocks.packages.mockImplementation((_python: string, wantOutdated: boolean) =>
|
||||
wantOutdated ? outdated() : Promise.resolve(ok(INSTALLED)),
|
||||
);
|
||||
|
||||
it("marks the packages that have a newer release once the list shows", async () => {
|
||||
mocks.effective.mockResolvedValue(ok("/p/.venv/bin/python"));
|
||||
listing(async () => ok([{ name: "six", version: "1.15.0", latestVersion: "1.17.0" }]));
|
||||
mount("");
|
||||
expect(await screen.findByTitle("Upgrade available: 1.17.0")).toHaveTextContent("1.17.0");
|
||||
expect(screen.getByRole("row", { name: "requests 2.34.2" })).toBeInTheDocument();
|
||||
expect(screen.getByRole("row", { name: "six 1.15.0 1.17.0" })).toBeInTheDocument();
|
||||
expect(mocks.packages.mock.calls.map((c) => c[1])).toEqual([false, true]);
|
||||
});
|
||||
|
||||
it("keeps the list and says so when the check fails", async () => {
|
||||
mocks.effective.mockResolvedValue(ok("/p/.venv/bin/python"));
|
||||
listing(async () => ({ status: "error", error: { kind: "unavailable", message: "no network" } }));
|
||||
mount("");
|
||||
expect(await screen.findByText("Could not check for newer versions of the packages.")).toBeInTheDocument();
|
||||
expect(screen.getByText("six")).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("cancels a check still running when the page closes", async () => {
|
||||
mocks.effective.mockResolvedValue(ok("/p/.venv/bin/python"));
|
||||
listing(() => new Promise(() => {}));
|
||||
mount("");
|
||||
expect(await screen.findByText("six")).toBeInTheDocument();
|
||||
await waitFor(() => expect(mocks.packages).toHaveBeenCalledTimes(2));
|
||||
expect(mocks.cancel).not.toHaveBeenCalled();
|
||||
cleanup();
|
||||
expect(mocks.cancel).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
it("does not check a container interpreter", async () => {
|
||||
mount("target:web");
|
||||
expect(await screen.findByText("Django")).toBeInTheDocument();
|
||||
expect(screen.queryByRole("columnheader", { name: "Latest" })).toBeNull();
|
||||
expect(mocks.packages).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
describe("missing interpreter", () => {
|
||||
it("reports the applied interpreter gone, not one chosen and not applied yet", async () => {
|
||||
const { stage } = await import("../model/staging");
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
import { isCancelled } from "@/platform/ipc";
|
||||
import { useCallback, useEffect, useMemo, useState, type KeyboardEvent, type MouseEvent } from "react";
|
||||
import clsx from "clsx";
|
||||
import { Button, IconButton, Input, Spinner, showContextMenu, T } from "@/ui";
|
||||
import { Button, Icon, IconButton, Input, Spinner, showContextMenu, T } from "@/ui";
|
||||
import { useProject } from "@/platform/project";
|
||||
import { Section, Toggle } from "../components/Form";
|
||||
import {
|
||||
@@ -16,6 +16,7 @@ import {
|
||||
effectivePython,
|
||||
interpreterTarget,
|
||||
listPackages,
|
||||
outdatedPackages,
|
||||
pip,
|
||||
refreshContainerPython,
|
||||
targetChoices,
|
||||
@@ -51,26 +52,50 @@ function usePackages(python: string | null) {
|
||||
packages: PythonPackage[] | null;
|
||||
error: string | null;
|
||||
} | null>(null);
|
||||
// Newer releases by package name; `null` when the check failed.
|
||||
const [newer, setNewer] = useState<{ key: string; python: string; versions: Map<string, string> | null } | null>(
|
||||
null,
|
||||
);
|
||||
useEffect(() => {
|
||||
if (!python) return;
|
||||
let live = true;
|
||||
let check: ReturnType<typeof outdatedPackages> | undefined;
|
||||
const key = `${python}#${tick}`;
|
||||
listPackages(python)
|
||||
.then((packages) => live && setResult({ key, python, packages, error: null }))
|
||||
.then((packages) => {
|
||||
if (!live) return;
|
||||
setResult({ key, python, packages, error: null });
|
||||
// The list shows first: this asks the package index.
|
||||
check = outdatedPackages(python);
|
||||
check.promise
|
||||
.then(
|
||||
(outdated) =>
|
||||
live &&
|
||||
setNewer({ key, python, versions: new Map(outdated.map((p) => [p.name, p.latestVersion ?? p.version])) }),
|
||||
() => live && setNewer({ key, python, versions: null }),
|
||||
)
|
||||
.finally(() => (check = undefined));
|
||||
})
|
||||
.catch(
|
||||
(e: unknown) => live && setResult({ key, python, packages: null, error: String((e as Error)?.message ?? e) }),
|
||||
);
|
||||
return () => {
|
||||
live = false;
|
||||
check?.cancel();
|
||||
};
|
||||
}, [python, tick]);
|
||||
const reload = useCallback(() => setTick((t) => t + 1), []);
|
||||
// While reloading the same interpreter, keep showing its previous list.
|
||||
const same = !!python && result?.python === python;
|
||||
const key = `${python}#${tick}`;
|
||||
const listed = same && result.key === key && !!result.packages;
|
||||
return {
|
||||
packages: same ? result.packages : null,
|
||||
error: same ? result.error : null,
|
||||
loading: !!python && result?.key !== `${python}#${tick}`,
|
||||
loading: !!python && result?.key !== key,
|
||||
newer: same && newer?.python === python ? newer.versions : null,
|
||||
checking: listed && newer?.key !== key,
|
||||
checkFailed: listed && newer?.key === key && !newer.versions,
|
||||
reload,
|
||||
};
|
||||
}
|
||||
@@ -185,6 +210,7 @@ export function PythonInterpreterPage() {
|
||||
// Without a configured interpreter the project's virtualenv is used (like run configurations).
|
||||
const python = target ? null : interpreter || auto;
|
||||
const local = usePackages(python);
|
||||
const { newer, checking, checkFailed } = local;
|
||||
const { packages, error, loading, reload } = target
|
||||
? {
|
||||
packages: container.info?.version ? container.info.packages : null,
|
||||
@@ -333,7 +359,12 @@ export function PythonInterpreterPage() {
|
||||
onClick={reload}
|
||||
/>
|
||||
<span className={styles.spacer} />
|
||||
{(loading || job) && <Spinner size={14} label={job ? `${job.op} ${job.target}` : "Loading packages"} />}
|
||||
{(loading || job || checking) && (
|
||||
<Spinner
|
||||
size={14}
|
||||
label={job ? `${job.op} ${job.target}` : loading ? "Loading packages" : "Checking for newer versions"}
|
||||
/>
|
||||
)}
|
||||
<Input
|
||||
className={styles.search}
|
||||
value={query}
|
||||
@@ -379,6 +410,11 @@ export function PythonInterpreterPage() {
|
||||
<th scope="col">
|
||||
<T>Version</T>
|
||||
</th>
|
||||
{!target && (
|
||||
<th scope="col">
|
||||
<T>Latest</T>
|
||||
</th>
|
||||
)}
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@@ -394,6 +430,7 @@ export function PythonInterpreterPage() {
|
||||
>
|
||||
<td>{p.name}</td>
|
||||
<td className={styles.versionCell}>{p.version}</td>
|
||||
{!target && <td className={styles.versionCell}>{latestCell(p, newer)}</td>}
|
||||
</tr>
|
||||
))}
|
||||
</tbody>
|
||||
@@ -419,6 +456,11 @@ export function PythonInterpreterPage() {
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{checkFailed && (
|
||||
<div className={styles.note}>
|
||||
<T>Could not check for newer versions of the packages.</T>
|
||||
</div>
|
||||
)}
|
||||
{target && (
|
||||
<div className={styles.note}>
|
||||
<T>
|
||||
@@ -475,6 +517,18 @@ export function PythonInterpreterPage() {
|
||||
);
|
||||
}
|
||||
|
||||
/** The newer release of `pkg`, marked as an upgrade; nothing for a package that is up to date. */
|
||||
function latestCell(pkg: PythonPackage, newer: Map<string, string> | null) {
|
||||
const latest = newer?.get(pkg.name);
|
||||
if (!latest || latest === pkg.version) return null;
|
||||
return (
|
||||
<span className={styles.upgradable} title={tx`Upgrade available: ${latest}`}>
|
||||
<Icon name="arrow-up" size={12} />
|
||||
{latest}
|
||||
</span>
|
||||
);
|
||||
}
|
||||
|
||||
/** Whether `resolved` (an absolute path from the backend) is the configured `interpreter` setting. */
|
||||
function sameInterpreter(resolved: string | null, interpreter: string, root: string | null): boolean {
|
||||
if (!resolved) return false;
|
||||
|
||||
@@ -123,6 +123,12 @@
|
||||
color: var(--fg-secondary);
|
||||
font-variant-numeric: tabular-nums;
|
||||
}
|
||||
.upgradable {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: var(--space-1);
|
||||
color: var(--link);
|
||||
}
|
||||
|
||||
/* Settings › Python › All Interpreters (PyCharm's "All interpreters"). */
|
||||
.interpretersRow {
|
||||
|
||||
@@ -167,7 +167,16 @@ export function pythonProjectInterpreters(): Promise<ProjectInterpreter[]> {
|
||||
}
|
||||
|
||||
export function listPackages(python: string): Promise<PythonPackage[]> {
|
||||
return call(commands.sdkPythonPackages(python, nextRequestId()));
|
||||
return call(commands.sdkPythonPackages(python, false, nextRequestId()));
|
||||
}
|
||||
|
||||
/** The packages with a newer release (`latestVersion`). Asks the package index, so it can take a while. */
|
||||
export function outdatedPackages(python: string): { promise: Promise<PythonPackage[]>; cancel: () => void } {
|
||||
const request = nextRequestId();
|
||||
return {
|
||||
promise: call(commands.sdkPythonPackages(python, true, request)),
|
||||
cancel: () => void commands.cancelRequest(request),
|
||||
};
|
||||
}
|
||||
|
||||
export function pip(
|
||||
|
||||
@@ -3744,6 +3744,10 @@
|
||||
"Pipenv Environment": "Pipenv Environment",
|
||||
"Install packages from Pipfile": "Install packages from Pipfile",
|
||||
"Runs “pipenv --python <base>” in the project, which writes a Pipfile (from requirements.txt if there is one) when the project has none. Pipenv chooses where to store the environment and reuses an existing one.": "Runs “pipenv --python <base>” in the project, which writes a Pipfile (from requirements.txt if there is one) when the project has none. Pipenv chooses where to store the environment and reuses an existing one.",
|
||||
"Latest": "Latest",
|
||||
"Checking for newer versions": "Checking for newer versions",
|
||||
"Could not check for newer versions of the packages.": "Could not check for newer versions of the packages.",
|
||||
"Upgrade available: {latest}": "Upgrade available: {latest}",
|
||||
"Rearrange Code": "Rearrange Code",
|
||||
"Nothing to rearrange: members are in order, or moving them could change the class": "Nothing to rearrange: members are in order, or moving them could change the class",
|
||||
"The file changed while rearranging; try again": "The file changed while rearranging; try again"
|
||||
|
||||
@@ -9980,6 +9980,10 @@
|
||||
"Pipenv Environment": "Pipenv 环境",
|
||||
"Install packages from Pipfile": "安装 Pipfile 中的软件包",
|
||||
"Runs “pipenv --python <base>” in the project, which writes a Pipfile (from requirements.txt if there is one) when the project has none. Pipenv chooses where to store the environment and reuses an existing one.": "在项目中运行“pipenv --python <base>”。项目没有 Pipfile 时会写入一个(有 requirements.txt 时从中导入)。环境的存放位置由 Pipenv 决定,已有环境会被复用。",
|
||||
"Latest": "最新版本",
|
||||
"Checking for newer versions": "正在检查新版本",
|
||||
"Could not check for newer versions of the packages.": "无法检查软件包的新版本。",
|
||||
"Upgrade available: {latest}": "可升级到 {latest}",
|
||||
"Rearrange Code": "重新排列代码",
|
||||
"Nothing to rearrange: members are in order, or moving them could change the class": "无需重新排列:成员已按顺序排列,或移动它们可能改变类的行为",
|
||||
"The file changed while rearranging; try again": "重新排列期间文件已更改,请重试"
|
||||
|
||||
Reference in New Issue
Block a user