Skip to content

Commit

Permalink
Add Git resolver in lieu of static hash map (astral-sh#3954)
Browse files Browse the repository at this point in the history
## Summary

This PR removes the static resolver map:

```rust
static RESOLVED_GIT_REFS: Lazy<Mutex<FxHashMap<RepositoryReference, GitSha>>> =
    Lazy::new(Mutex::default);
```

With a `GitResolver` struct that we now pass around on the
`BuildContext`. There should be no behavior changes here; it's purely an
internal refactor with an eye towards making it cleaner for us to
"pre-populate" the list of resolved SHAs.
  • Loading branch information
charliermarsh authored Jun 1, 2024
1 parent a065292 commit b7d77c0
Show file tree
Hide file tree
Showing 31 changed files with 473 additions and 382 deletions.
9 changes: 7 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions crates/bench/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ uv-client = { workspace = true }
uv-configuration = { workspace = true }
uv-dispatch = { workspace = true }
uv-distribution = { workspace = true }
uv-git = { workspace = true }
uv-interpreter = { workspace = true }
uv-resolver = { workspace = true }
uv-types = { workspace = true }
Expand Down
13 changes: 8 additions & 5 deletions crates/bench/benches/uv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ mod resolver {
};
use uv_dispatch::BuildDispatch;
use uv_distribution::DistributionDatabase;
use uv_git::GitResolver;
use uv_interpreter::PythonEnvironment;
use uv_resolver::{
FlatIndex, InMemoryIndex, Manifest, Options, PythonRequirement, ResolutionGraph, Resolver,
Expand Down Expand Up @@ -124,17 +125,18 @@ mod resolver {
client: &RegistryClient,
venv: &PythonEnvironment,
) -> Result<ResolutionGraph> {
let build_isolation = BuildIsolation::Isolated;
let concurrency = Concurrency::default();
let config_settings = ConfigSettings::default();
let flat_index = FlatIndex::default();
let index = InMemoryIndex::default();
let git = GitResolver::default();
let hashes = HashStrategy::None;
let index_locations = IndexLocations::default();
let in_flight = InFlight::default();
let index = InMemoryIndex::default();
let index_locations = IndexLocations::default();
let installed_packages = EmptyInstalledPackages;
let interpreter = venv.interpreter().clone();
let python_requirement = PythonRequirement::from_marker_environment(&interpreter, &MARKERS);
let concurrency = Concurrency::default();
let config_settings = ConfigSettings::default();
let build_isolation = BuildIsolation::Isolated;

let build_context = BuildDispatch::new(
client,
Expand All @@ -143,6 +145,7 @@ mod resolver {
&index_locations,
&flat_index,
&index,
&git,
&in_flight,
SetupPyStrategy::default(),
&config_settings,
Expand Down
3 changes: 2 additions & 1 deletion crates/uv-dev/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,10 @@ uv-build = { workspace = true }
uv-cache = { workspace = true, features = ["clap"] }
uv-client = { workspace = true }
uv-configuration = { workspace = true }
uv-distribution = { workspace = true, features = ["schemars"] }
uv-dispatch = { workspace = true }
uv-distribution = { workspace = true, features = ["schemars"] }
uv-fs = { workspace = true }
uv-git = { workspace = true }
uv-installer = { workspace = true }
uv-interpreter = { workspace = true }
uv-resolver = { workspace = true }
Expand Down
13 changes: 8 additions & 5 deletions crates/uv-dev/src/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ use uv_configuration::{
BuildKind, Concurrency, ConfigSettings, NoBinary, NoBuild, PreviewMode, SetupPyStrategy,
};
use uv_dispatch::BuildDispatch;
use uv_git::GitResolver;
use uv_interpreter::PythonEnvironment;
use uv_resolver::{FlatIndex, InMemoryIndex};
use uv_types::{BuildContext, BuildIsolation, InFlight};
Expand Down Expand Up @@ -55,15 +56,16 @@ pub(crate) async fn build(args: BuildArgs) -> Result<PathBuf> {

let cache = Cache::try_from(args.cache_args)?.init()?;

let venv = PythonEnvironment::from_virtualenv(&cache)?;
let client = RegistryClientBuilder::new(cache.clone()).build();
let index_urls = IndexLocations::default();
let concurrency = Concurrency::default();
let config_settings = ConfigSettings::default();
let flat_index = FlatIndex::default();
let git = GitResolver::default();
let in_flight = InFlight::default();
let index = InMemoryIndex::default();
let index_urls = IndexLocations::default();
let setup_py = SetupPyStrategy::default();
let in_flight = InFlight::default();
let config_settings = ConfigSettings::default();
let concurrency = Concurrency::default();
let venv = PythonEnvironment::from_virtualenv(&cache)?;

let build_dispatch = BuildDispatch::new(
&client,
Expand All @@ -72,6 +74,7 @@ pub(crate) async fn build(args: BuildArgs) -> Result<PathBuf> {
&index_urls,
&flat_index,
&index,
&git,
&in_flight,
setup_py,
&config_settings,
Expand Down
1 change: 1 addition & 0 deletions crates/uv-dispatch/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ uv-cache = { workspace = true }
uv-client = { workspace = true }
uv-configuration = { workspace = true }
uv-distribution = { workspace = true }
uv-git = { workspace = true }
uv-installer = { workspace = true }
uv-interpreter = { workspace = true }
uv-resolver = { workspace = true }
Expand Down
14 changes: 11 additions & 3 deletions crates/uv-dispatch/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ use uv_client::RegistryClient;
use uv_configuration::{BuildKind, ConfigSettings, NoBinary, NoBuild, Reinstall, SetupPyStrategy};
use uv_configuration::{Concurrency, PreviewMode};
use uv_distribution::DistributionDatabase;
use uv_git::GitResolver;
use uv_installer::{Downloader, Installer, Plan, Planner, SitePackages};
use uv_interpreter::{Interpreter, PythonEnvironment};
use uv_resolver::{FlatIndex, InMemoryIndex, Manifest, Options, PythonRequirement, Resolver};
Expand All @@ -33,6 +34,7 @@ pub struct BuildDispatch<'a> {
index_locations: &'a IndexLocations,
flat_index: &'a FlatIndex,
index: &'a InMemoryIndex,
git: &'a GitResolver,
in_flight: &'a InFlight,
setup_py: SetupPyStrategy,
build_isolation: BuildIsolation<'a>,
Expand All @@ -56,6 +58,7 @@ impl<'a> BuildDispatch<'a> {
index_locations: &'a IndexLocations,
flat_index: &'a FlatIndex,
index: &'a InMemoryIndex,
git: &'a GitResolver,
in_flight: &'a InFlight,
setup_py: SetupPyStrategy,
config_settings: &'a ConfigSettings,
Expand All @@ -73,6 +76,7 @@ impl<'a> BuildDispatch<'a> {
index_locations,
flat_index,
index,
git,
in_flight,
setup_py,
config_settings,
Expand Down Expand Up @@ -102,6 +106,10 @@ impl<'a> BuildContext for BuildDispatch<'a> {
self.cache
}

fn git(&self) -> &GitResolver {
self.git
}

fn interpreter(&self) -> &Interpreter {
self.interpreter
}
Expand Down Expand Up @@ -194,9 +202,9 @@ impl<'a> BuildContext for BuildDispatch<'a> {
extraneous: _,
} = Planner::new(&requirements).build(
site_packages,
&Reinstall::None,
&NoBinary::None,
&HashStrategy::None,
&Reinstall::default(),
&NoBinary::default(),
&HashStrategy::default(),
self.index_locations,
self.cache(),
venv,
Expand Down
2 changes: 0 additions & 2 deletions crates/uv-distribution/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ license = { workspace = true }
workspace = true

[dependencies]
cache-key = { workspace = true }
distribution-filename = { workspace = true }
distribution-types = { workspace = true }
install-wheel-rs = { workspace = true }
Expand All @@ -36,7 +35,6 @@ fs-err = { workspace = true }
futures = { workspace = true }
glob = { workspace = true }
nanoid = { workspace = true }
once_cell = { workspace = true }
path-absolutize = { workspace = true }
reqwest = { workspace = true }
reqwest-middleware = { workspace = true }
Expand Down
4 changes: 2 additions & 2 deletions crates/uv-distribution/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ pub enum Error {
RelativePath(PathBuf),
#[error(transparent)]
JoinRelativeUrl(#[from] pypi_types::JoinRelativeError),
#[error("Git operation failed")]
Git(#[source] anyhow::Error),
#[error(transparent)]
Git(#[from] uv_git::GitResolverError),
#[error(transparent)]
Reqwest(#[from] BetterReqwestError),
#[error(transparent)]
Expand Down
Loading

0 comments on commit b7d77c0

Please sign in to comment.