Skip to content

Commit 721b383

Browse files
committed
prevent adding duplicate authors if both Authors and Authors-email is used #53
1 parent 4b970ec commit 721b383

1 file changed

Lines changed: 16 additions & 10 deletions

File tree

codemeta/parsers/python.py

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,8 @@ def parse_python(
280280
metadata = pkg.metadata.items() #type: ignore
281281
# if prevdir: os.chdir(prevdir)
282282

283+
author_mail_processed = False
284+
maintainer_mail_processed = False
283285
for key, value in metadata:
284286
if key == "Classifier": # importlib.metadata
285287
parse_classifier(value, g, res, crosswalk, args)
@@ -304,6 +306,8 @@ def parse_python(
304306
only_mail = pkg.metadata.get("Author-email", "")
305307
if not re.match(r'^[\w._%+-]+@[\w.-]+(\.[\w]+)+$',only_mail):
306308
only_mail = ""
309+
else:
310+
author_mail_processed = True
307311
add_authors(
308312
g,
309313
res,
@@ -312,7 +316,7 @@ def parse_python(
312316
mail=only_mail,
313317
baseuri=args.baseuri,
314318
)
315-
elif key == "Author-email" and pkg: # importlib.metadata
319+
elif key == "Author-email" and pkg and not author_mail_processed: # importlib.metadata
316320
#this contains both the name and the email (name <email>) and may contain multiple such pairs seperated by a comma
317321
add_authors(
318322
g,
@@ -339,6 +343,8 @@ def parse_python(
339343
only_mail = pkg.metadata.get("Maintainer-email", "")
340344
if not re.match(r'^[\w._%+-]+@[\w.-]+(\.[\w]+)+$',only_mail):
341345
only_mail = ""
346+
else:
347+
maintainer_mail_processed = True
342348
add_authors(
343349
g,
344350
res,
@@ -348,16 +354,16 @@ def parse_python(
348354
mail=only_mail,
349355
baseuri=args.baseuri,
350356
)
351-
elif key == "Maintainer-email" and pkg: # importlib.metadata
357+
elif key == "Maintainer-email" and pkg and not maintainer_mail_processed: # importlib.metadata
352358
#this contains both the name and the email (name <email>) and may contain multiple such pairs seperated by a comma
353-
add_authors(
354-
g,
355-
res,
356-
value,
357-
property=SDO.maintainer,
358-
single_author=False,
359-
baseuri=args.baseuri,
360-
)
359+
add_authors(
360+
g,
361+
res,
362+
value,
363+
property=SDO.maintainer,
364+
single_author=False,
365+
baseuri=args.baseuri,
366+
)
361367
elif key == "Project-URL":
362368
if "," in value:
363369
label, url = value.split(",", 1) # according to spec

0 commit comments

Comments
 (0)