Skip to content

Commit

Permalink
Split version ranges into their own crate
Browse files Browse the repository at this point in the history
  • Loading branch information
konstin committed Oct 12, 2024
1 parent fe65959 commit 96384b2
Show file tree
Hide file tree
Showing 10 changed files with 236 additions and 207 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ jobs:
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
- run: cargo build --verbose
- run: cargo test --features=serde --verbose
- run: cargo build --verbose --workspace
- run: cargo test --features serde --workspace --verbose

clippy:
name: No warnings from Clippy
Expand All @@ -30,7 +30,7 @@ jobs:
- name: Check Clippy lints
env:
RUSTFLAGS: -D warnings
run: cargo clippy
run: cargo clippy --workspace

check_formatting:
name: Source code is formatted
Expand All @@ -40,7 +40,7 @@ jobs:
- uses: dtolnay/rust-toolchain@stable
with:
components: rustfmt
- run: cargo fmt --all -- --check
- run: cargo fmt --workspace -- --check

check_documentation:
name: Documentation builds successfully
Expand All @@ -51,4 +51,4 @@ jobs:
- name: Check documentation
env:
RUSTDOCFLAGS: -D warnings
run: cargo doc --no-deps --document-private-items
run: cargo doc --workspace --no-deps --document-private-items
23 changes: 18 additions & 5 deletions Cargo.lock

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

13 changes: 10 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# SPDX-License-Identifier: MPL-2.0

[workspace]
members = ["version-range"]

[package]
name = "pubgrub"
version = "0.2.1"
Expand All @@ -21,18 +24,22 @@ include = ["Cargo.toml", "LICENSE", "README.md", "src/**", "tests/**", "examples

[dependencies]
indexmap = "2.5.0"
log = "0.4.22" # for debug logs in tests
priority-queue = "2.1.0"
thiserror = "1.0"
rustc-hash = ">=1.0.0, <3.0.0"
serde = { version = "1.0", features = ["derive"], optional = true }
log = "0.4.22" # for debug logs in tests
thiserror = "1.0"
version-range = { version = "0.1.0", path = "version-range" }

[dev-dependencies]
proptest = "1.5.0"
ron = "=0.9.0-alpha.0"
varisat = "0.2.2"
criterion = "0.5"
env_logger = "0.11.5"
version-range = { version = "0.1.0", path = "version-range", features = ["proptest"] }

[features]
serde = ["dep:serde", "version-range/serde"]

[[bench]]
name = "large_case"
Expand Down
3 changes: 1 addition & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,6 @@

mod error;
mod package;
mod range;
mod report;
mod solver;
mod term;
Expand All @@ -222,7 +221,6 @@ mod version_set;

pub use error::{NoSolutionError, PubGrubError};
pub use package::Package;
pub use range::Range;
pub use report::{
DefaultStringReportFormatter, DefaultStringReporter, DerivationTree, Derived, External,
ReportFormatter, Reporter,
Expand All @@ -231,6 +229,7 @@ pub use solver::{resolve, Dependencies, DependencyProvider, OfflineDependencyPro
pub use term::Term;
pub use type_aliases::{DependencyConstraints, Map, SelectedDependencies, Set};
pub use version::{SemanticVersion, VersionParseError};
pub use version_range::Range;
pub use version_set::VersionSet;

mod internal;
2 changes: 1 addition & 1 deletion src/solver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ pub trait DependencyProvider {
/// How this provider stores the version requirements for the packages.
/// The requirements must be able to process the same kind of version as this dependency provider.
///
/// A common choice is [`Range`][crate::range::Range].
/// A common choice is [`Range`][version_range::Range].
type VS: VersionSet<V = Self::V>;

/// Type for custom incompatibilities.
Expand Down
9 changes: 4 additions & 5 deletions src/term.rs
Original file line number Diff line number Diff line change
Expand Up @@ -220,15 +220,14 @@ impl<VS: VersionSet + Display> Display for Term<VS> {

#[cfg(test)]
pub mod tests {
use proptest::prelude::*;

use super::*;
use crate::Range;
use proptest::prelude::*;
use version_range::Range;

pub fn strategy() -> impl Strategy<Value = Term<Range<u32>>> {
prop_oneof![
crate::range::tests::strategy().prop_map(Term::Positive),
crate::range::tests::strategy().prop_map(Term::Negative),
version_range::proptest_strategy().prop_map(Term::Negative),
version_range::proptest_strategy().prop_map(Term::Positive),
]
}
proptest! {
Expand Down
42 changes: 42 additions & 0 deletions src/version_set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
use std::fmt::{Debug, Display};

use crate::Range;

/// Trait describing sets of versions.
pub trait VersionSet: Debug + Display + Clone + Eq {
/// Version type associated with the sets manipulated.
Expand Down Expand Up @@ -68,3 +70,43 @@ pub trait VersionSet: Debug + Display + Clone + Eq {
self == &self.intersection(other)
}
}

impl<T: Debug + Display + Clone + Eq + Ord> VersionSet for Range<T> {
type V = T;

fn empty() -> Self {
Range::empty()
}

fn singleton(v: Self::V) -> Self {
Range::singleton(v)
}

fn complement(&self) -> Self {
Range::complement(self)
}

fn intersection(&self, other: &Self) -> Self {
Range::intersection(self, other)
}

fn contains(&self, v: &Self::V) -> bool {
Range::contains(self, v)
}

fn full() -> Self {
Range::full()
}

fn union(&self, other: &Self) -> Self {
Range::union(self, other)
}

fn is_disjoint(&self, other: &Self) -> bool {
Range::is_disjoint(self, other)
}

fn subset_of(&self, other: &Self) -> bool {
Range::subset_of(self, other)
}
}
7 changes: 7 additions & 0 deletions version-range/Cargo.lock

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

17 changes: 17 additions & 0 deletions version-range/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[package]
name = "version-range"
version = "0.1.0"
edition = "2021"
keywords = ["version", "pubgrub", "selector", "ranges"]

[dependencies]
proptest = { version = "1.5.0", optional = true }
serde = { version = "1.0.210", features = ["derive"], optional = true }
smallvec = { version = "1.13.2" }

[features]
serde = ["dep:serde", "smallvec/serde"]

[dev-dependencies]
proptest = "1.5.0"
ron = "=0.9.0-alpha.0"
Loading

0 comments on commit 96384b2

Please sign in to comment.