Skip to content

Commit b0c4387

Browse files
committed
better same person logging
1 parent 9d5c79e commit b0c4387

1 file changed

Lines changed: 29 additions & 20 deletions

File tree

src/somesy/pyproject/models.py

Lines changed: 29 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
EmailStr,
1212
Field,
1313
TypeAdapter,
14-
ValidationError,
1514
field_validator,
1615
model_validator,
1716
)
@@ -30,6 +29,13 @@ class STPerson(BaseModel):
3029
name: Annotated[str, Field(min_length=1)]
3130
email: Annotated[Optional[str], Field(min_length=1)] = None
3231

32+
def __str__(self):
33+
"""Return string representation of STPerson."""
34+
if self.email:
35+
return f"{self.name} <{self.email}>"
36+
else:
37+
return self.name
38+
3339

3440
class License(BaseModel):
3541
"""License model for setuptools."""
@@ -129,29 +135,32 @@ def validate_email_format(cls, v):
129135
if v is None:
130136
return []
131137
validated = []
138+
seen = set()
132139
for author in v:
133-
try:
134-
if isinstance(author, STPerson) and author.email:
135-
if not EMailAddress.validate_python(author.email):
136-
logger.warning(
137-
f"Invalid email format for author/maintainer {author}, omitting."
138-
)
139-
else:
140+
if isinstance(author, STPerson) and author.email:
141+
if not EMailAddress.validate_python(author.email):
142+
logger.warning(
143+
f"Invalid email format for author/maintainer {author}."
144+
)
145+
else:
146+
author_str = str(author)
147+
if author_str not in seen:
148+
seen.add(author_str)
140149
validated.append(author)
141-
continue
142-
143-
if " " in author and EMailAddress.validate_python(
144-
author.split(" ")[-1][1:-1]
145-
):
150+
else:
151+
logger.warning(f"Same person {author} is added multiple times.")
152+
elif " " in author and EMailAddress.validate_python(
153+
author.split(" ")[-1][1:-1]
154+
):
155+
validated.append(author)
156+
else:
157+
author_str = str(author)
158+
if author_str not in seen:
159+
seen.add(author_str)
146160
validated.append(author)
147161
else:
148-
logger.warning(
149-
f"Invalid email format for author/maintainer {author}, omitting."
150-
)
151-
except ValidationError:
152-
logger.warning(
153-
f"Invalid email format for author/maintainer {author}, omitting."
154-
)
162+
logger.warning(f"Same person {author} is added multiple times.")
163+
155164
return validated
156165

157166
@field_validator("readme")

0 commit comments

Comments
 (0)