From 0c8343851fa33440d843fbbb6deaa48a268c154e Mon Sep 17 00:00:00 2001 From: Wolf Vollprecht Date: Thu, 7 Nov 2024 17:50:37 +0100 Subject: [PATCH] fix git dependencies with recursive git dependencies --- Cargo.lock | 58 +++++++++++++++++++++++++++++++++++ Cargo.toml | 44 +++++++++++++------------- src/lock_file/resolve/pypi.rs | 28 +++++++++++++++-- src/uv_reporter.rs | 27 ++++++++++++++++ 4 files changed, 134 insertions(+), 23 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 65cbfe6e4..3c17992a4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -951,6 +951,16 @@ dependencies = [ "memchr", ] +[[package]] +name = "ctrlc" +version = "3.4.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "90eeab0aa92f3f9b4e87f258c72b139c207d251f9cbc1080a0086b86a8870dd3" +dependencies = [ + "nix", + "windows-sys 0.59.0", +] + [[package]] name = "darling" version = "0.20.10" @@ -3301,6 +3311,7 @@ dependencies = [ "uv-pep508", "uv-pypi-types", "uv-python", + "uv-requirements", "uv-resolver", "uv-types", "xxhash-rust", @@ -5999,6 +6010,15 @@ dependencies = [ "which", ] +[[package]] +name = "uv-console" +version = "0.0.1" +source = "git+https://github.com/astral-sh/uv?tag=0.4.30#61ed2a236ade13703fd6cd3271e2c4d627398f38" +dependencies = [ + "console", + "ctrlc", +] + [[package]] name = "uv-dirs" version = "0.0.1" @@ -6445,6 +6465,41 @@ dependencies = [ "windows-sys 0.59.0", ] +[[package]] +name = "uv-requirements" +version = "0.1.0" +source = "git+https://github.com/astral-sh/uv?tag=0.4.30#61ed2a236ade13703fd6cd3271e2c4d627398f38" +dependencies = [ + "anyhow", + "configparser", + "console", + "fs-err 2.11.0", + "futures", + "rustc-hash", + "serde", + "thiserror", + "toml", + "tracing", + "url", + "uv-cache-key", + "uv-client", + "uv-configuration", + "uv-console", + "uv-distribution", + "uv-distribution-filename", + "uv-distribution-types", + "uv-fs", + "uv-git", + "uv-normalize", + "uv-pep508", + "uv-pypi-types", + "uv-requirements-txt", + "uv-resolver", + "uv-types", + "uv-warnings", + "uv-workspace", +] + [[package]] name = "uv-requirements-txt" version = "0.0.1" @@ -6452,6 +6507,8 @@ source = "git+https://github.com/astral-sh/uv?tag=0.4.30#61ed2a236ade13703fd6cd3 dependencies = [ "fs-err 2.11.0", "regex", + "reqwest", + "reqwest-middleware", "thiserror", "tracing", "unscanny", @@ -6472,6 +6529,7 @@ version = "0.0.1" source = "git+https://github.com/astral-sh/uv?tag=0.4.30#61ed2a236ade13703fd6cd3271e2c4d627398f38" dependencies = [ "anyhow", + "clap", "dashmap", "either", "futures", diff --git a/Cargo.toml b/Cargo.toml index 64a3ee85e..7af7ef567 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -287,6 +287,7 @@ uv-normalize = { workspace = true } uv-python = { workspace = true } uv-resolver = { workspace = true } uv-types = { workspace = true } +uv-requirements = { workspace = true} xxhash-rust = { workspace = true } zip = { workspace = true, features = ["deflate", "time"] } zstd = { workspace = true } @@ -354,24 +355,25 @@ reqwest-retry = { git = "https://github.com/TrueLayer/reqwest-middleware", rev = # Change these lines if you want a patched version of uv -# [patch.'https://github.com/astral-sh/uv'] -# pep440_rs = { git = "https://github.com/astral-sh/uv", rev = "65b17f6e81125064ea04c5cfef685516ab660cf5" } -# pep508_rs = { git = "https://github.com/astral-sh/uv", rev = "65b17f6e81125064ea04c5cfef685516ab660cf5" } -# uv-build = { git = "https://github.com/astral-sh/uv", rev = "65b17f6e81125064ea04c5cfef685516ab660cf5" } -# uv-cache = { git = "https://github.com/astral-sh/uv", rev = "65b17f6e81125064ea04c5cfef685516ab660cf5" } -# uv-client = { git = "https://github.com/astral-sh/uv", rev = "65b17f6e81125064ea04c5cfef685516ab660cf5" } -# uv-configuration = { git = "https://github.com/astral-sh/uv", rev = "65b17f6e81125064ea04c5cfef685516ab660cf5" } -# uv-git = { git = "https://github.com/astral-sh/uv", rev = "65b17f6e81125064ea04c5cfef685516ab660cf5" } -# uv-dispatch = { git = "https://github.com/astral-sh/uv", rev = "65b17f6e81125064ea04c5cfef685516ab660cf5" } -# uv-distribution = { git = "https://github.com/astral-sh/uv", rev = "65b17f6e81125064ea04c5cfef685516ab660cf5" } -# uv-installer = { git = "https://github.com/astral-sh/uv", rev = "65b17f6e81125064ea04c5cfef685516ab660cf5" } -# uv-interpreter = { git = "https://github.com/astral-sh/uv", rev = "65b17f6e81125064ea04c5cfef685516ab660cf5" } -# uv-normalize = { git = "https://github.com/astral-sh/uv", rev = "65b17f6e81125064ea04c5cfef685516ab660cf5" } -# uv-resolver = { git = "https://github.com/astral-sh/uv", rev = "65b17f6e81125064ea04c5cfef685516ab660cf5" } -# uv-types = { git = "https://github.com/astral-sh/uv", rev = "65b17f6e81125064ea04c5cfef685516ab660cf5" } -# distribution-filename = { git = "https://github.com/astral-sh/uv", rev = "65b17f6e81125064ea04c5cfef685516ab660cf5" } -# distribution-types = { git = "https://github.com/astral-sh/uv", rev = "65b17f6e81125064ea04c5cfef685516ab660cf5" } -# install-wheel-rs = { git = "https://github.com/astral-sh/uv", rev = "65b17f6e81125064ea04c5cfef685516ab660cf5" } -# platform-tags = { git = "https://github.com/astral-sh/uv", rev = "65b17f6e81125064ea04c5cfef685516ab660cf5" } -# pypi-types = { git = "https://github.com/astral-sh/uv", rev = "65b17f6e81125064ea04c5cfef685516ab660cf5" } -# requirements-txt = { git = "https://github.com/astral-sh/uv", rev = "65b17f6e81125064ea04c5cfef685516ab660cf5" } +[patch.'https://github.com/astral-sh/uv'] +# uv-cache = { path = "../uv/crates/uv-cache" } +# uv-pep508 = { path = "../uv/crates/uv-pep508" } +# uv-pep440 = { path = "../uv/crates/uv-pep440" } +# uv-cache-info = { path = "../uv/crates/uv-cache-info" } +# uv-client = { path = "../uv/crates/uv-client" } +# uv-configuration = { path = "../uv/crates/uv-configuration" } +# uv-git = { path = "../uv/crates/uv-git" } +# uv-dispatch = { path = "../uv/crates/uv-dispatch" } +# uv-distribution = { path = "../uv/crates/uv-distribution" } +# uv-installer = { path = "../uv/crates/uv-installer" } +# uv-normalize = { path = "../uv/crates/uv-normalize" } +# uv-resolver = { path = "../uv/crates/uv-resolver" } +# uv-types = { path = "../uv/crates/uv-types" } +# uv-distribution-filename = { path = "../uv/crates/uv-distribution-filename" } +# uv-distribution-types = { path = "../uv/crates/uv-distribution-types" } +# uv-install-wheel = { path = "../uv/crates/uv-install-wheel" } +# uv-platform-tags = { path = "../uv/crates/uv-platform-tags" } +# uv-pypi-types = { path = "../uv/crates/uv-pypi-types" } +# uv-requirements = { path = "../uv/crates/uv-requirements" } +# uv-requirements-txt = { path = "../uv/crates/uv-requirements-txt" } +# uv-python = { path = "../uv/crates/uv-python" } diff --git a/src/lock_file/resolve/pypi.rs b/src/lock_file/resolve/pypi.rs index f23d11e31..bb4e18691 100644 --- a/src/lock_file/resolve/pypi.rs +++ b/src/lock_file/resolve/pypi.rs @@ -41,6 +41,7 @@ use uv_git::GitResolver; use uv_install_wheel::linker::LinkMode; use uv_pypi_types::{HashAlgorithm, HashDigest, RequirementSource}; use uv_python::{Interpreter, PythonEnvironment, PythonVersion}; +use uv_requirements::LookaheadResolver; use uv_resolver::{ AllowedYanks, DefaultResolverProvider, FlatIndex, InMemoryIndex, Manifest, Options, Preference, Preferences, PythonRequirement, Resolver, ResolverEnvironment, @@ -351,16 +352,39 @@ pub async fn resolve_pypi( .into_diagnostic()?; let resolver_env = ResolverEnvironment::specific(marker_environment.into()); + + let constraints = Constraints::from_requirements(constraints.iter().cloned()); + let lookahead_index = InMemoryIndex::default(); + let lookaheads = LookaheadResolver::new( + &requirements, + &constraints, + &Overrides::default(), + &[], + &context.hash_strategy, + &lookahead_index, + DistributionDatabase::new( + ®istry_client, + &build_dispatch, + context.concurrency.downloads, + ), + ) + .with_reporter(UvReporter::new( + UvReporterOptions::new().with_existing(pb.clone()), + )) + .resolve(&resolver_env) + .await + .into_diagnostic()?; + let manifest = Manifest::new( requirements, - Constraints::from_requirements(constraints.iter().cloned()), + constraints, Overrides::default(), Default::default(), Preferences::from_iter(preferences, &resolver_env), None, None, uv_resolver::Exclusions::None, - Vec::new(), + lookaheads, ); let interpreter_version = interpreter.python_version(); diff --git a/src/uv_reporter.rs b/src/uv_reporter.rs index 888c0bca1..06d03d5a6 100644 --- a/src/uv_reporter.rs +++ b/src/uv_reporter.rs @@ -224,3 +224,30 @@ impl uv_resolver::ResolverReporter for UvReporter { fn on_download_complete(&self, _name: &PackageName, _id: usize) {} } + +impl uv_distribution::Reporter for UvReporter { + fn on_build_start(&self, dist: &BuildableSource) -> usize { + self.start_sync(format!("building {}", dist,)) + } + + fn on_build_complete(&self, _dist: &BuildableSource, id: usize) { + self.finish(id); + } + + fn on_checkout_start(&self, url: &url::Url, _rev: &str) -> usize { + self.start_sync(format!("cloning {}", url)) + } + + fn on_checkout_complete(&self, _url: &url::Url, _rev: &str, index: usize) { + self.finish(index); + } + + // TODO: figure out how to display this nicely + fn on_download_start(&self, _name: &PackageName, _size: Option) -> usize { + 0 + } + + fn on_download_progress(&self, _id: usize, _bytes: u64) {} + + fn on_download_complete(&self, _name: &PackageName, _id: usize) {} +}