Skip to content

Commit

Permalink
Fix parsing version
Browse files Browse the repository at this point in the history
  • Loading branch information
anti-social committed Aug 1, 2023
1 parent 5912fd0 commit 58054f4
Showing 1 changed file with 15 additions and 10 deletions.
25 changes: 15 additions & 10 deletions rye/src/pyproject.rs
Original file line number Diff line number Diff line change
Expand Up @@ -745,17 +745,22 @@ impl PyProject {

/// Returns the version.
pub fn version(&mut self) -> Result<Version, Error> {
let mut version = self
.doc
.get("project")
.and_then(|x| x.get("version"))
.map(|x| x.to_string());
if let Some(dynamic) = self.dynamic() {
if dynamic.contains(&"version".to_string()) {
let read_version = || {
self.doc
.get("project")
.and_then(|x| x.get("version"))
.and_then(|x| x.as_str().map(String::from))
};

let version = match self.dynamic() {
Some(dynamic) if dynamic.contains(&"version".to_string()) => {
if let Ok(metadata) = get_project_metadata(&self.root_path()) {
version = Some(metadata.version);
};
};
Some(metadata.version)
} else {
read_version()
}
}
_ => read_version(),
};

match version {
Expand Down

0 comments on commit 58054f4

Please sign in to comment.