diff --git a/setup.cfg b/setup.cfg index 5fb2065..ae525fe 100644 --- a/setup.cfg +++ b/setup.cfg @@ -63,12 +63,14 @@ exclude = # PDF = ReportLab; RXP full = configupdater>=3.0.1,<4 - atoml>=1.1.0,<2 + # atoml>=1.1.0,<2 + atoml @ git+https://github.com/abravalheri/atoml@table-common-ancestor#egg=atoml lite = tomli-w>=0.4.0,<2 all = configupdater>=3.0.1,<4 - atoml>=1.1.0,<2 + # atoml>=1.1.0,<2 + atoml @ git+https://github.com/abravalheri/atoml@table-common-ancestor#egg=atoml tomli-w>=0.4.0,<2 # Add here test requirements (semicolon/line-separated) diff --git a/src/ini2toml/plugins/setuptools_pep621.py b/src/ini2toml/plugins/setuptools_pep621.py index 1ba3b42..1d05836 100644 --- a/src/ini2toml/plugins/setuptools_pep621.py +++ b/src/ini2toml/plugins/setuptools_pep621.py @@ -196,27 +196,25 @@ def merge_and_rename_urls(self, doc: R) -> R: metadata.replace_first_remove_others(keys, "urls", urls_kv) return doc - def merge_authors_maintainers_and_emails(self, doc: R) -> R: - # author OR maintainer => author.name - # author-email OR maintainer-email => author.email + def process_authors_maintainers_and_emails(self, doc: R) -> R: + # author OR maintainer => .name + # author-email OR maintainer-email => .email metadata: IR = doc["metadata"] - author_ = split_comment(metadata.get("author", "")) - maintainer_ = split_comment(metadata.get("maintainer", "")) - names_ = (author_, maintainer_) - names = chain_iter(n.value_or("").strip().split(",") for n in names_) - a_email_ = split_comment(metadata.get("author-email", "")) - m_email_ = split_comment(metadata.get("maintainer-email", "")) - emails_ = (a_email_, m_email_) - emails = chain_iter(n.value_or("").strip().split(",") for n in emails_) - comments = [o.comment for o in chain(names_, emails_) if o.has_comment()] - - combined_ = {e: n for n, e in zip(names, emails) if n} # deduplicate - out = [{"name": n, "email": e} for e, n in combined_.items()] - if out: - keys = ("author", "maintainer", "author-email", "maintainer-email") - i = metadata.replace_first_remove_others(keys, "author", out) - for j, cmt in enumerate(comments): - metadata.insert(j + i + 1, CommentKey(), cmt) + for key in ("author", "maintainer"): + name_field = split_comment(metadata.get(key, "")) + names = name_field.value_or("").strip().split(",") + email_field = split_comment(metadata.get(f"{key}-email", "")) + emails = email_field.value_or("").strip().split(",") + fields = (name_field, email_field) + comments = [f.comment for f in fields if f.has_comment()] + + combined = {e: n for n, e in zip(names, emails) if n} # deduplicate + out = [{"name": n, "email": e} for e, n in combined.items()] + if out: + keys = (key, f"{key}-email") + i = metadata.replace_first_remove_others(keys, key, out) + for j, cmt in enumerate(comments): + metadata.insert(j + i + 1, CommentKey(), cmt) return doc def merge_and_rename_long_description_and_content_type(self, doc: R) -> R: @@ -462,7 +460,7 @@ def pep621_transform(self, doc: R) -> R: transformations = [ # --- transformations mainly focusing on PEP 621 --- self.merge_and_rename_urls, - self.merge_authors_maintainers_and_emails, + self.process_authors_maintainers_and_emails, self.merge_license_and_files, self.merge_and_rename_long_description_and_content_type, self.move_and_split_entrypoints, diff --git a/tests/examples/flask/pyproject.toml b/tests/examples/flask/pyproject.toml index 8185bb1..aa8516a 100644 --- a/tests/examples/flask/pyproject.toml +++ b/tests/examples/flask/pyproject.toml @@ -34,7 +34,7 @@ text = "BSD-3-Clause" name = "Armin Ronacher" email = "armin.ronacher@active-4.com" -[[project.author]] +[[project.maintainer]] name = "Pallets" email = "contact@palletsprojects.com" diff --git a/tests/examples/virtualenv/pyproject.toml b/tests/examples/virtualenv/pyproject.toml index f0f1f37..a863220 100644 --- a/tests/examples/virtualenv/pyproject.toml +++ b/tests/examples/virtualenv/pyproject.toml @@ -45,6 +45,10 @@ content-type = "text/markdown" name = "Bernat Gabor" email = "gaborjbernat@gmail.com" +[[project.maintainer]] +name = "Bernat Gabor" +email = "gaborjbernat@gmail.com" + [project.license] file = "LICENSE"