mirror of
https://github.com/astral-sh/uv.git
synced 2025-08-04 02:48:17 +00:00
uv-resolver: make MarkerEnvironment optional
This commit touches a lot of code, but the conceptual change here is pretty simple: make it so we can run the resolver without providing a `MarkerEnvironment`. This also indicates that the resolver should run in universal mode. That is, the effect of a missing marker environment is that all marker expressions that reference the marker environment are evaluated to `true`. That is, they are ignored. (The only markers we evaluate in that context are extras, which are the only markers that aren't dependent on the environment.) One interesting change here is that a `Resolver` no longer needs an `Interpreter`. Previously, it had only been using it to construct a `PythonRequirement`, by filling in the installed version from the `Interpreter` state. But we now construct a `PythonRequirement` explicitly since its `target` Python version should no longer be tied to the `MarkerEnvironment`. (Currently, the marker environment is mutated such that its `python_full_version` is derived from multiple sources, including the CLI, which I found a touch confusing.) The change in behavior can now be observed through the `--unstable-uv-lock-file` flag. First, without it: ``` $ cat requirements.in anyio>=4.3.0 ; sys_platform == "linux" anyio<4 ; sys_platform == "darwin" $ cargo run -qp uv -- pip compile -p3.10 requirements.in anyio==4.3.0 exceptiongroup==1.2.1 # via anyio idna==3.7 # via anyio sniffio==1.3.1 # via anyio typing-extensions==4.11.0 # via anyio ``` And now with it: ``` $ cargo run -qp uv -- pip compile -p3.10 requirements.in --unstable-uv-lock-file x No solution found when resolving dependencies: `-> Because you require anyio>=4.3.0 and anyio<4, we can conclude that the requirements are unsatisfiable. ``` This is expected at this point because the marker expressions are being explicitly ignored, *and* there is no forking done yet to account for the conflict.
This commit is contained in:
parent
21f5999b57
commit
8b0fad3560
26 changed files with 153 additions and 95 deletions
|
@ -19,7 +19,7 @@ use uv_client::RegistryClient;
|
|||
use uv_configuration::{BuildKind, ConfigSettings, NoBinary, NoBuild, Reinstall, SetupPyStrategy};
|
||||
use uv_installer::{Downloader, Installer, Plan, Planner, SitePackages};
|
||||
use uv_interpreter::{Interpreter, PythonEnvironment};
|
||||
use uv_resolver::{FlatIndex, InMemoryIndex, Manifest, Options, Resolver};
|
||||
use uv_resolver::{FlatIndex, InMemoryIndex, Manifest, Options, PythonRequirement, Resolver};
|
||||
use uv_types::{BuildContext, BuildIsolation, EmptyInstalledPackages, HashStrategy, InFlight};
|
||||
|
||||
/// The main implementation of [`BuildContext`], used by the CLI, see [`BuildContext`]
|
||||
|
@ -135,12 +135,14 @@ impl<'a> BuildContext for BuildDispatch<'a> {
|
|||
|
||||
async fn resolve<'data>(&'data self, requirements: &'data [Requirement]) -> Result<Resolution> {
|
||||
let markers = self.interpreter.markers();
|
||||
let python_requirement =
|
||||
PythonRequirement::from_marker_environment(self.interpreter, markers);
|
||||
let tags = self.interpreter.tags()?;
|
||||
let resolver = Resolver::new(
|
||||
Manifest::simple(requirements.to_vec()),
|
||||
self.options,
|
||||
markers,
|
||||
self.interpreter,
|
||||
&python_requirement,
|
||||
Some(markers),
|
||||
tags,
|
||||
self.client,
|
||||
self.flat_index,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue