Skip to content

Commit

Permalink
Rename uv-traits and split into separate modules (#2674)
Browse files Browse the repository at this point in the history
This is driving me a little crazy and is becoming a larger problem in
#2596 where I need to move more types (like `Upgrade` and `Reinstall`)
into this crate. Anything that's shared across our core resolver,
install, and build crates needs to be defined in this crate to avoid
cyclic dependencies. We've outgrown it being a single file with some
shared traits.

There are no behavioral changes here.
  • Loading branch information
zanieb authored Mar 26, 2024
1 parent 39769d8 commit 0b08ba1
Show file tree
Hide file tree
Showing 44 changed files with 696 additions and 624 deletions.
19 changes: 10 additions & 9 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ uv-interpreter = { path = "crates/uv-interpreter" }
uv-normalize = { path = "crates/uv-normalize" }
uv-requirements = { path = "crates/uv-requirements" }
uv-resolver = { path = "crates/uv-resolver" }
uv-traits = { path = "crates/uv-traits" }
uv-types = { path = "crates/uv-types" }
uv-trampoline = { path = "crates/uv-trampoline" }
uv-version = { path = "crates/uv-version" }
uv-virtualenv = { path = "crates/uv-virtualenv" }
Expand Down
4 changes: 2 additions & 2 deletions crates/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ Development utilities for uv.
## [uv-dispatch](./uv-dispatch)

A centralized `struct` for resolving and building source distributions in isolated environments.
Implements the traits defined in `uv-traits`.
Implements the traits defined in `uv-types`.

## [uv-distribution](./uv-distribution)

Expand Down Expand Up @@ -109,7 +109,7 @@ Utilities for reading package requirements from `pyproject.toml` and `requiremen

Functionality for resolving Python packages and their dependencies.

## [uv-traits](./uv-traits)
## [uv-types](./uv-types)

Shared traits for uv, to avoid circular dependencies.

Expand Down
2 changes: 1 addition & 1 deletion crates/uv-build/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ pep440_rs = { workspace = true }
pep508_rs = { workspace = true }
uv-fs = { workspace = true }
uv-interpreter = { workspace = true }
uv-traits = { workspace = true, features = ["serde"] }
uv-types = { workspace = true, features = ["serde"] }
uv-virtualenv = { workspace = true }

anyhow = { workspace = true }
Expand Down
2 changes: 1 addition & 1 deletion crates/uv-build/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ use pep440_rs::{Version, VersionSpecifiers};
use pep508_rs::{PackageName, Requirement};
use uv_fs::{PythonExt, Simplified};
use uv_interpreter::{Interpreter, PythonEnvironment};
use uv_traits::{
use uv_types::{
BuildContext, BuildIsolation, BuildKind, ConfigSettings, SetupPyStrategy, SourceBuildTrait,
};

Expand Down
2 changes: 1 addition & 1 deletion crates/uv-dev/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ uv-installer = { workspace = true }
uv-interpreter = { workspace = true }
uv-normalize = { workspace = true }
uv-resolver = { workspace = true }
uv-traits = { workspace = true }
uv-types = { workspace = true }

# Any dependencies that are exclusively used in `uv-dev` should be listed as non-workspace
# dependencies, to ensure that we're forced to think twice before including them in other crates.
Expand Down
2 changes: 1 addition & 1 deletion crates/uv-dev/src/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use uv_dispatch::BuildDispatch;
use uv_installer::NoBinary;
use uv_interpreter::PythonEnvironment;
use uv_resolver::InMemoryIndex;
use uv_traits::{
use uv_types::{
BuildContext, BuildIsolation, BuildKind, ConfigSettings, InFlight, NoBuild, SetupPyStrategy,
};

Expand Down
2 changes: 1 addition & 1 deletion crates/uv-dev/src/install_many.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use uv_installer::{Downloader, NoBinary};
use uv_interpreter::PythonEnvironment;
use uv_normalize::PackageName;
use uv_resolver::{DistFinder, InMemoryIndex};
use uv_traits::{BuildContext, BuildIsolation, ConfigSettings, InFlight, NoBuild, SetupPyStrategy};
use uv_types::{BuildContext, BuildIsolation, ConfigSettings, InFlight, NoBuild, SetupPyStrategy};

#[derive(Parser)]
pub(crate) struct InstallManyArgs {
Expand Down
2 changes: 1 addition & 1 deletion crates/uv-dev/src/resolve_cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use uv_dispatch::BuildDispatch;
use uv_installer::NoBinary;
use uv_interpreter::PythonEnvironment;
use uv_resolver::{InMemoryIndex, Manifest, Options, Resolver};
use uv_traits::{BuildIsolation, ConfigSettings, InFlight, NoBuild, SetupPyStrategy};
use uv_types::{BuildIsolation, ConfigSettings, InFlight, NoBuild, SetupPyStrategy};

#[derive(ValueEnum, Default, Clone)]
pub(crate) enum ResolveCliFormat {
Expand Down
2 changes: 1 addition & 1 deletion crates/uv-dev/src/resolve_many.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use uv_installer::NoBinary;
use uv_interpreter::PythonEnvironment;
use uv_normalize::PackageName;
use uv_resolver::InMemoryIndex;
use uv_traits::{BuildContext, BuildIsolation, ConfigSettings, InFlight, NoBuild, SetupPyStrategy};
use uv_types::{BuildContext, BuildIsolation, ConfigSettings, InFlight, NoBuild, SetupPyStrategy};

#[derive(Parser)]
pub(crate) struct ResolveManyArgs {
Expand Down
2 changes: 1 addition & 1 deletion crates/uv-dispatch/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ uv-client = { workspace = true }
uv-installer = { workspace = true }
uv-interpreter = { workspace = true }
uv-resolver = { workspace = true }
uv-traits = { workspace = true }
uv-types = { workspace = true }

anyhow = { workspace = true }
futures = { workspace = true }
Expand Down
2 changes: 1 addition & 1 deletion crates/uv-dispatch/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use uv_client::{FlatIndex, RegistryClient};
use uv_installer::{Downloader, Installer, NoBinary, Plan, Planner, Reinstall, SitePackages};
use uv_interpreter::{Interpreter, PythonEnvironment};
use uv_resolver::{InMemoryIndex, Manifest, Options, Resolver};
use uv_traits::{
use uv_types::{
BuildContext, BuildIsolation, BuildKind, ConfigSettings, InFlight, NoBuild, SetupPyStrategy,
};

Expand Down
2 changes: 1 addition & 1 deletion crates/uv-distribution/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ uv-extract = { workspace = true }
uv-fs = { workspace = true, features = ["tokio"] }
uv-git = { workspace = true, features = ["vendored-openssl"] }
uv-normalize = { workspace = true }
uv-traits = { workspace = true }
uv-types = { workspace = true }
pypi-types = { workspace = true }

anyhow = { workspace = true }
Expand Down
2 changes: 1 addition & 1 deletion crates/uv-distribution/src/distribution_database.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use pypi_types::Metadata23;
use uv_cache::{ArchiveTarget, ArchiveTimestamp, Cache, CacheBucket, CacheEntry, WheelCache};
use uv_client::{CacheControl, CachedClientError, Connectivity, RegistryClient};
use uv_git::GitSource;
use uv_traits::{BuildContext, NoBinary, NoBuild};
use uv_types::{BuildContext, NoBinary, NoBuild};

use crate::download::{BuiltWheel, UnzippedWheel};
use crate::locks::Locks;
Expand Down
2 changes: 1 addition & 1 deletion crates/uv-distribution/src/source/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ use uv_client::{
};
use uv_fs::{write_atomic, LockedFile};
use uv_git::{Fetch, GitSource};
use uv_traits::{BuildContext, BuildKind, NoBuild, SourceBuildTrait};
use uv_types::{BuildContext, BuildKind, NoBuild, SourceBuildTrait};

use crate::error::Error;
use crate::reporter::Facade;
Expand Down
2 changes: 1 addition & 1 deletion crates/uv-installer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ uv-extract = { workspace = true }
uv-fs = { workspace = true }
uv-interpreter = { workspace = true }
uv-normalize = { workspace = true }
uv-traits = { workspace = true }
uv-types = { workspace = true }
uv-warnings = { workspace = true }

anyhow = { workspace = true }
Expand Down
2 changes: 1 addition & 1 deletion crates/uv-installer/src/downloader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use platform_tags::Tags;
use uv_cache::Cache;
use uv_client::RegistryClient;
use uv_distribution::{DistributionDatabase, LocalWheel, Unzip};
use uv_traits::{BuildContext, InFlight};
use uv_types::{BuildContext, InFlight};

use crate::editable::BuiltEditable;

Expand Down
2 changes: 1 addition & 1 deletion crates/uv-installer/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ pub use installer::{Installer, Reporter as InstallReporter};
pub use plan::{Plan, Planner, Reinstall};
pub use site_packages::{Diagnostic, SitePackages};
pub use uninstall::{uninstall, UninstallError};
pub use uv_traits::NoBinary;
pub use uv_types::NoBinary;

mod compile;
mod downloader;
Expand Down
2 changes: 1 addition & 1 deletion crates/uv-installer/src/plan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use uv_distribution::{BuiltWheelIndex, RegistryWheelIndex};
use uv_fs::Simplified;
use uv_interpreter::PythonEnvironment;
use uv_normalize::PackageName;
use uv_traits::NoBinary;
use uv_types::NoBinary;

use crate::{ResolvedEditable, SitePackages};

Expand Down
2 changes: 1 addition & 1 deletion crates/uv-requirements/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ uv-distribution = { workspace = true }
uv-fs = { workspace = true }
uv-normalize = { workspace = true }
uv-resolver = { workspace = true, features = ["clap"] }
uv-traits = { workspace = true }
uv-types = { workspace = true }
uv-warnings = { workspace = true }

anyhow = { workspace = true }
Expand Down
2 changes: 1 addition & 1 deletion crates/uv-requirements/src/resolver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use pypi_types::Metadata10;
use uv_client::RegistryClient;
use uv_distribution::{Reporter, SourceDistCachedBuilder};
use uv_normalize::PackageName;
use uv_traits::BuildContext;
use uv_types::BuildContext;

/// Like [`RequirementsSpecification`], but with concrete names for all requirements.
pub struct NamedRequirementsResolver {
Expand Down
2 changes: 1 addition & 1 deletion crates/uv-requirements/src/source_tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use distribution_types::{BuildableSource, PathSourceUrl, SourceUrl};
use pep508_rs::Requirement;
use uv_client::RegistryClient;
use uv_distribution::{Reporter, SourceDistCachedBuilder};
use uv_traits::BuildContext;
use uv_types::BuildContext;

use crate::ExtrasSpecification;

Expand Down
39 changes: 1 addition & 38 deletions crates/uv-requirements/src/upgrade.rs
Original file line number Diff line number Diff line change
@@ -1,48 +1,11 @@
use std::path::Path;

use anyhow::Result;
use rustc_hash::FxHashSet;

use requirements_txt::RequirementsTxt;
use uv_client::{BaseClientBuilder, Connectivity};
use uv_normalize::PackageName;
use uv_resolver::{Preference, PreferenceError};

/// Whether to allow package upgrades.
#[derive(Debug)]
pub enum Upgrade {
/// Prefer pinned versions from the existing lockfile, if possible.
None,

/// Allow package upgrades for all packages, ignoring the existing lockfile.
All,

/// Allow package upgrades, but only for the specified packages.
Packages(FxHashSet<PackageName>),
}

impl Upgrade {
/// Determine the upgrade strategy from the command-line arguments.
pub fn from_args(upgrade: bool, upgrade_package: Vec<PackageName>) -> Self {
if upgrade {
Self::All
} else if !upgrade_package.is_empty() {
Self::Packages(upgrade_package.into_iter().collect())
} else {
Self::None
}
}

/// Returns `true` if no packages should be upgraded.
pub fn is_none(&self) -> bool {
matches!(self, Self::None)
}

/// Returns `true` if all packages should be upgraded.
pub fn is_all(&self) -> bool {
matches!(self, Self::All)
}
}
use uv_types::Upgrade;

/// Load the preferred requirements from an existing lockfile, applying the upgrade strategy.
pub async fn read_lockfile(
Expand Down
2 changes: 1 addition & 1 deletion crates/uv-resolver/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ uv-client = { workspace = true }
uv-distribution = { workspace = true }
uv-interpreter = { workspace = true }
uv-normalize = { workspace = true }
uv-traits = { workspace = true }
uv-types = { workspace = true }
uv-warnings = { workspace = true }

anstream = { workspace = true }
Expand Down
2 changes: 1 addition & 1 deletion crates/uv-resolver/src/finder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use anyhow::Result;
use futures::{stream, Stream, StreamExt, TryStreamExt};
use rustc_hash::FxHashMap;
use uv_traits::{NoBinary, NoBuild};
use uv_types::{NoBinary, NoBuild};

use distribution_filename::DistFilename;
use distribution_types::{Dist, IndexUrl, Resolution};
Expand Down
2 changes: 1 addition & 1 deletion crates/uv-resolver/src/resolver/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ use uv_client::{FlatIndex, RegistryClient};
use uv_distribution::DistributionDatabase;
use uv_interpreter::Interpreter;
use uv_normalize::PackageName;
use uv_traits::BuildContext;
use uv_types::BuildContext;

use crate::candidate_selector::{CandidateDist, CandidateSelector};
use crate::constraints::Constraints;
Expand Down
2 changes: 1 addition & 1 deletion crates/uv-resolver/src/resolver/provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use pypi_types::Metadata23;
use uv_client::{FlatIndex, RegistryClient};
use uv_distribution::DistributionDatabase;
use uv_normalize::PackageName;
use uv_traits::{BuildContext, NoBinary, NoBuild};
use uv_types::{BuildContext, NoBinary, NoBuild};

use crate::python_requirement::PythonRequirement;
use crate::version_map::VersionMap;
Expand Down
2 changes: 1 addition & 1 deletion crates/uv-resolver/src/version_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use pypi_types::{Hashes, Yanked};
use rkyv::{de::deserializers::SharedDeserializeMap, Deserialize};
use uv_client::{FlatDistributions, OwnedArchive, SimpleMetadata, VersionFiles};
use uv_normalize::PackageName;
use uv_traits::{NoBinary, NoBuild};
use uv_types::{NoBinary, NoBuild};
use uv_warnings::warn_user_once;

use crate::{python_requirement::PythonRequirement, yanks::AllowedYanks};
Expand Down
2 changes: 1 addition & 1 deletion crates/uv-resolver/tests/resolver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use uv_resolver::{
DisplayResolutionGraph, InMemoryIndex, Manifest, Options, OptionsBuilder, PreReleaseMode,
Preference, ResolutionGraph, ResolutionMode, Resolver,
};
use uv_traits::{
use uv_types::{
BuildContext, BuildIsolation, BuildKind, NoBinary, NoBuild, SetupPyStrategy, SourceBuildTrait,
};

Expand Down
Loading

0 comments on commit 0b08ba1

Please sign in to comment.