Skip to content

Commit

Permalink
chore: bump pep508_rs and pep440_rs (#549)
Browse files Browse the repository at this point in the history
Bump the pep508_rs and pep440_rs crates to use the latest versions.

---------

Co-authored-by: Bas Zalmstra <zalmstra.bas@gmail.com>
  • Loading branch information
tdejager and baszalmstra authored Feb 29, 2024
1 parent 82dc20f commit 7e0a130
Show file tree
Hide file tree
Showing 12 changed files with 83 additions and 45 deletions.
29 changes: 23 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,29 @@ lto = true
[workspace.dependencies]
anyhow = "1.0.79"
assert_matches = "1.5.0"
async-compression = { version = "0.4.6", features = ["gzip", "tokio", "bzip2", "zstd"] }
async-compression = { version = "0.4.6", features = [
"gzip",
"tokio",
"bzip2",
"zstd",
] }
async-trait = "0.1.77"
axum = { version = "0.7.4", default-features = false, features = ["tokio", "http1"] }
axum = { version = "0.7.4", default-features = false, features = [
"tokio",
"http1",
] }
base64 = "0.21.7"
bindgen = "0.69.4"
blake2 = "0.10.6"
bytes = "1.5.0"
bzip2 = "0.4.4"
cache_control = "0.2.0"
cfg-if = "1.0"
chrono = { version = "0.4.33", default-features = false, features = ["std", "serde", "alloc"] }
chrono = { version = "0.4.33", default-features = false, features = [
"std",
"serde",
"alloc",
] }
clap = { version = "4.4.18", features = ["derive"] }
cmake = "0.1.50"
console = { version = "0.15.8", features = ["windows-console-colors"] }
Expand Down Expand Up @@ -78,8 +90,8 @@ num_cpus = "1.16.0"
once_cell = "1.19.0"
ouroboros = "0.18.3"
pathdiff = "0.2.1"
pep440_rs = { version = "0.4.0" }
pep508_rs = { version = "0.3.0" }
pep440_rs = { version = "0.5.0" }
pep508_rs = { version = "0.4.2" }
pin-project-lite = "0.2.13"
plist = "1"
purl = { version = "0.1.2", features = ["serde"] }
Expand All @@ -102,7 +114,12 @@ serde_yaml = "0.9.31"
sha2 = "0.10.8"
shlex = "1.3.0"
similar-asserts = "1.5.0"
smallvec = { version = "1.13.1", features = ["serde", "const_new", "const_generics", "union"] }
smallvec = { version = "1.13.1", features = [
"serde",
"const_new",
"const_generics",
"union",
] }
strum = { version = "0.26.1", features = ["derive"] }
superslice = "1.0.0"
syn = "2.0.48"
Expand Down
3 changes: 2 additions & 1 deletion crates/rattler_lock/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use crate::{
};
use fxhash::FxHashMap;
use indexmap::{IndexMap, IndexSet};
use pep508_rs::ExtraName;
use rattler_conda_types::Platform;
use std::{
collections::{BTreeSet, HashMap},
Expand Down Expand Up @@ -186,7 +187,7 @@ impl LockFileBuilder {
/// Similar to [`PypiPackageEnvironmentData`] but hashable.
#[derive(Hash, PartialEq, Eq)]
struct HashablePypiPackageEnvironmentData {
extras: BTreeSet<String>,
extras: BTreeSet<ExtraName>,
}

impl From<HashablePypiPackageEnvironmentData> for PypiPackageEnvironmentData {
Expand Down
10 changes: 5 additions & 5 deletions crates/rattler_lock/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
//! in a single file.
use fxhash::FxHashMap;
use pep508_rs::Requirement;
use pep508_rs::{ExtraName, Requirement};
use rattler_conda_types::{MatchSpec, PackageRecord, Platform, RepoDataRecord};
use std::collections::{BTreeSet, HashMap};
use std::sync::Arc;
Expand Down Expand Up @@ -429,10 +429,10 @@ impl Package {
}

/// Returns the name of the package.
pub fn name(&self) -> &str {
pub fn name(&self) -> Cow<'_, str> {
match self {
Self::Conda(value) => value.package_record().name.as_normalized(),
Self::Pypi(value) => value.package_data().name.as_str(),
Self::Conda(value) => value.package_record().name.as_normalized().into(),
Self::Pypi(value) => value.package_data().name.as_dist_info_name(),
}
}

Expand Down Expand Up @@ -550,7 +550,7 @@ impl PypiPackage {
}

/// Returns the extras enabled for this package
pub fn extras(&self) -> &BTreeSet<String> {
pub fn extras(&self) -> &BTreeSet<ExtraName> {
&self.environment_data().extras
}

Expand Down
3 changes: 2 additions & 1 deletion crates/rattler_lock/src/parse/deserialize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use crate::{
use fxhash::FxHashMap;
use indexmap::IndexSet;
use itertools::{Either, Itertools};
use pep508_rs::ExtraName;
use rattler_conda_types::Platform;
use serde::Deserialize;
use serde_yaml::Value;
Expand Down Expand Up @@ -48,7 +49,7 @@ enum DeserializablePackageSelector {
#[derive(Hash, Deserialize, Eq, PartialEq)]
struct DeserializablePypiPackageEnvironmentData {
#[serde(default)]
extras: BTreeSet<String>,
extras: BTreeSet<ExtraName>,
}

impl From<DeserializablePypiPackageEnvironmentData> for PypiPackageEnvironmentData {
Expand Down
3 changes: 3 additions & 0 deletions crates/rattler_lock/src/parse/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ pub enum ParseCondaLockError {

#[error("environment {0} and platform {1} refers to a package that does not exist: {2}")]
MissingPackage(String, Platform, Url),

#[error(transparent)]
InvalidPypiPackageName(#[from] pep508_rs::InvalidNameError),
}

impl FromStr for LockFile {
Expand Down
13 changes: 7 additions & 6 deletions crates/rattler_lock/src/parse/serialize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use super::FILE_VERSION;
use crate::utils::serde::RawCondaPackageData;
use crate::{Channel, EnvironmentPackageData, LockFile, PypiPackageData};
use itertools::Itertools;
use pep508_rs::ExtraName;
use rattler_conda_types::Platform;
use serde::{Serialize, Serializer};
use std::collections::{BTreeSet, HashSet};
Expand Down Expand Up @@ -38,7 +39,7 @@ enum SerializablePackageSelector<'a> {
Pypi {
pypi: &'a Url,
#[serde(skip_serializing_if = "BTreeSet::is_empty")]
extras: &'a BTreeSet<String>,
extras: &'a BTreeSet<ExtraName>,
},
}

Expand Down Expand Up @@ -106,10 +107,10 @@ impl<'a> Ord for SerializablePackageSelector<'a> {
}

impl<'a> SerializablePackageData<'a> {
fn name(&self) -> &str {
fn source_name(&self) -> &str {
match self {
SerializablePackageData::Conda(p) => p.name.as_normalized(),
SerializablePackageData::Pypi(p) => &p.name,
SerializablePackageData::Conda(p) => p.name.as_source(),
SerializablePackageData::Pypi(p) => p.name.as_ref(),
}
}

Expand All @@ -131,8 +132,8 @@ impl Ord for SerializablePackageData<'_> {
fn cmp(&self, other: &Self) -> Ordering {
use SerializablePackageData::{Conda, Pypi};
// First sort by name, then by package type specific attributes
self.name()
.cmp(other.name())
self.source_name()
.cmp(other.source_name())
.then_with(|| match (self, other) {
(Conda(a), Conda(b)) => a.cmp(b),
(Pypi(a), Pypi(b)) => a.cmp(b),
Expand Down
6 changes: 3 additions & 3 deletions crates/rattler_lock/src/parse/v3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use crate::{
use fxhash::FxHashMap;
use indexmap::IndexSet;
use pep440_rs::VersionSpecifiers;
use pep508_rs::Requirement;
use pep508_rs::{ExtraName, Requirement};
use rattler_conda_types::{
NoArchType, PackageName, PackageRecord, PackageUrl, Platform, VersionWithSource,
};
Expand Down Expand Up @@ -70,7 +70,7 @@ struct PypiLockedPackageV3 {
#[derive(Clone, Debug, Deserialize, Hash, Eq, PartialEq)]
pub struct PypiPackageEnvironmentDataV3 {
#[serde(default)]
pub extras: BTreeSet<String>,
pub extras: BTreeSet<ExtraName>,
}

impl From<PypiPackageEnvironmentDataV3> for PypiPackageEnvironmentData {
Expand Down Expand Up @@ -178,7 +178,7 @@ pub fn parse_v3_or_lower(document: serde_yaml::Value) -> Result<LockFile, ParseC
LockedPackageKindV3::Pypi(pkg) => {
let deduplicated_index = pypi_packages
.insert_full(PypiPackageData {
name: pkg.name,
name: pep508_rs::PackageName::new(pkg.name)?,
version: pkg.version,
requires_dist: pkg.requires_dist,
requires_python: pkg.requires_python,
Expand Down
6 changes: 3 additions & 3 deletions crates/rattler_lock/src/pypi.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::PackageHashes;
use pep440_rs::VersionSpecifiers;
use pep508_rs::Requirement;
use pep508_rs::{ExtraName, PackageName, Requirement};
use serde::{Deserialize, Serialize};
use serde_with::{serde_as, skip_serializing_none};
use std::cmp::Ordering;
Expand All @@ -13,7 +13,7 @@ use url::Url;
#[derive(Serialize, Deserialize, Eq, PartialEq, Clone, Debug, Hash)]
pub struct PypiPackageData {
/// The name of the package.
pub name: String,
pub name: PackageName,

/// The version of the package.
pub version: pep440_rs::Version,
Expand All @@ -38,7 +38,7 @@ pub struct PypiPackageData {
#[derive(Clone, Debug, Default)]
pub struct PypiPackageEnvironmentData {
/// The extras enabled for the package. Note that the order doesn't matter here but it does matter for serialization.
pub extras: BTreeSet<String>,
pub extras: BTreeSet<ExtraName>,
}

impl PartialOrd for PypiPackageData {
Expand Down
23 changes: 13 additions & 10 deletions crates/rattler_lock/src/utils/serde/pep440_map_or_vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,20 @@ impl<'de> DeserializeAs<'de, Vec<Requirement>> for Pep440MapOrVec {
MapOrVec::Vec(v) => v,
MapOrVec::Map(m) => m
.into_iter()
.map(|(name, spec)| pep508_rs::Requirement {
name,
extras: None,
version_or_url: if spec.is_empty() {
None
} else {
Some(VersionOrUrl::VersionSpecifier(spec))
},
marker: None,
.map(|(name, spec)| {
Ok::<_, pep508_rs::InvalidNameError>(pep508_rs::Requirement {
name: pep508_rs::PackageName::new(name)?,
extras: Vec::new(),
version_or_url: if spec.is_empty() {
None
} else {
Some(VersionOrUrl::VersionSpecifier(spec))
},
marker: None,
})
})
.collect(),
.collect::<Result<Vec<_>, _>>()
.map_err(serde::de::Error::custom)?,
})
}
}
26 changes: 19 additions & 7 deletions py-rattler/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 py-rattler/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ thiserror = "1.0.44"
url = "2.4.1"

openssl = { version = "0.10", optional = true }
pep508_rs = "0.3.0"
pep508_rs = "0.4.2"

[build-dependencies]
pyo3-build-config = "0.20"
Expand Down
4 changes: 2 additions & 2 deletions py-rattler/src/lock/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ impl PyPypiPackageData {
/// The name of the package.
#[getter]
pub fn name(&self) -> String {
self.inner.name.clone()
self.inner.name.to_string()
}

/// The version of the package.
Expand Down Expand Up @@ -475,7 +475,7 @@ impl PyPypiPackageEnvironmentData {
/// The extras enabled for the package. Note that the order doesn't matter.
#[getter]
pub fn extras(&self) -> BTreeSet<String> {
self.inner.extras.clone()
self.inner.extras.iter().map(|e| e.to_string()).collect()
}
}

Expand Down

0 comments on commit 7e0a130

Please sign in to comment.