Skip to content

Commit afb8189

Browse files
Issue softwarepub#276 - Harvest metadata from CodeMeta via path
1 parent 16cba5d commit afb8189

File tree

1 file changed

+16
-11
lines changed

1 file changed

+16
-11
lines changed

src/hermes/commands/harvest/codemeta.py

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
from hermes.commands.harvest.base import HermesHarvestCommand, HermesHarvestPlugin
1414
from hermes.commands.harvest.util.validate_codemeta import validate_codemeta
1515
from hermes.model.errors import HermesValidationError
16-
16+
from hermes.commands.harvest.util.remote_harvesting import normalize_url, fetch_metadata_from_repo
1717

1818
class CodeMetaHarvestPlugin(HermesHarvestPlugin):
1919
def __call__(self, command: HermesHarvestCommand) -> t.Tuple[t.Dict, t.Dict]:
@@ -56,13 +56,18 @@ def _validate(self, codemeta_file: pathlib.Path) -> bool:
5656
return True
5757

5858
def _get_single_codemeta(self, path: pathlib.Path) -> t.Optional[pathlib.Path]:
59-
# Find CodeMeta files in directories and subdirectories
60-
# TODO: Do we really want to search recursive? Maybe add another option to enable pointing to a single file?
61-
# (So this stays "convention over configuration")
62-
files = glob.glob(str(path / "**" / "codemeta.json"), recursive=True)
63-
if len(files) == 1:
64-
return pathlib.Path(files[0])
65-
# TODO: Shouldn't we log/echo the found CFF files so a user can debug/cleanup?
66-
# TODO: Do we want to hand down a logging instance via Hermes context or just encourage
67-
# peeps to use the Click context?
68-
return None
59+
if str(path).startswith("http:") or str(path).startswith("https:"):
60+
# Find CodeMeta files from the provided URL repository
61+
normalized_url = normalize_url(str(path))
62+
return fetch_metadata_from_repo(normalized_url, "codemeta.json")
63+
else:
64+
# Find CodeMeta files in directories and subdirectories
65+
# TODO: Do we really want to search recursive? Maybe add another option to enable pointing to a single file?
66+
# (So this stays "convention over configuration")
67+
files = glob.glob(str(path / "**" / "codemeta.json"), recursive=True)
68+
if len(files) == 1:
69+
return pathlib.Path(files[0])
70+
# TODO: Shouldn't we log/echo the found CFF files so a user can debug/cleanup?
71+
# TODO: Do we want to hand down a logging instance via Hermes context or just encourage
72+
# peeps to use the Click context?
73+
return None

0 commit comments

Comments
 (0)