Skip to content

Commit 902b93a

Browse files
committed
fix(poetry): port project name normalization from poetry-core
1 parent 64d8a55 commit 902b93a

1 file changed

Lines changed: 18 additions & 2 deletions

File tree

crates/pet-poetry/src/pyproject_toml.rs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,14 @@ use std::{
66
path::{Path, PathBuf},
77
};
88

9+
use lazy_static::lazy_static;
910
use log::{error, trace};
11+
use regex::Regex;
12+
13+
lazy_static! {
14+
static ref NORMALIZE_NAME: Regex = Regex::new(r"[-_.]+")
15+
.expect("Error generating RegEx for poetry project name normalization");
16+
}
1017

1118
#[derive(Debug)]
1219
pub struct PyProjectToml {
@@ -15,8 +22,17 @@ pub struct PyProjectToml {
1522

1623
impl PyProjectToml {
1724
fn new(name: String, file: PathBuf) -> Self {
18-
trace!("Poetry project: {:?} with name {:?}", file, name);
19-
PyProjectToml { name }
25+
// Source from https://github.com/python-poetry/poetry-core/blob/a2c068227358984d835c9684de723b046bdcd67a/src/poetry/core/_vendor/packaging/utils.py#L46-L51
26+
// normalized_name = re.sub(r"[-_.]+", "-", name).lower()
27+
let normalized_name = NORMALIZE_NAME
28+
.replace_all(&name.to_lowercase(), "-")
29+
.chars()
30+
.collect::<String>();
31+
32+
trace!("Poetry project: {:?} with name {:?}", file, normalized_name);
33+
PyProjectToml {
34+
name: normalized_name,
35+
}
2036
}
2137
pub fn find(path: &Path) -> Option<Self> {
2238
trace!("Finding poetry file in {:?}", path);

0 commit comments

Comments
 (0)