дзеркало
https://github.com/l0ng-ai/openidea.git
синхронізовано 2026-12-04 09:11:10 +02:00
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]>
Цей коміт міститься в:
1 джерело
8108b440a6
коміт
d5ba63e333
6 files changed
+68
-10
No files matched your search
@@ -637,8 +637,16 @@ pub fn install_package(
|
||||
return Err(IdeError::invalid("enter a package name or requirement"));
|
||||
}
|
||||
let requirement = resolve_requirement(requirement, project_root)?;
|
||||
// A path (a requirement never starts with a root), maybe with `[extras]` after it.
|
||||
let path = Path::new(&requirement).has_root().then_some(requirement.as_str());
|
||||
if let Some(path) = path {
|
||||
let without_extras = path.strip_suffix(']').and_then(|p| p.rsplit_once('[')).map(|(p, _)| p);
|
||||
if !Path::new(path).exists() && !without_extras.is_some_and(|p| Path::new(p).exists()) {
|
||||
return Err(IdeError::not_found(format!("{} does not exist", without_extras.unwrap_or(path))));
|
||||
}
|
||||
}
|
||||
// An editable clone of a repository would go where pip runs, a temporary folder.
|
||||
if editable && !Path::new(&requirement).is_absolute() {
|
||||
if editable && path.is_none() {
|
||||
return Err(IdeError::invalid("only a local directory can be installed in editable mode"));
|
||||
}
|
||||
let installer = installer(python)?;
|
||||
|
||||
@@ -1919,6 +1919,32 @@ fn editable_installs_put_e_right_before_the_path() {
|
||||
assert_eq!(install_args("six", true, false), ["install", "--upgrade", "six"]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_missing_local_path_is_reported_before_pip_runs() {
|
||||
let root = tempfile::tempdir().unwrap();
|
||||
let install = |requirement: &str| {
|
||||
crate::python::install_package(
|
||||
Path::new("/nonexistent/python"),
|
||||
requirement,
|
||||
false,
|
||||
false,
|
||||
Some(root.path()),
|
||||
&CancellationToken::new(),
|
||||
&|_| {},
|
||||
)
|
||||
.unwrap_err()
|
||||
.to_string()
|
||||
};
|
||||
assert!(install("./mylib").contains("does not exist"), "{}", install("./mylib"));
|
||||
assert!(install("./mylib[dev]").contains("does not exist"));
|
||||
// An existing folder gets as far as looking for pip.
|
||||
std::fs::create_dir(root.path().join("mylib")).unwrap();
|
||||
assert!(!install("./mylib[dev]").contains("does not exist"));
|
||||
// A folder whose name has brackets is a folder, not extras.
|
||||
std::fs::create_dir(root.path().join("lib[1]")).unwrap();
|
||||
assert!(!install("./lib[1]").contains("does not exist"), "{}", install("./lib[1]"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn only_a_local_directory_is_installed_in_editable_mode() {
|
||||
let err = crate::python::install_package(
|
||||
|
||||
@@ -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)" }));
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -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);
|
||||
});
|
||||
});
|
||||
@@ -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
|
||||
|
||||
Reference in new issue
Заблокувати користувача