diff --git a/src/poetry/core/packages/package.py b/src/poetry/core/packages/package.py index 1f72b7e67..45b9a34b8 100644 --- a/src/poetry/core/packages/package.py +++ b/src/poetry/core/packages/package.py @@ -1,6 +1,5 @@ from __future__ import annotations -import re import warnings from typing import TYPE_CHECKING @@ -13,6 +12,7 @@ from poetry.core.constraints.version.exceptions import ParseConstraintError from poetry.core.packages.dependency_group import MAIN_GROUP from poetry.core.packages.specification import PackageSpecification +from poetry.core.utils.patterns import AUTHOR_REGEX from poetry.core.version.exceptions import InvalidVersionError @@ -32,10 +32,6 @@ T = TypeVar("T", bound="Package") -AUTHOR_REGEX = re.compile( - r"(?u)^(?P[- .,\w\d'’\"():&]+)(?: <(?P.+?)>)?$" # noqa: RUF001 -) - class Package(PackageSpecification): AVAILABLE_PYTHONS: ClassVar[set[str]] = { diff --git a/src/poetry/core/utils/patterns.py b/src/poetry/core/utils/patterns.py index c2d9d9bfb..c43bb28eb 100644 --- a/src/poetry/core/utils/patterns.py +++ b/src/poetry/core/utils/patterns.py @@ -3,6 +3,8 @@ import re +AUTHOR_REGEX = re.compile(r"(?u)^(?P[^<>]+)(?: <(?P.+?)>)?$") + wheel_file_re = re.compile( r"""^(?P(?P.+?)(-(?P\d.+?))?) ((-(?P\d.*?))?-(?P.+?)-(?P.+?)-(?P.+?) diff --git a/tests/packages/test_package.py b/tests/packages/test_package.py index fd9b88b31..b95972f51 100644 --- a/tests/packages/test_package.py +++ b/tests/packages/test_package.py @@ -83,6 +83,8 @@ def test_package_authors_invalid() -> None: ("John-Paul: Doe", None), ("John-Paul: Doe", "jp@nomail.none"), ("John Doe the 3rd", "3rd@jd.net"), + ("FirstName LastName firstname.lastname@company.com", None), + ("Surname, Given Name [Department]", None), ], ) def test_package_authors_valid(name: str, email: str | None) -> None: @@ -98,12 +100,9 @@ def test_package_authors_valid(name: str, email: str | None) -> None: ("name",), [ ("",), - ("john@john.doe",), + ("",), (" None: