From 58054f42dfa18e313dfb4c8ef8a3317c3fd7bb4b Mon Sep 17 00:00:00 2001 From: Alexander Koval Date: Tue, 1 Aug 2023 12:58:54 +0300 Subject: [PATCH] Fix parsing version --- rye/src/pyproject.rs | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/rye/src/pyproject.rs b/rye/src/pyproject.rs index 50c3a297ed..0ffac4977e 100644 --- a/rye/src/pyproject.rs +++ b/rye/src/pyproject.rs @@ -745,17 +745,22 @@ impl PyProject { /// Returns the version. pub fn version(&mut self) -> Result { - 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 {