Skip to content

Commit c93c8e0

Browse files
committed
Clean up marketplace.py
1 parent e33c023 commit c93c8e0

1 file changed

Lines changed: 16 additions & 16 deletions

File tree

src/hermes/commands/marketplace.py

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,11 @@ def handle_data(self, data):
9696
plugin = SchemaOrgSoftwareApplication.model_validate_json(data)
9797
self.plugins.append(plugin)
9898

99+
def parse_plugins_from_url(self, url: str = MARKETPLACE_URL, user_agent: str = hermes_user_agent):
100+
response = requests.get(url, headers={"User-Agent": user_agent})
101+
response.raise_for_status()
102+
self.feed(response.text)
103+
99104

100105
@cache
101106
def _doi_is_version_of_concept_doi(doi: str, concept_doi: str) -> bool:
@@ -150,28 +155,22 @@ def _sort_plugins_by_step(plugins: list[SchemaOrgSoftwareApplication]) -> dict[s
150155

151156

152157
def _plugin_loc(_plugin: SchemaOrgSoftwareApplication) -> str:
153-
return "builtin" if _plugin.is_part_of == schema_org_hermes else (_plugin.url or "")
158+
return (
159+
"builtin"
160+
if _is_hermes_reference(_plugin.is_part_of)
161+
else (_plugin.url or "")
162+
)
154163

155164

156165
def main():
157-
response = requests.get(MARKETPLACE_URL, headers={"User-Agent": hermes_user_agent})
158-
response.raise_for_status()
159-
160166
parser = PluginMarketPlaceParser()
161-
parser.feed(response.text)
167+
parser.parse_plugins_from_url(MARKETPLACE_URL, hermes_user_agent)
162168

163169
print(
164170
"A detailed list of available plugins can be found on the HERMES website at",
165171
MARKETPLACE_URL + "."
166172
)
167173

168-
def _plugin_loc(_plugin: SchemaOrgSoftwareApplication) -> str:
169-
return (
170-
"builtin"
171-
if _is_hermes_reference(_plugin.is_part_of)
172-
else (_plugin.url or "")
173-
)
174-
175174
if parser.plugins:
176175
print()
177176
max_name_len = max(map(lambda plugin: len(plugin.name), parser.plugins))
@@ -230,10 +229,11 @@ def is_valid(self) -> bool:
230229

231230

232231
def get_plugin_infos() -> list[PluginInfo]:
233-
response = requests.get(MARKETPLACE_URL, headers={"User-Agent": hermes_user_agent})
234-
response.raise_for_status()
232+
"""
233+
Returns a List of PluginInfos which are meant to be used by the init-command.
234+
"""
235235
parser = PluginMarketPlaceParser()
236-
parser.feed(response.text)
236+
parser.parse_plugins_from_url(MARKETPLACE_URL, hermes_user_agent)
237237
infos: list[PluginInfo] = []
238238
if parser.plugins:
239239
plugins_sorted = _sort_plugins_by_step(parser.plugins)
@@ -243,7 +243,7 @@ def get_plugin_infos() -> list[PluginInfo]:
243243
info.name = plugin.name
244244
info.step = step
245245
info.location = _plugin_loc(plugin)
246-
info.builtin = plugin.is_part_of == schema_org_hermes
246+
info.builtin = info.location == "builtin"
247247
info.install_url = plugin.install_url
248248
info.abstract = plugin.abstract
249249
infos.append(info)

0 commit comments

Comments
 (0)