Skip to content

Commit

Permalink
Rename from group to dev internally
Browse files Browse the repository at this point in the history
  • Loading branch information
charliermarsh committed Jun 6, 2024
1 parent 7b3e195 commit 52970c1
Show file tree
Hide file tree
Showing 23 changed files with 156 additions and 152 deletions.
14 changes: 7 additions & 7 deletions crates/distribution-types/src/resolution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,11 @@ pub enum ResolutionDiagnostic {
/// The extra that was requested. For example, `colorama` in `black[colorama]`.
extra: ExtraName,
},
MissingGroup {
/// The distribution that was requested with a non-existent group.
MissingDev {
/// The distribution that was requested with a non-existent development dependency group.
dist: ResolvedDist,
/// The group that was requested.
group: GroupName,
/// The development dependency group that was requested.
dev: GroupName,
},
YankedVersion {
/// The package that was requested with a yanked version. For example, `black==23.10.0`.
Expand All @@ -96,8 +96,8 @@ impl Diagnostic for ResolutionDiagnostic {
Self::MissingExtra { dist, extra } => {
format!("The package `{dist}` does not have an extra named `{extra}`.")
}
Self::MissingGroup { dist, group } => {
format!("The package `{dist}` does not have a group named `{group}`.")
Self::MissingDev { dist, dev } => {
format!("The package `{dist}` does not have a development dependency group named `{dev}`.")
}
Self::YankedVersion { dist, reason } => {
if let Some(reason) = reason {
Expand All @@ -113,7 +113,7 @@ impl Diagnostic for ResolutionDiagnostic {
fn includes(&self, name: &PackageName) -> bool {
match self {
Self::MissingExtra { dist, .. } => name == dist.name(),
Self::MissingGroup { dist, .. } => name == dist.name(),
Self::MissingDev { dist, .. } => name == dist.name(),
Self::YankedVersion { dist, .. } => name == dist.name(),
}
}
Expand Down
8 changes: 4 additions & 4 deletions crates/uv-distribution/src/metadata/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ pub struct Metadata {
pub requires_dist: Vec<pypi_types::Requirement>,
pub requires_python: Option<VersionSpecifiers>,
pub provides_extras: Vec<ExtraName>,
pub dependency_groups: BTreeMap<GroupName, Vec<pypi_types::Requirement>>,
pub dev_dependencies: BTreeMap<GroupName, Vec<pypi_types::Requirement>>,
}

impl Metadata {
Expand All @@ -49,7 +49,7 @@ impl Metadata {
.collect(),
requires_python: metadata.requires_python,
provides_extras: metadata.provides_extras,
dependency_groups: BTreeMap::default(),
dev_dependencies: BTreeMap::default(),
}
}

Expand All @@ -65,7 +65,7 @@ impl Metadata {
name,
requires_dist,
provides_extras,
dependency_groups,
dev_dependencies,
} = RequiresDist::from_workspace(
pypi_types::RequiresDist {
name: metadata.name,
Expand All @@ -84,7 +84,7 @@ impl Metadata {
requires_dist,
requires_python: metadata.requires_python,
provides_extras,
dependency_groups,
dev_dependencies,
})
}
}
Expand Down
12 changes: 6 additions & 6 deletions crates/uv-distribution/src/metadata/requires_dist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use crate::metadata::lowering::lower_requirement;
use crate::metadata::MetadataError;
use crate::{Metadata, ProjectWorkspace};

/// The `dev-dependencies` dependency group.
/// The name of the global `dev-dependencies` group.
///
/// Internally, we model dependency groups as a generic concept; but externally, we only expose the
/// `dev-dependencies` group.
Expand All @@ -21,7 +21,7 @@ pub struct RequiresDist {
pub name: PackageName,
pub requires_dist: Vec<pypi_types::Requirement>,
pub provides_extras: Vec<ExtraName>,
pub dependency_groups: BTreeMap<GroupName, Vec<pypi_types::Requirement>>,
pub dev_dependencies: BTreeMap<GroupName, Vec<pypi_types::Requirement>>,
}

impl RequiresDist {
Expand All @@ -36,7 +36,7 @@ impl RequiresDist {
.map(pypi_types::Requirement::from)
.collect(),
provides_extras: metadata.provides_extras,
dependency_groups: BTreeMap::default(),
dev_dependencies: BTreeMap::default(),
}
}

Expand Down Expand Up @@ -74,7 +74,7 @@ impl RequiresDist {
.and_then(|uv| uv.sources.as_ref())
.unwrap_or(&empty);

let dependency_groups = {
let dev_dependencies = {
let dev_dependencies = project_workspace
.current_project()
.pyproject_toml()
Expand Down Expand Up @@ -125,7 +125,7 @@ impl RequiresDist {
Ok(Self {
name: metadata.name,
requires_dist,
dependency_groups,
dev_dependencies,
provides_extras: metadata.provides_extras,
})
}
Expand All @@ -137,7 +137,7 @@ impl From<Metadata> for RequiresDist {
name: metadata.name,
requires_dist: metadata.requires_dist,
provides_extras: metadata.provides_extras,
dependency_groups: metadata.dependency_groups,
dev_dependencies: metadata.dev_dependencies,
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion crates/uv-resolver/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ impl NoSolutionError {
PubGrubPackageInner::Root(_) => {}
PubGrubPackageInner::Python(_) => {}
PubGrubPackageInner::Extra { .. } => {}
PubGrubPackageInner::Group { .. } => {}
PubGrubPackageInner::Dev { .. } => {}
PubGrubPackageInner::Package { name, .. } => {
// Avoid including available versions for packages that exist in the derivation
// tree, but were never visited during resolution. We _may_ have metadata for
Expand Down
53 changes: 27 additions & 26 deletions crates/uv-resolver/src/lock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ impl Lock {
}
}

// Lock all extras and dependency groups.
// Lock all extras and development dependencies.
for node_index in graph.petgraph.node_indices() {
let dist = &graph.petgraph[node_index];
if let Some(extra) = dist.extra.as_ref() {
Expand All @@ -86,14 +86,14 @@ impl Lock {
locked_dist.add_optional_dependency(extra.clone(), dependency_dist);
}
}
if let Some(group) = dist.group.as_ref() {
if let Some(group) = dist.dev.as_ref() {
let id = DistributionId::from_annotated_dist(dist);
let Some(locked_dist) = locked_dists.get_mut(&id) else {
return Err(LockError::missing_group_base(id, group.clone()));
return Err(LockError::missing_dev_base(id, group.clone()));
};
for neighbor in graph.petgraph.neighbors(node_index) {
let dependency_dist = &graph.petgraph[neighbor];
locked_dist.add_group_dependency(group.clone(), dependency_dist);
locked_dist.add_dev_dependency(group.clone(), dependency_dist);
}
}
}
Expand Down Expand Up @@ -134,7 +134,7 @@ impl Lock {
tags: &Tags,
root_name: &PackageName,
extras: &ExtrasSpecification,
groups: &[GroupName],
dev: &[GroupName],
) -> Resolution {
let mut queue: VecDeque<(&Distribution, Option<&ExtraName>)> = VecDeque::new();

Expand Down Expand Up @@ -169,8 +169,8 @@ impl Lock {
Either::Left(dist.optional_dependencies.get(extra).into_iter().flatten())
} else {
Either::Right(dist.dependencies.iter().chain(
groups.iter().flat_map(|group| {
dist.dependency_groups.get(group).into_iter().flatten()
dev.iter().flat_map(|group| {
dist.dev_dependencies.get(group).into_iter().flatten()
}),
))
};
Expand Down Expand Up @@ -288,16 +288,16 @@ impl Lock {
table.insert("optional-dependencies", Item::Table(optional_deps));
}

if !dist.dependency_groups.is_empty() {
let mut dependency_groups = Table::new();
for (extra, deps) in &dist.dependency_groups {
if !dist.dev_dependencies.is_empty() {
let mut dev_dependencies = Table::new();
for (extra, deps) in &dist.dev_dependencies {
let deps = deps
.iter()
.map(Dependency::to_toml)
.collect::<ArrayOfTables>();
dependency_groups.insert(extra.as_ref(), Item::ArrayOfTables(deps));
dev_dependencies.insert(extra.as_ref(), Item::ArrayOfTables(deps));
}
table.insert("dependency-groups", Item::Table(dependency_groups));
table.insert("dev-dependencies", Item::Table(dev_dependencies));
}

if !dist.wheels.is_empty() {
Expand Down Expand Up @@ -414,7 +414,7 @@ pub struct Distribution {
#[serde(default, skip_serializing_if = "IndexMap::is_empty")]
optional_dependencies: IndexMap<ExtraName, Vec<Dependency>>,
#[serde(default, skip_serializing_if = "IndexMap::is_empty")]
dependency_groups: IndexMap<GroupName, Vec<Dependency>>,
dev_dependencies: IndexMap<GroupName, Vec<Dependency>>,
}

impl Distribution {
Expand All @@ -435,7 +435,7 @@ impl Distribution {
wheels,
dependencies: vec![],
optional_dependencies: IndexMap::default(),
dependency_groups: IndexMap::default(),
dev_dependencies: IndexMap::default(),
})
}

Expand All @@ -454,10 +454,10 @@ impl Distribution {
.push(dep);
}

/// Add the [`AnnotatedDist`] as an optional dependency of the [`Distribution`].
fn add_group_dependency(&mut self, group: GroupName, annotated_dist: &AnnotatedDist) {
/// Add the [`AnnotatedDist`] as a development dependency of the [`Distribution`].
fn add_dev_dependency(&mut self, dev: GroupName, annotated_dist: &AnnotatedDist) {
let dep = Dependency::from_annotated_dist(annotated_dist);
self.dependency_groups.entry(group).or_default().push(dep);
self.dev_dependencies.entry(dev).or_default().push(dep);
}

/// Convert the [`Distribution`] to a [`Dist`] that can be used in installation.
Expand Down Expand Up @@ -1510,8 +1510,8 @@ impl LockError {
}
}

fn missing_group_base(id: DistributionId, group: GroupName) -> LockError {
let kind = LockErrorKind::MissingGroupBase { id, group };
fn missing_dev_base(id: DistributionId, group: GroupName) -> LockError {
let kind = LockErrorKind::MissingDevBase { id, group };
LockError {
kind: Box::new(kind),
}
Expand All @@ -1527,7 +1527,7 @@ impl std::error::Error for LockError {
LockErrorKind::UnrecognizedDependency { ref err } => Some(err),
LockErrorKind::Hash { .. } => None,
LockErrorKind::MissingExtraBase { .. } => None,
LockErrorKind::MissingGroupBase { .. } => None,
LockErrorKind::MissingDevBase { .. } => None,
}
}
}
Expand Down Expand Up @@ -1583,10 +1583,10 @@ impl std::fmt::Display for LockError {
"found distribution `{id}` with extra `{extra}` but no base distribution",
)
}
LockErrorKind::MissingGroupBase { ref id, ref group } => {
LockErrorKind::MissingDevBase { ref id, ref group } => {
write!(
f,
"found distribution `{id}` with group `{group}` but no base distribution",
"found distribution `{id}` with development dependency group `{group}` but no base distribution",
)
}
}
Expand Down Expand Up @@ -1643,12 +1643,13 @@ enum LockErrorKind {
/// The extra name that was found.
extra: ExtraName,
},
/// An error that occurs when a distribution is included with a dependency group,
/// but no corresponding base distribution (i.e., without the group) exists.
MissingGroupBase {
/// An error that occurs when a distribution is included with a development
/// dependency group, but no corresponding base distribution (i.e., without
/// the group) exists.
MissingDevBase {
/// The ID of the distribution that has a missing base.
id: DistributionId,
/// The group name that was found.
/// The development dependency group that was found.
group: GroupName,
},
}
Expand Down
12 changes: 6 additions & 6 deletions crates/uv-resolver/src/manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ pub struct Manifest {
/// The overrides for the project.
pub(crate) overrides: Overrides,

/// The enabled dependency groups for the project. Dependency groups are global, such that any
/// provided groups will be enabled for all requirements.
pub(crate) groups: Vec<GroupName>,
/// The enabled development dependency groups for the project. Dependency groups are global,
/// such that any provided groups will be enabled for all requirements.
pub(crate) dev: Vec<GroupName>,

/// The preferences for the project.
///
Expand Down Expand Up @@ -54,7 +54,7 @@ impl Manifest {
requirements: Vec<Requirement>,
constraints: Constraints,
overrides: Overrides,
groups: Vec<GroupName>,
dev: Vec<GroupName>,
preferences: Vec<Preference>,
project: Option<PackageName>,
exclusions: Exclusions,
Expand All @@ -64,7 +64,7 @@ impl Manifest {
requirements,
constraints,
overrides,
groups,
dev,
preferences,
project,
exclusions,
Expand All @@ -77,7 +77,7 @@ impl Manifest {
requirements,
constraints: Constraints::default(),
overrides: Overrides::default(),
groups: Vec::new(),
dev: Vec::new(),
preferences: Vec::new(),
project: None,
exclusions: Exclusions::default(),
Expand Down
Loading

0 comments on commit 52970c1

Please sign in to comment.