44import pathlib
55import toml
66
7+ from email .utils import getaddresses
78from pydantic import BaseModel
89
910from hermes .commands .harvest .base import HermesHarvestCommand , HermesHarvestPlugin
@@ -29,7 +30,7 @@ class TomlHarvestPlugin(HermesHarvestPlugin):
2930 ("codeRepository" , "repository" ), ("keywords" , "keywords" )
3031 ]
3132 }
32- allowed_keys_for_person = ["givenName" , "lastName" , "email" , "@id" , "@type" ]
33+ allowed_keys_for_person = ["givenName" , "lastName" , "email" , "@id" , "@type" , "name" ]
3334
3435 def __call__ (self , command : HermesHarvestCommand ):
3536 """start of the process of harvesting the .toml file"""
@@ -173,9 +174,17 @@ def handle_person_in_unknown_format(cls, persons):
173174 if len (temp .keys ()) > 0 :
174175 return_list .append (temp )
175176
177+ elif isinstance (person , str ):
178+ #try to parse the string
179+ try :
180+ [(name , email )] = getaddresses ([person ])
181+ return cls .remove_forbidden_keys ({"name" :name , "email" :email })
182+ except ValueError :
183+ raise ValueError ("Wrong string format for name (and email)." )
184+
176185 else :
177186 #if the person isn't a dictionary raise an Error
178- raise ValueError ("A person must be a dict." )
187+ raise ValueError ("A person must be a dict or special string ." )
179188
180189 #return the person(s)
181190 return return_list
@@ -187,8 +196,16 @@ def handle_person_in_unknown_format(cls, persons):
187196 #the 'person' may be an empty dictionary if all keys are incorrect
188197 return cls .remove_forbidden_keys (persons )
189198
199+ elif isinstance (persons , str ):
200+ #try to parse the string
201+ try :
202+ [(name , email )] = getaddresses ([persons ])
203+ return cls .remove_forbidden_keys ({"name" :name , "email" :email })
204+ except ValueError :
205+ raise ValueError ("Wrong string format for name (and email)." )
206+
190207 #raise an error if the persons data is not in the right format
191- raise ValueError ("A person must be a dict." )
208+ raise ValueError ("A person must be a dict or special string ." )
192209
193210 @classmethod
194211 def remove_forbidden_keys (cls , person ):
0 commit comments