Skip to content

Commit

Permalink
Change like packaging
Browse files Browse the repository at this point in the history
  • Loading branch information
ischaojie committed May 6, 2023
1 parent ce1dba2 commit 85daa98
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 30 deletions.
22 changes: 4 additions & 18 deletions src/version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -290,12 +290,6 @@ pub struct Version {
/// > identifier by a plus. Local version labels have no specific semantics assigned, but some
/// > syntactic restrictions are imposed.
pub local: Option<Vec<LocalSegment>>,
/// The first item of release or 0 if unavailable.
pub major: usize,
/// The second item of release or 0 if unavailable.
pub minor: usize,
/// The third item of release or 0 if unavailable.
pub micro: usize,
}

#[cfg(feature = "pyo3")]
Expand Down Expand Up @@ -353,17 +347,17 @@ impl PyVersion {
/// The first item of release or 0 if unavailable.
#[getter]
pub fn major(&self) -> usize {
self.0.major
if !self.release().is_empty() {self.release()[0]} else {0}
}
/// The second item of release or 0 if unavailable.
#[getter]
pub fn minor(&self) -> usize {
self.0.minor
if self.release().len() > 1 {self.release()[1]} else {0}
}
/// The third item of release or 0 if unavailable.
#[getter]
pub fn micro(&self) -> usize {
self.0.micro
if self.release().len() > 2 {self.release()[2]} else {0}
}

/// Parses a PEP 440 version string
Expand Down Expand Up @@ -448,9 +442,6 @@ impl Version {
post: None,
dev: None,
local: None,
major: 0,
minor: 0,
micro: 0,
}
}

Expand Down Expand Up @@ -789,9 +780,7 @@ impl Version {
.split('.')
.map(|segment| segment.parse::<usize>().map_err(|err| err.to_string()))
.collect::<Result<Vec<usize>, String>>()?;
let major = if !release.is_empty() { release[0] } else { 0 };
let minor = if release.len() >= 2 { release[1] } else { 0 };
let micro = if release.len() >= 3 { release[2] } else { 0 };

let star = captures.name("trailing_dot_star").is_some();
if star {
if pre.is_some() {
Expand All @@ -817,9 +806,6 @@ impl Version {
post,
dev,
local,
major,
minor,
micro,
};
Ok((version, star))
}
Expand Down
12 changes: 0 additions & 12 deletions src/version_specifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1039,9 +1039,6 @@ mod test {
post: None,
dev: None,
local: None,
major: 0,
minor: 9,
micro: 0,
}
},
VersionSpecifier {
Expand All @@ -1053,9 +1050,6 @@ mod test {
post: None,
dev: None,
local: None,
major: 1,
minor: 0,
micro: 0,
}
},
VersionSpecifier {
Expand All @@ -1067,9 +1061,6 @@ mod test {
post: None,
dev: None,
local: None,
major: 1,
minor: 3,
micro: 4,
}
},
VersionSpecifier {
Expand All @@ -1081,9 +1072,6 @@ mod test {
post: None,
dev: None,
local: None,
major: 2,
minor: 0,
micro: 0,
}
}
]
Expand Down

0 comments on commit 85daa98

Please sign in to comment.