Skip to content

Commit 1a31e7e

Browse files
committed
feat: add configuration options for directly mapped URLs
fix: add repo label
1 parent a677a90 commit 1a31e7e

File tree

1 file changed

+53
-14
lines changed

1 file changed

+53
-14
lines changed

hatch_nodejs_version/metadata_source.py

Lines changed: 53 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ def __init__(self, *args, **kwargs):
3030
self.__path = None
3131
self.__fields = None
3232
self.__contributors_as_maintainers = None
33+
self.__homepage_label = None
34+
self.__bugs_label = None
35+
self.__repository_label = None
3336

3437
@property
3538
def path(self) -> str:
@@ -57,9 +60,8 @@ def fields(self) -> None | set[str]:
5760
isinstance(fields, list) and all(isinstance(f, str) for f in fields)
5861
):
5962
raise TypeError(
60-
"Option `fields` for build hook `{}` must be a list of strings".format(
61-
self.PLUGIN_NAME
62-
)
63+
"Option `fields` for build hook `{}` "
64+
"must be a list of strings".format(self.PLUGIN_NAME)
6365
)
6466
self.__fields = set(fields)
6567
return self.__fields
@@ -72,13 +74,52 @@ def contributors_as_maintainers(self) -> bool:
7274
)
7375
if not isinstance(contributors_as_maintainers, bool):
7476
raise TypeError(
75-
"Option `contributors-as-maintainers` for build hook `{}` must be a boolean".format(
76-
self.PLUGIN_NAME
77-
)
77+
"Option `contributors-as-maintainers` for build hook `{}` "
78+
"must be a boolean".format(self.PLUGIN_NAME)
7879
)
7980
self.__contributors_as_maintainers = contributors_as_maintainers
8081
return self.__contributors_as_maintainers
8182

83+
@property
84+
def homepage_label(self) -> bool:
85+
if self.__homepage_label is None:
86+
homepage_label = self.config.get("homepage-label", "Homepage")
87+
88+
if not isinstance(homepage_label, str):
89+
raise TypeError(
90+
"Option `homepage-label` for build hook `{}` "
91+
"must be a string".format(self.PLUGIN_NAME)
92+
)
93+
self.__homepage_label = homepage_label
94+
return self.__homepage_label
95+
96+
@property
97+
def bugs_label(self) -> bool:
98+
if self.__bugs_label is None:
99+
bug_tracker_label = self.config.get("bugs-label", "Bug Tracker")
100+
101+
if not isinstance(bug_tracker_label, str):
102+
raise TypeError(
103+
"Option `bugs-label` for build hook `{}` must be a string".format(
104+
self.PLUGIN_NAME
105+
)
106+
)
107+
self.__bugs_label = bug_tracker_label
108+
return self.__bugs_label
109+
110+
@property
111+
def repository_label(self) -> bool:
112+
if self.__repository_label is None:
113+
bug_tracker_label = self.config.get("repository-label", "Repository")
114+
115+
if not isinstance(bug_tracker_label, str):
116+
raise TypeError(
117+
"Option `repository-label` for build hook `{}` "
118+
"must be a string".format(self.PLUGIN_NAME)
119+
)
120+
self.__repository_label = bug_tracker_label
121+
return self.__repository_label
122+
82123
def load_package_data(self):
83124
path = os.path.normpath(os.path.join(self.root, self.path))
84125
if not os.path.isfile(path):
@@ -136,19 +177,17 @@ def update(self, metadata: dict[str, Any]):
136177
authors = [self._parse_person(package["author"])]
137178

138179
if "contributors" in package:
139-
contributors = [
140-
self._parse_person(p) for p in package["contributors"]
141-
]
180+
contributors = [self._parse_person(p) for p in package["contributors"]]
142181
if self.contributors_as_maintainers:
143182
maintainers = contributors
144183
else:
145184
authors = [*(authors or []), *contributors]
146185

147186
if authors is not None:
148-
new_metadata['authors'] = authors
187+
new_metadata["authors"] = authors
149188

150189
if maintainers is not None:
151-
new_metadata['maintainers'] = maintainers
190+
new_metadata["maintainers"] = maintainers
152191

153192
if "keywords" in package:
154193
new_metadata["keywords"] = package["keywords"]
@@ -162,13 +201,13 @@ def update(self, metadata: dict[str, Any]):
162201
# Construct URLs
163202
urls = {}
164203
if "homepage" in package:
165-
urls["homepage"] = package["homepage"]
204+
urls[self.homepage_label] = package["homepage"]
166205
if "bugs" in package:
167206
bugs_url = self._parse_bugs(package["bugs"])
168207
if bugs_url is not None:
169-
urls["bug tracker"] = bugs_url
208+
urls[self.bugs_label] = bugs_url
170209
if "repository" in package:
171-
urls["repository"] = self._parse_repository(package["repository"])
210+
urls[self.repository_label] = self._parse_repository(package["repository"])
172211

173212
# Write URLs
174213
if urls:

0 commit comments

Comments
 (0)