mirror of https://github.com/astral-sh/uv
Remove dynamic providers
This commit is contained in:
parent
0c55e12d18
commit
ba727863d1
|
|
@ -1,4 +1,3 @@
|
|||
use std::collections::BTreeSet;
|
||||
use std::future::Future;
|
||||
use std::io;
|
||||
use std::path::Path;
|
||||
|
|
@ -35,7 +34,7 @@ use uv_redacted::DisplaySafeUrl;
|
|||
use uv_types::{BuildContext, BuildStack, VariantsTrait};
|
||||
use uv_variants::VariantProviderOutput;
|
||||
use uv_variants::resolved_variants::ResolvedVariants;
|
||||
use uv_variants::variants_json::{Provider, VariantPropertyType, VariantsJsonContent};
|
||||
use uv_variants::variants_json::{Provider, VariantsJsonContent};
|
||||
|
||||
use crate::archive::Archive;
|
||||
use crate::metadata::{ArchiveMetadata, Metadata};
|
||||
|
|
@ -594,25 +593,6 @@ impl<'a, Context: BuildContext> DistributionDatabase<'a, Context> {
|
|||
variants_json: VariantsJsonContent,
|
||||
marker_env: &MarkerEnvironment,
|
||||
) -> Result<ResolvedVariants, Error> {
|
||||
// Collect all known properties for dynamic providers.
|
||||
// TODO(konsti): We shouldn't need to do this conversion.
|
||||
let mut known_properties = BTreeSet::default();
|
||||
for variant in variants_json.variants.values() {
|
||||
for (namespace, features) in &**variant {
|
||||
for (feature, value) in features {
|
||||
for value in value {
|
||||
// TODO(charlie): At minimum, we can probably avoid these clones.
|
||||
known_properties.insert(VariantPropertyType {
|
||||
namespace: namespace.clone(),
|
||||
feature: feature.clone(),
|
||||
value: value.clone(),
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
let known_properties: Vec<_> = known_properties.into_iter().collect();
|
||||
|
||||
// Compute the set of available variants.
|
||||
let provider_outputs: FxHashMap<VariantNamespace, Arc<VariantProviderOutput>> =
|
||||
futures::stream::iter(variants_json.providers.iter().filter(|(_, provider)| {
|
||||
|
|
@ -620,7 +600,7 @@ impl<'a, Context: BuildContext> DistributionDatabase<'a, Context> {
|
|||
.enable_if
|
||||
.evaluate(marker_env, MarkerVariantsUniversal, &[])
|
||||
}))
|
||||
.map(|(name, provider)| self.query_variant_provider(name, provider, &known_properties))
|
||||
.map(|(name, provider)| self.query_variant_provider(name, provider))
|
||||
// TODO(konsti): Buffer size
|
||||
.buffered(8)
|
||||
.map_ok(|config| (config.namespace.clone(), config))
|
||||
|
|
@ -637,7 +617,6 @@ impl<'a, Context: BuildContext> DistributionDatabase<'a, Context> {
|
|||
&self,
|
||||
name: &VariantNamespace,
|
||||
provider: &Provider,
|
||||
known_properties: &[VariantPropertyType],
|
||||
) -> Result<Arc<VariantProviderOutput>, Error> {
|
||||
let config = if self.build_context.variants().register(provider.clone()) {
|
||||
debug!("Querying provider `{name}` for variants");
|
||||
|
|
@ -648,7 +627,7 @@ impl<'a, Context: BuildContext> DistributionDatabase<'a, Context> {
|
|||
.build_context
|
||||
.setup_variants(backend_name, provider, BuildOutput::Debug)
|
||||
.await?;
|
||||
let config = builder.query(known_properties).await?;
|
||||
let config = builder.query().await?;
|
||||
trace!(
|
||||
"Found namespace {} with configs {:?}",
|
||||
config.namespace, config
|
||||
|
|
|
|||
|
|
@ -18,7 +18,6 @@ use uv_normalize::PackageName;
|
|||
use uv_python::{Interpreter, PythonEnvironment};
|
||||
use uv_variants::VariantProviderOutput;
|
||||
use uv_variants::cache::VariantProviderCache;
|
||||
use uv_variants::variants_json::VariantPropertyType;
|
||||
use uv_workspace::WorkspaceCache;
|
||||
|
||||
use crate::{BuildArena, BuildIsolation};
|
||||
|
|
@ -204,10 +203,7 @@ pub trait SourceBuildTrait {
|
|||
}
|
||||
|
||||
pub trait VariantsTrait {
|
||||
fn query(
|
||||
&self,
|
||||
known_properties: &[VariantPropertyType],
|
||||
) -> impl Future<Output = Result<VariantProviderOutput>>;
|
||||
fn query(&self) -> impl Future<Output = Result<VariantProviderOutput>>;
|
||||
}
|
||||
|
||||
/// A wrapper for [`uv_installer::SitePackages`]
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ use uv_python::{Interpreter, PythonEnvironment};
|
|||
use uv_static::EnvVars;
|
||||
use uv_types::{BuildContext, BuildStack, VariantsTrait};
|
||||
use uv_variants::VariantProviderOutput;
|
||||
use uv_variants::variants_json::{Provider, VariantPropertyType};
|
||||
use uv_variants::variants_json::Provider;
|
||||
use uv_virtualenv::OnExisting;
|
||||
|
||||
pub struct VariantBuild {
|
||||
|
|
@ -50,11 +50,8 @@ pub struct VariantBuild {
|
|||
}
|
||||
|
||||
impl VariantsTrait for VariantBuild {
|
||||
async fn query(
|
||||
&self,
|
||||
known_properties: &[VariantPropertyType],
|
||||
) -> anyhow::Result<VariantProviderOutput> {
|
||||
Ok(self.build(known_properties).await?)
|
||||
async fn query(&self) -> anyhow::Result<VariantProviderOutput> {
|
||||
Ok(self.build().await?)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -151,15 +148,9 @@ impl VariantBuild {
|
|||
}
|
||||
|
||||
/// Run a variant provider to infer compatible variants.
|
||||
pub async fn build(
|
||||
&self,
|
||||
known_properties: &[VariantPropertyType],
|
||||
) -> Result<VariantProviderOutput, Error> {
|
||||
pub async fn build(&self) -> Result<VariantProviderOutput, Error> {
|
||||
// Write the hook output to a file so that we can read it back reliably.
|
||||
let out_file = self.temp_dir.path().join("output.json");
|
||||
let in_file = self.temp_dir.path().join("input.json");
|
||||
let in_writer = fs_err::File::create(&in_file)?;
|
||||
serde_json::to_writer(in_writer, known_properties)?;
|
||||
|
||||
// Construct the appropriate build script based on the build kind.
|
||||
let script = formatdoc! {
|
||||
|
|
@ -168,32 +159,7 @@ impl VariantBuild {
|
|||
|
||||
import json
|
||||
|
||||
if backend.dynamic:
|
||||
class VariantPropertyType:
|
||||
namespace: str
|
||||
feature: str
|
||||
value: str
|
||||
|
||||
def __init__(self, namespace: str, feature: str, value: str):
|
||||
self.namespace = namespace
|
||||
self.feature = feature
|
||||
self.value = value
|
||||
|
||||
with open("{in_file}") as fp:
|
||||
known_properties = json.load(fp)
|
||||
|
||||
# Filter to the namespace of the plugin.
|
||||
filtered_properties = []
|
||||
for known_property in known_properties:
|
||||
# We don't know the namespace ahead of time, so the frontend passes all properties.
|
||||
if known_property["namespace"] != backend.namespace:
|
||||
continue
|
||||
filtered_properties.append(VariantPropertyType(**known_property))
|
||||
known_properties = frozenset(filtered_properties)
|
||||
else:
|
||||
known_properties = None
|
||||
|
||||
configs = backend.get_supported_configs(known_properties)
|
||||
configs = backend.get_supported_configs()
|
||||
features = {{config.name: config.values for config in configs}}
|
||||
output = {{"namespace": backend.namespace, "features": features}}
|
||||
|
||||
|
|
@ -201,7 +167,6 @@ impl VariantBuild {
|
|||
fp.write(json.dumps(output))
|
||||
"#,
|
||||
backend = self.backend.import(&self.backend_name),
|
||||
in_file = in_file.escape_for_python(),
|
||||
out_file = out_file.escape_for_python()
|
||||
};
|
||||
|
||||
|
|
|
|||
Binary file not shown.
Binary file not shown.
|
|
@ -22,10 +22,7 @@ class VariantPropertyType:
|
|||
|
||||
|
||||
def get_supported_configs(
|
||||
known_properties: frozenset[VariantPropertyType] | None,
|
||||
) -> list[VariantFeatureConfigType]:
|
||||
if known_properties is not None:
|
||||
raise ValueError("known_properties are unsupported")
|
||||
if override := os.getenv("UV_CPU_LEVEL_OVERRIDE"):
|
||||
try:
|
||||
current_level = int(override)
|
||||
|
|
@ -98,7 +95,7 @@ def get_x86_64_level() -> int | None:
|
|||
|
||||
|
||||
def main():
|
||||
print(get_supported_configs(None))
|
||||
print(get_supported_configs())
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
|
|
|||
Loading…
Reference in New Issue