Skip to content

Commit

Permalink
Add frozen targets
Browse files Browse the repository at this point in the history
Use lock

Move onto target

Validate early
  • Loading branch information
charliermarsh committed Nov 2, 2024
1 parent b36ae6d commit a39bf01
Show file tree
Hide file tree
Showing 18 changed files with 614 additions and 262 deletions.
1 change: 0 additions & 1 deletion Cargo.lock

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

4 changes: 2 additions & 2 deletions crates/uv-resolver/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ pub use exclude_newer::ExcludeNewer;
pub use exclusions::Exclusions;
pub use flat_index::{FlatDistributions, FlatIndex};
pub use lock::{
Lock, LockError, LockVersion, RequirementsTxtExport, ResolverManifest, SatisfiesResult,
TreeDisplay, VERSION,
InstallTarget, Lock, LockError, LockVersion, RequirementsTxtExport, ResolverManifest,
SatisfiesResult, TreeDisplay, VERSION,
};
pub use manifest::Manifest;
pub use options::{Flexibility, Options, OptionsBuilder};
Expand Down
14 changes: 13 additions & 1 deletion crates/uv-resolver/src/lock/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ use toml_edit::{value, Array, ArrayOfTables, InlineTable, Item, Table, Value};
use url::Url;

pub use crate::lock::requirements_txt::RequirementsTxtExport;
pub use crate::lock::target::InstallTarget;
pub use crate::lock::tree::TreeDisplay;
use crate::requires_python::SimplifiedMarkerTree;
use crate::resolution::{AnnotatedDist, ResolutionGraphNode};
Expand Down Expand Up @@ -44,9 +45,10 @@ use uv_pypi_types::{
};
use uv_types::{BuildContext, HashStrategy};
use uv_workspace::dependency_groups::DependencyGroupError;
use uv_workspace::{InstallTarget, Workspace};
use uv_workspace::Workspace;

mod requirements_txt;
mod target;
mod tree;

/// The current version of the lockfile format.
Expand Down Expand Up @@ -544,6 +546,16 @@ impl Lock {
&self.manifest.members
}

/// Return the workspace root used to generate this lock.
pub fn root(&self) -> Option<&Package> {
self.packages.iter().find(|package| {
let (Source::Editable(path) | Source::Virtual(path)) = &package.id.source else {
return false;
};
path == Path::new("")
})
}

/// Returns the supported environments that were used to generate this
/// lock.
///
Expand Down
20 changes: 10 additions & 10 deletions crates/uv-resolver/src/lock/requirements_txt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,17 @@ use petgraph::{Directed, Graph};
use rustc_hash::{FxBuildHasher, FxHashMap, FxHashSet};
use url::Url;

use crate::graph_ops::marker_reachability;
use crate::lock::{Package, PackageId, Source};
use crate::{Lock, LockError};
use uv_configuration::{DevGroupsManifest, EditableMode, ExtrasSpecification, InstallOptions};
use uv_distribution_filename::{DistExtension, SourceDistExtension};
use uv_fs::Simplified;
use uv_git::GitReference;
use uv_normalize::ExtraName;
use uv_pep508::MarkerTree;
use uv_pypi_types::{ParsedArchiveUrl, ParsedGitUrl};
use uv_workspace::InstallTarget;

use crate::graph_ops::marker_reachability;
use crate::lock::{Package, PackageId, Source};
use crate::{InstallTarget, LockError};

type LockGraph<'lock> = Graph<Node<'lock>, Edge, Directed>;

Expand All @@ -34,15 +34,14 @@ pub struct RequirementsTxtExport<'lock> {

impl<'lock> RequirementsTxtExport<'lock> {
pub fn from_lock(
lock: &'lock Lock,
target: InstallTarget<'lock>,
extras: &ExtrasSpecification,
dev: &DevGroupsManifest,
editable: EditableMode,
hashes: bool,
install_options: &'lock InstallOptions,
) -> Result<Self, LockError> {
let size_guess = lock.packages.len();
let size_guess = target.lock().packages.len();
let mut petgraph = LockGraph::with_capacity(size_guess, size_guess);
let mut inverse = FxHashMap::with_capacity_and_hasher(size_guess, FxBuildHasher);

Expand All @@ -53,7 +52,8 @@ impl<'lock> RequirementsTxtExport<'lock> {

// Add the workspace package to the queue.
for root_name in target.packages() {
let dist = lock
let dist = target
.lock()
.find_by_name(root_name)
.expect("found too many packages matching root")
.expect("could not find root");
Expand Down Expand Up @@ -88,7 +88,7 @@ impl<'lock> RequirementsTxtExport<'lock> {
// Add any development dependencies.
for group in dev.iter() {
for dep in dist.dependency_groups.get(group).into_iter().flatten() {
let dep_dist = lock.find_by_id(&dep.package_id);
let dep_dist = target.lock().find_by_id(&dep.package_id);

// Add the dependency to the graph.
if let Entry::Vacant(entry) = inverse.entry(&dep.package_id) {
Expand Down Expand Up @@ -135,7 +135,7 @@ impl<'lock> RequirementsTxtExport<'lock> {
};

for dep in deps {
let dep_dist = lock.find_by_id(&dep.package_id);
let dep_dist = target.lock().find_by_id(&dep.package_id);

// Add the dependency to the graph.
if let Entry::Vacant(entry) = inverse.entry(&dep.package_id) {
Expand Down Expand Up @@ -175,7 +175,7 @@ impl<'lock> RequirementsTxtExport<'lock> {
install_options.include_package(
&package.id.name,
target.project_name(),
lock.members(),
target.lock().members(),
)
})
.map(|(index, package)| Requirement {
Expand Down
Loading

0 comments on commit a39bf01

Please sign in to comment.