From 64d8a557d0f7e2fa30516320a99a11035a2a3c26 Mon Sep 17 00:00:00 2001 From: Victor Colomb Date: Thu, 21 Aug 2025 12:18:23 +0200 Subject: [PATCH 1/3] test(poetry): should normalize project name from pyproject.toml --- crates/pet-poetry/src/pyproject_toml.rs | 26 +++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/crates/pet-poetry/src/pyproject_toml.rs b/crates/pet-poetry/src/pyproject_toml.rs index 0bd785ad..87983476 100644 --- a/crates/pet-poetry/src/pyproject_toml.rs +++ b/crates/pet-poetry/src/pyproject_toml.rs @@ -85,6 +85,32 @@ readme = "README.md" python = "^3.12" +[build-system] +requires = ["poetry-core"] +build-backend = "poetry.core.masonry.api" +"#; + assert_eq!( + parse_contents(cfg, Path::new("pyproject.toml")) + .unwrap() + .name, + "poetry-demo" + ); + } + + #[test] + fn extract_normalized_name_from_pyproject_toml() { + let cfg = r#" +[tool.poetry] +name = "poetry_.demo" +version = "0.1.0" +description = "" +authors = ["User Name "] +readme = "README.md" + +[tool.poetry.dependencies] +python = "^3.12" + + [build-system] requires = ["poetry-core"] build-backend = "poetry.core.masonry.api" From 902b93a90115d35e23ef0b5e9c1b32eab79217d2 Mon Sep 17 00:00:00 2001 From: Victor Colomb Date: Thu, 21 Aug 2025 12:35:52 +0200 Subject: [PATCH 2/3] fix(poetry): port project name normalization from poetry-core --- crates/pet-poetry/src/pyproject_toml.rs | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/crates/pet-poetry/src/pyproject_toml.rs b/crates/pet-poetry/src/pyproject_toml.rs index 87983476..9e753282 100644 --- a/crates/pet-poetry/src/pyproject_toml.rs +++ b/crates/pet-poetry/src/pyproject_toml.rs @@ -6,7 +6,14 @@ use std::{ path::{Path, PathBuf}, }; +use lazy_static::lazy_static; use log::{error, trace}; +use regex::Regex; + +lazy_static! { + static ref NORMALIZE_NAME: Regex = Regex::new(r"[-_.]+") + .expect("Error generating RegEx for poetry project name normalization"); +} #[derive(Debug)] pub struct PyProjectToml { @@ -15,8 +22,17 @@ pub struct PyProjectToml { impl PyProjectToml { fn new(name: String, file: PathBuf) -> Self { - trace!("Poetry project: {:?} with name {:?}", file, name); - PyProjectToml { name } + // Source from https://github.com/python-poetry/poetry-core/blob/a2c068227358984d835c9684de723b046bdcd67a/src/poetry/core/_vendor/packaging/utils.py#L46-L51 + // normalized_name = re.sub(r"[-_.]+", "-", name).lower() + let normalized_name = NORMALIZE_NAME + .replace_all(&name.to_lowercase(), "-") + .chars() + .collect::(); + + trace!("Poetry project: {:?} with name {:?}", file, normalized_name); + PyProjectToml { + name: normalized_name, + } } pub fn find(path: &Path) -> Option { trace!("Finding poetry file in {:?}", path); From 9491c07746d87f9721c07303e86c82dee17fc97c Mon Sep 17 00:00:00 2001 From: Victor Colomb Date: Wed, 8 Oct 2025 13:19:08 +0200 Subject: [PATCH 3/3] fix(pet-jsonrpc): clippy error --- crates/pet-python-utils/src/cache.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/pet-python-utils/src/cache.rs b/crates/pet-python-utils/src/cache.rs index 00b64282..e0575a86 100644 --- a/crates/pet-python-utils/src/cache.rs +++ b/crates/pet-python-utils/src/cache.rs @@ -91,7 +91,7 @@ impl CacheImpl { Entry::Occupied(lock) => lock.get().clone(), Entry::Vacant(lock) => { let cache = Box::new(CacheEntryImpl::create(cache_directory.clone(), executable)) - as Box<(dyn CacheEntry + 'static)>; + as Box; lock.insert(Arc::new(Mutex::new(cache))).clone() } }