Skip to content

Commit

Permalink
Separate author and maintainer
Browse files Browse the repository at this point in the history
  • Loading branch information
abravalheri committed Nov 8, 2021
1 parent 96f5105 commit 05d7d8f
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 24 deletions.
6 changes: 4 additions & 2 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
40 changes: 19 additions & 21 deletions src/ini2toml/plugins/setuptools_pep621.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 => <author/maintainer>.name
# author-email OR maintainer-email => <author/maintainer>.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:
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion tests/examples/flask/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
4 changes: 4 additions & 0 deletions tests/examples/virtualenv/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down

0 comments on commit 05d7d8f

Please sign in to comment.