|
7 | 7 | import os.path
|
8 | 8 | import re
|
9 | 9 | import urllib.parse
|
10 |
| -from typing import Any |
| 10 | +from typing import Any, Union |
11 | 11 |
|
12 | 12 | from hatchling.metadata.plugin.interface import MetadataHookInterface
|
13 | 13 |
|
14 |
| -AUTHOR_PATTERN = r"^([^<(]+?)?[ \t]*(?:<([^>(]+?)>)?[ \t]*(?:\(([^)]+?)\)|$)" |
| 14 | +AUTHOR_PATTERN = r"^(?P<name>[^<(]+?)?[ \t]*(?:<(?P<email>[^>(]+?)>)?[ \t]*(?:\((?P<url>[^)]+?)\)|$)" |
15 | 15 | REPOSITORY_PATTERN = r"^(?:(gist|bitbucket|gitlab|github):)?(.*?)$"
|
16 | 16 | REPOSITORY_TABLE = {
|
17 | 17 | "gitlab": "https://gitlab.com",
|
@@ -137,19 +137,24 @@ def _parse_bugs(self, bugs: str | dict[str, str]) -> str | None:
|
137 | 137 | return bugs["url"]
|
138 | 138 |
|
139 | 139 | def _parse_person(self, person: dict[str, str]) -> dict[str, str]:
|
140 |
| - if {"url", "email"} & person.keys(): |
141 |
| - result = {"name": person["name"]} |
142 |
| - if "email" in person: |
143 |
| - result["email"] = person["email"] |
| 140 | + result = {} |
| 141 | + if isinstance(person, dict): |
| 142 | + if {"url", "email"} & person.keys(): |
| 143 | + result["name"] = person["name"] |
| 144 | + if "email" in person: |
| 145 | + result["email"] = person["email"] |
| 146 | + return result |
| 147 | + else: |
| 148 | + author = person["name"] |
144 | 149 | else:
|
145 |
| - match = re.match(AUTHOR_PATTERN, person["name"]) |
146 |
| - if match is None: |
147 |
| - raise ValueError(f"Invalid author name: {person['name']}") |
148 |
| - name, email, _ = match.groups() |
149 |
| - result = {"name": name} |
150 |
| - if email is not None: |
151 |
| - result["email"] = email |
152 |
| - |
| 150 | + author = person |
| 151 | + match = re.match(AUTHOR_PATTERN, author) |
| 152 | + if match is None: |
| 153 | + raise ValueError(f"Invalid author name: {author}") |
| 154 | + name, email, _ = match.groups() |
| 155 | + result = {"name": name} |
| 156 | + if email is not None: |
| 157 | + result["email"] = email |
153 | 158 | return result
|
154 | 159 |
|
155 | 160 | def _parse_repository(self, repository: str | dict[str, str]) -> str:
|
|
0 commit comments