-
Notifications
You must be signed in to change notification settings - Fork 765
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
217 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1640,6 +1640,14 @@ mod tests { | |
PythonRequest::parse("pp"), | ||
PythonRequest::Implementation(ImplementationName::PyPy) | ||
); | ||
assert_eq!( | ||
PythonRequest::parse("graalpy"), | ||
PythonRequest::Implementation(ImplementationName::GraalPy) | ||
); | ||
assert_eq!( | ||
PythonRequest::parse("gp"), | ||
PythonRequest::Implementation(ImplementationName::GraalPy) | ||
); | ||
assert_eq!( | ||
PythonRequest::parse("cp"), | ||
PythonRequest::Implementation(ImplementationName::CPython) | ||
|
@@ -1658,6 +1666,20 @@ mod tests { | |
VersionRequest::from_str("3.10").unwrap() | ||
) | ||
); | ||
assert_eq!( | ||
PythonRequest::parse("graalpy3.10"), | ||
PythonRequest::ImplementationVersion( | ||
ImplementationName::GraalPy, | ||
VersionRequest::from_str("3.10").unwrap() | ||
) | ||
); | ||
assert_eq!( | ||
PythonRequest::parse("gp310"), | ||
PythonRequest::ImplementationVersion( | ||
ImplementationName::GraalPy, | ||
VersionRequest::from_str("3.10").unwrap() | ||
) | ||
); | ||
assert_eq!( | ||
PythonRequest::parse("cp38"), | ||
PythonRequest::ImplementationVersion( | ||
|
@@ -1679,6 +1701,20 @@ mod tests { | |
VersionRequest::from_str("3.10").unwrap() | ||
) | ||
); | ||
assert_eq!( | ||
PythonRequest::parse("[email protected]"), | ||
PythonRequest::ImplementationVersion( | ||
ImplementationName::GraalPy, | ||
VersionRequest::from_str("3.10").unwrap() | ||
) | ||
); | ||
assert_eq!( | ||
PythonRequest::parse("graalpy310"), | ||
PythonRequest::ImplementationVersion( | ||
ImplementationName::GraalPy, | ||
VersionRequest::from_str("3.10").unwrap() | ||
) | ||
); | ||
|
||
let tempdir = TempDir::new().unwrap(); | ||
assert_eq!( | ||
|
@@ -1749,6 +1785,18 @@ mod tests { | |
.to_canonical_string(), | ||
"[email protected]" | ||
); | ||
assert_eq!( | ||
PythonRequest::Implementation(ImplementationName::GraalPy).to_canonical_string(), | ||
"graalpy" | ||
); | ||
assert_eq!( | ||
PythonRequest::ImplementationVersion( | ||
ImplementationName::GraalPy, | ||
VersionRequest::from_str("3.10").unwrap() | ||
) | ||
.to_canonical_string(), | ||
"[email protected]" | ||
); | ||
|
||
let tempdir = TempDir::new().unwrap(); | ||
assert_eq!( | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1869,4 +1869,150 @@ mod tests { | |
|
||
Ok(()) | ||
} | ||
|
||
#[test] | ||
fn find_python_graalpy() -> Result<()> { | ||
let mut context = TestContext::new()?; | ||
|
||
context.add_python_interpreters(&[(true, ImplementationName::GraalPy, "graalpy", "3.10.0")])?; | ||
let result = context.run(|| { | ||
find_python_installation( | ||
&PythonRequest::Any, | ||
EnvironmentPreference::Any, | ||
PythonPreference::OnlySystem, | ||
&context.cache, | ||
) | ||
})?; | ||
assert!( | ||
matches!(result, Err(PythonNotFound { .. })), | ||
"We should not the graalpy interpreter if not named `python` or requested; got {result:?}" | ||
); | ||
|
||
// But we should find it | ||
context.reset_search_path(); | ||
context.add_python_interpreters(&[(true, ImplementationName::GraalPy, "python", "3.10.1")])?; | ||
let python = context.run(|| { | ||
find_python_installation( | ||
&PythonRequest::Any, | ||
EnvironmentPreference::Any, | ||
PythonPreference::OnlySystem, | ||
&context.cache, | ||
) | ||
})??; | ||
assert_eq!( | ||
python.interpreter().python_full_version().to_string(), | ||
"3.10.1", | ||
"We should find the graalpy interpreter if it's the only one" | ||
); | ||
|
||
let python = context.run(|| { | ||
find_python_installation( | ||
&PythonRequest::parse("graalpy"), | ||
EnvironmentPreference::Any, | ||
PythonPreference::OnlySystem, | ||
&context.cache, | ||
) | ||
})??; | ||
assert_eq!( | ||
python.interpreter().python_full_version().to_string(), | ||
"3.10.1", | ||
"We should find the graalpy interpreter if it's requested" | ||
); | ||
|
||
Ok(()) | ||
} | ||
|
||
#[test] | ||
fn find_python_graalpy_request_ignores_cpython() -> Result<()> { | ||
let mut context = TestContext::new()?; | ||
context.add_python_interpreters(&[ | ||
(true, ImplementationName::CPython, "python", "3.10.0"), | ||
(true, ImplementationName::GraalPy, "graalpy", "3.10.1"), | ||
])?; | ||
|
||
let python = context.run(|| { | ||
find_python_installation( | ||
&PythonRequest::parse("graalpy"), | ||
EnvironmentPreference::Any, | ||
PythonPreference::OnlySystem, | ||
&context.cache, | ||
) | ||
})??; | ||
assert_eq!( | ||
python.interpreter().python_full_version().to_string(), | ||
"3.10.1", | ||
"We should skip the CPython interpreter" | ||
); | ||
|
||
let python = context.run(|| { | ||
find_python_installation( | ||
&PythonRequest::Any, | ||
EnvironmentPreference::Any, | ||
PythonPreference::OnlySystem, | ||
&context.cache, | ||
) | ||
})??; | ||
assert_eq!( | ||
python.interpreter().python_full_version().to_string(), | ||
"3.10.0", | ||
"We should take the first interpreter without a specific request" | ||
); | ||
|
||
Ok(()) | ||
} | ||
|
||
#[test] | ||
fn find_python_graalpy_prefers_executable_with_implementation_name() -> Result<()> { | ||
let mut context = TestContext::new()?; | ||
|
||
// We should prefer `graalpy` executables over `python` executables in the same directory | ||
// even if they are both graalpy | ||
TestContext::create_mock_interpreter( | ||
&context.tempdir.join("python"), | ||
&PythonVersion::from_str("3.10.0").unwrap(), | ||
ImplementationName::GraalPy, | ||
true, | ||
)?; | ||
TestContext::create_mock_interpreter( | ||
&context.tempdir.join("graalpy"), | ||
&PythonVersion::from_str("3.10.1").unwrap(), | ||
ImplementationName::GraalPy, | ||
true, | ||
)?; | ||
context.add_to_search_path(context.tempdir.to_path_buf()); | ||
|
||
let python = context.run(|| { | ||
find_python_installation( | ||
&PythonRequest::parse("[email protected]"), | ||
EnvironmentPreference::Any, | ||
PythonPreference::OnlySystem, | ||
&context.cache, | ||
) | ||
})??; | ||
assert_eq!( | ||
python.interpreter().python_full_version().to_string(), | ||
"3.10.1", | ||
); | ||
|
||
// But `python` executables earlier in the search path will take precedence | ||
context.reset_search_path(); | ||
context.add_python_interpreters(&[ | ||
(true, ImplementationName::GraalPy, "python", "3.10.2"), | ||
(true, ImplementationName::GraalPy, "graalpy", "3.10.3"), | ||
])?; | ||
let python = context.run(|| { | ||
find_python_installation( | ||
&PythonRequest::parse("[email protected]"), | ||
EnvironmentPreference::Any, | ||
PythonPreference::OnlySystem, | ||
&context.cache, | ||
) | ||
})??; | ||
assert_eq!( | ||
python.interpreter().python_full_version().to_string(), | ||
"3.10.2", | ||
); | ||
|
||
Ok(()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters