Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure that authors and maintainers are normalized. #276

Merged
merged 1 commit into from
Feb 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/poetry/core/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from typing import Union
from warnings import warn

from poetry.core.utils.helpers import combine_unicode
from poetry.core.utils.helpers import readme_content_type


Expand Down Expand Up @@ -76,10 +77,10 @@ def configure_package(
package.root_dir = root

for author in config["authors"]:
package.authors.append(author)
package.authors.append(combine_unicode(author))

for maintainer in config.get("maintainers", []):
package.maintainers.append(maintainer)
package.maintainers.append(combine_unicode(maintainer))

package.description = config.get("description", "")
package.homepage = config.get("homepage")
Expand Down
5 changes: 5 additions & 0 deletions src/poetry/core/utils/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import shutil
import stat
import tempfile
import unicodedata

from collections.abc import Mapping
from contextlib import contextmanager
Expand All @@ -20,6 +21,10 @@
_canonicalize_regex = re.compile(r"[-_]+")


def combine_unicode(string: str) -> str:
return unicodedata.normalize("NFC", string)


def canonicalize_name(name: str) -> str:
return _canonicalize_regex.sub("-", name).lower()

Expand Down
2 changes: 1 addition & 1 deletion tests/fixtures/sample_project/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name = "my-package"
version = "1.2.3"
description = "Some description."
authors = [
"Sébastien Eustace <sebastien@eustace.io>"
"Sébastien Eustace <sebastien@eustace.io>"
]
license = "MIT"

Expand Down
10 changes: 10 additions & 0 deletions tests/utils/test_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import pytest

from poetry.core.utils.helpers import canonicalize_name
from poetry.core.utils.helpers import combine_unicode
from poetry.core.utils.helpers import parse_requires
from poetry.core.utils.helpers import readme_content_type
from poetry.core.utils.helpers import temporary_directory
Expand Down Expand Up @@ -76,6 +77,15 @@ def test_utils_helpers_canonical_names(raw: str):
assert canonicalize_name(raw) == "a-b-c"


def test_utils_helpers_combine_unicode():
combined_expected = "é"
decomposed = "é"
assert combined_expected != decomposed

combined = combine_unicode(decomposed)
assert combined == combined_expected


def test_utils_helpers_temporary_directory_readonly_file():
with temporary_directory() as temp_dir:
readonly_filename = os.path.join(temp_dir, "file.txt")
Expand Down