This commit is contained in:
Hood Chatham 2025-12-23 02:32:39 +01:00 committed by GitHub
commit f8d2da2d0b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 53 additions and 2 deletions

View file

@ -277,12 +277,28 @@ impl IndexLocations {
///
/// If the current index location has an `index` set, it will be preserved.
#[must_use]
pub fn combine(self, indexes: Vec<Index>, flat_index: Vec<Index>, no_index: bool) -> Self {
Self {
pub fn combine(
self,
indexes: Vec<Index>,
flat_index: Vec<Index>,
no_index: bool,
pyodide_ver: Option<&str>,
) -> Self {
let mut res = Self {
indexes: self.indexes.into_iter().chain(indexes).collect(),
flat_index: self.flat_index.into_iter().chain(flat_index).collect(),
no_index: self.no_index || no_index,
};
if res.is_none()
&& let Some(s) = pyodide_ver
{
let index = Index::from_index_url(IndexUrl::Pypi(Arc::new(VerbatimUrl::from_url(
DisplaySafeUrl::parse(&format!("https://index.pyodide.org/{s}")).unwrap(),
))));
res.indexes.push(DEFAULT_INDEX.clone());
res.indexes.push(index);
}
res
}
/// Returns `true` if no index configuration is set, i.e., the [`IndexLocations`] matches the

View file

@ -257,6 +257,10 @@ impl PlatformTag {
} | Self::Win32
)
}
pub fn is_pyodide(&self) -> bool {
matches!(self, Self::Pyodide { .. })
}
}
impl std::fmt::Display for PlatformTag {

View file

@ -28,6 +28,10 @@ impl Os {
matches!(self.0, target_lexicon::OperatingSystem::Darwin(_))
}
pub fn emscripten() -> Self {
Self(target_lexicon::OperatingSystem::Emscripten)
}
/// Whether this OS can run the other OS.
pub fn supports(&self, other: Self) -> bool {
// Emscripten cannot run on Windows, but all other OSes can run Emscripten.

View file

@ -2,6 +2,7 @@
use owo_colors::OwoColorize;
use thiserror::Error;
use uv_platform::Os;
#[cfg(test)]
use uv_static::EnvVars;
@ -11,6 +12,7 @@ pub use crate::discovery::{
find_python_installations, satisfies_python_preference,
};
pub use crate::downloads::PlatformRequest;
use crate::downloads::{ManagedPythonDownload, PythonDownloadRequest};
pub use crate::environment::{InvalidEnvironmentKind, PythonEnvironment};
pub use crate::implementation::{ImplementationName, LenientImplementationName};
pub use crate::installation::{
@ -119,6 +121,27 @@ impl From<PythonNotFound> for Error {
}
}
pub fn pyodide_version(interp: &Interpreter) -> Result<Option<&str>, Error> {
if !interp.os().is_emscripten() {
return Ok(None);
}
let pyver = interp.python_version();
let [major, minor, patch, ..] = *pyver.release() else {
panic!("oops")
};
let ver = VersionRequest::MajorMinorPatch(
major as u8,
minor as u8,
patch as u8,
PythonVariant::Default,
);
let download = ManagedPythonDownload::from_request(
&PythonDownloadRequest::new(Some(ver), None, None, Some(Os::emscripten()), None, None),
None,
)?;
Ok(download.build())
}
// The mock interpreters are not valid on Windows so we don't have unit test coverage there
// TODO(zanieb): We should write a mock interpreter script that works on Windows
#[cfg(all(test, unix))]

View file

@ -436,6 +436,7 @@ pub(crate) async fn pip_compile(
.map(|index| index.with_origin(Origin::RequirementsTxt))
.collect(),
no_index,
pyodide_version(&interpreter)?,
);
// Determine the PyTorch backend.

View file

@ -25,6 +25,7 @@ use uv_installer::{InstallationStrategy, SatisfiesResult, SitePackages};
use uv_normalize::{DefaultExtras, DefaultGroups, PackageName};
use uv_preview::{Preview, PreviewFeatures};
use uv_pypi_types::Conflicts;
use uv_python::pyodide_version;
use uv_python::{
EnvironmentPreference, Prefix, PythonDownloads, PythonEnvironment, PythonInstallation,
PythonPreference, PythonRequest, PythonVersion, Target,
@ -396,6 +397,7 @@ pub(crate) async fn pip_install(
.map(|index| index.with_origin(Origin::RequirementsTxt))
.collect(),
no_index,
pyodide_version(&interpreter)?,
);
// Determine the PyTorch backend.

View file

@ -298,6 +298,7 @@ pub(crate) async fn pip_sync(
.map(|index| index.with_origin(Origin::RequirementsTxt))
.collect(),
no_index,
pyodide_version(&interpreter)?,
);
// Determine the PyTorch backend.