fix(python): accept direct references and bzr+lp URLs, report a missing path, and keep editable cleared after an archive (#6650)

Follow-up to #6617. The version control dialog now accepts pip's direct references (name @ git+https://..., with extras) and bzr+lp:project. Installing from a local path that does not exist fails before pip runs, with the path in the message; a trailing [extras] is not part of the path, and a folder whose name has brackets is still a folder. Typing an archive path clears the editable choice, so a directory typed after it starts unticked.

Co-authored-by: wildcatDownstairs <[email protected]>
Цей коміт міститься в:
LU XIANGRUIтаwildcatDownstairs authored and GitHub committed 2026-11-28 14:57:21 +08:00
1 джерело 8108b440a6
коміт d5ba63e333
6 files changed
+68 -10

No files matched your search

+5
Переглянути файл
@@ -156,8 +156,13 @@ describe("Python Packages", () => {
const path = await screen.findByRole("textbox", { name: "Path" });
fireEvent.change(path, { target: { value: "--index-url=https://evil.example" } });
expect(screen.getByRole("button", { name: "Install" })).toBeDisabled();
// Editable, then an archive, then a directory again: the archive cleared the choice.
fireEvent.change(path, { target: { value: "pkgs/mylib" } });
fireEvent.click(screen.getByRole("checkbox", { name: "Install as editable (-e)" }));
fireEvent.change(path, { target: { value: "dist/mylib-0.1.0-py3-none-any.whl" } });
expect(screen.getByRole("checkbox", { name: "Install as editable (-e)" })).toBeDisabled();
fireEvent.change(path, { target: { value: "pkgs/mylib" } });
expect(screen.getByRole("checkbox", { name: "Install as editable (-e)" })).not.toBeChecked();
// A bare name is a directory here, never a PyPI package.
fireEvent.change(path, { target: { value: "mylib" } });
fireEvent.click(screen.getByRole("checkbox", { name: "Install as editable (-e)" }));
+6 -7
Переглянути файл
@@ -546,7 +546,11 @@ function InstallFromDialog({
source === "vcs" ? "git+https://github.com/owner/project.git" : tx("Project directory or archive")
}
aria-label={source === "vcs" ? "Repository URL" : "Path"}
onChange={(e) => setValue(e.target.value)}
onChange={(e) => {
setValue(e.target.value);
// An archive can't be editable; a directory typed after it starts unticked.
if (isArchive(e.target.value)) setEditable(false);
}}
onKeyDown={(e) => e.key === "Enter" && install()}
/>
{source === "disk" && (
@@ -562,12 +566,7 @@ function InstallFromDialog({
)}
</div>
{source === "disk" && (
<Checkbox
checked={canEdit && editable}
onChange={setEditable}
disabled={!canEdit}
label="Install as editable (-e)"
/>
<Checkbox checked={editable} onChange={setEditable} disabled={!canEdit} label="Install as editable (-e)" />
)}
</div>
</Dialog>
+16
Переглянути файл
@@ -100,6 +100,21 @@ describe("install from version control or disk", () => {
expect(isVcsUrl("hg+https://hg.example.org/demo")).toBe(true);
expect(isVcsUrl(vcsRequirement("requests"))).toBe(false);
expect(isVcsUrl(vcsRequirement("file:///tmp/pkg"))).toBe(false);
for (const url of [
"git+ssh://[email protected]/psf/requests.git",
"git+file:///work/repo",
"hg+https://hg.example.org/demo",
"svn+svn://svn.example.org/demo/trunk",
"bzr+lp:demo",
"git+https://github.com/psf/[email protected]",
"git+https://github.com/o/r.git#egg=demo&subdirectory=pkgs/demo",
"requests @ git+https://github.com/psf/requests.git",
"demo[cli] @ git+https://github.com/o/r.git",
])
expect(isVcsUrl(url), url).toBe(true);
expect(isVcsUrl("requests @ https://example.org/requests.zip")).toBe(false);
for (const url of ["git+https:foo", "git+ssh:git@host:o/r", "requests @ git+https:foo"])
expect(isVcsUrl(url), url).toBe(false);
});
it("never lets a typed path read as a PyPI name", () => {
@@ -112,5 +127,6 @@ describe("install from version control or disk", () => {
expect(isArchive("dist/demo-1.0.tar.gz")).toBe(true);
expect(isArchive("dist/demo-1.0-py3-none-any.whl")).toBe(true);
expect(isArchive("pkgs/demo")).toBe(false);
expect(isArchive(" dist/demo-1.0-py3-none-any.whl ")).toBe(true);
});
});
+6 -2
Переглянути файл
@@ -68,8 +68,12 @@ export function vcsRequirement(url: string) {
return scp ? `git+ssh://${scp[1]}/${scp[2]}` : text;
}
/** Whether `url` (after {@link vcsRequirement}) is a version control URL pip can install. */
export const isVcsUrl = (url: string) => /^(git|hg|svn|bzr)\+[a-z]+:\/\/\S+$/i.test(url);
/**
* Whether `url` (after {@link vcsRequirement}) is a version control URL pip can install, bare
* (`git+https://…`, `bzr+lp:project`) or as a direct reference (`name @ git+https://…`).
*/
export const isVcsUrl = (url: string) =>
/^([A-Za-z0-9][\w.-]*(\[[^\]]*\])?\s*@\s*)?((git|hg|svn|bzr)\+[a-z]+:\/\/|bzr\+lp:)\S+$/i.test(url);
/**
* A path typed for Install from Disk, made explicit so pip never reads it as a PyPI name: a