Skip to content

Commit

Permalink
Merge pull request #157 from jelmer/bump-pep
Browse files Browse the repository at this point in the history
Bump pep crates
  • Loading branch information
jelmer authored Nov 6, 2024
2 parents ac133e1 + 539f8ec commit 44a12c3
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 75 deletions.
106 changes: 75 additions & 31 deletions Cargo.lock

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

6 changes: 2 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ log = "0.4.20"
text-size = "1.1.1"
debversion = { version = "^0.4", features = ["serde"] }
chrono = "0.4.31"
fancy-regex = "0.11"
fancy-regex = "0.14"
lazy-regex = "3.0.2"
textwrap = "0.16.0"
chatgpt_rs = { version = "1", optional = true }
Expand All @@ -60,9 +60,7 @@ tokio = { version = "1", features = ["rt-multi-thread"], optional = true }
serde_yaml = { version = "0.9" }
debian-control = "0.1.18"
maplit = "1.0.2"
# Pin specific versions of pep508 and pep440, since we need compatible versions.
pep508_rs = { version = "0.6.1" }
pep440_rs = { version = "0.6.5" }
pep508_rs = "0.9.1"

[dev-dependencies]
maplit = "1.0.2"
61 changes: 22 additions & 39 deletions src/problems/common.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use crate::Problem;
use pep508_rs::pep440_rs;
use serde::{Deserialize, Serialize};
use std::borrow::Cow;
use std::fmt::{self, Debug, Display};
Expand Down Expand Up @@ -253,57 +254,39 @@ impl Problem for MissingPythonDistribution {
}
}

fn find_python_version(marker: Vec<Vec<pep508_rs::MarkerExpression>>) -> Option<i32> {
let mut major_version = None;
for expr in marker.iter().flat_map(|x| x.iter()) {
match expr {
pep508_rs::MarkerExpression::Version {
key: pep508_rs::MarkerValueVersion::PythonVersion,
specifier,
} => {
let version = specifier.version();
major_version = Some(version.release()[0] as i32);
}
_ => {}
}
}

major_version
}

impl MissingPythonDistribution {
pub fn from_requirement_str(
text: &str,
python_version: Option<i32>,
) -> MissingPythonDistribution {
use pep440_rs::Operator;
use pep508_rs::{
MarkerOperator, MarkerTree, MarkerValue, MarkerValueVersion, Requirement, VersionOrUrl,
};
use pep508_rs::{Requirement, VersionOrUrl};
use std::str::FromStr;

let depspec = Requirement::from_str(text).unwrap();
let depspec: Requirement = Requirement::from_str(text).unwrap();

let distribution = depspec.name.to_string();

fn extract_python_version(marker: &MarkerTree) -> Option<i32> {
match marker {
MarkerTree::Expression(e) => {
if e.operator == MarkerOperator::GreaterEqual
&& e.l_value
== pep508_rs::MarkerValue::MarkerEnvVersion(
MarkerValueVersion::PythonVersion,
)
{
if let MarkerValue::QuotedString(v) = &e.r_value {
return Some(v.split('.').next().unwrap().parse().unwrap());
}
}
None
}
MarkerTree::And(os) => {
let mut pv = None;
for o in os {
let npv = extract_python_version(o);
if let Some(npv) = npv {
pv = Some(npv);
}
}
pv
}
MarkerTree::Or(os) => {
if os.len() == 1 {
return extract_python_version(&os[0]);
}
None
}
}
}

let python_version =
python_version.or_else(|| depspec.marker.as_ref().and_then(extract_python_version));
python_version.or_else(|| find_python_version(depspec.marker.to_dnf()));
let minimum_version = if let Some(v_u) = depspec.version_or_url {
if let VersionOrUrl::VersionSpecifier(vs) = v_u {
if vs.len() == 1 {
Expand Down
2 changes: 1 addition & 1 deletion src/sbuild.rs
Original file line number Diff line number Diff line change
Expand Up @@ -682,7 +682,7 @@ pub const DEFAULT_LOOK_BACK: usize = 50;
pub fn strip_build_tail<'a>(
lines: &'a [&'a str],
look_back: Option<usize>,
) -> (&'a [&'a str], HashMap<&'a str, &'_ [&'a str]>) {
) -> (&'a [&'a str], HashMap<&'a str, &'a [&'a str]>) {
let look_back = look_back.unwrap_or(DEFAULT_LOOK_BACK);

let mut interesting_lines: &'_ [&'a str] = lines;
Expand Down

0 comments on commit 44a12c3

Please sign in to comment.