Skip to content

Commit 8058b35

Browse files
fix: generated CITATION.cff now uses - instead of _ which was invalid. Also validating with cffconvert without subprocess.
1 parent 7aaff77 commit 8058b35

2 files changed

Lines changed: 24 additions & 16 deletions

File tree

codemeta_convert.py

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,30 @@
1-
# Code by Brave AI
1+
import json
2+
import sys
3+
4+
from cffconvert import Citation
25
from pydantic import ValidationError
36
from pydantic_yaml import to_yaml_str
4-
import json
7+
8+
from crosswalks.codemeta_to_citation_cff import (
9+
get_citation_file_format_from_codemeta_software,
10+
get_pydantic_model_from_dict,
11+
)
512
from models.codemeta.v3_1.codemeta_pydantic import Software
6-
from crosswalks.codemeta_to_citation_cff import get_citation_file_format_from_codemeta_software, get_pydantic_model_from_dict
7-
import sys
8-
import subprocess
913

1014
status = 1
1115

1216
def validate_cff(citation_cff_yaml_str):
13-
# Assuming the CITATION.cff file is in the current directory
14-
result = subprocess.run(["cffconvert", "--validate"], capture_output=True, text=True)
15-
16-
ret = result.returncode == 0
17-
18-
if not ret:
19-
print("ERROR: cffconvert validation failed.", result.stderr, file=sys.stderr)
17+
ret = False
18+
try:
19+
# Initialize the Citation object with raw text instead of a file path
20+
citation = Citation(cffstr=citation_cff_yaml_str)
21+
22+
# Run the built-in validation check
23+
citation.validate()
24+
25+
ret = True
26+
except Exception as e:
27+
print(f"ERROR: cffconvert error occurred during parsing: {e}", file=sys.stderr)
2028

2129
return ret
2230

@@ -42,7 +50,7 @@ def convert(codemeta_path: str):
4250
citation_cff = get_citation_file_format_from_codemeta_software(codemeta_software)
4351

4452
if citation_cff:
45-
citation_cff_yaml_str = to_yaml_str(citation_cff, exclude_none=True)
53+
citation_cff_yaml_str = to_yaml_str(citation_cff, by_alias=True, exclude_none=True)
4654
print(citation_cff_yaml_str)
4755

4856
if validate_cff(citation_cff_yaml_str):

crosswalks/codemeta_to_citation_cff.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -144,14 +144,14 @@ def get_citation_file_format_from_codemeta_software(codemeta_software: cm.Softwa
144144
soft = codemeta_software
145145

146146
cff_data = {
147-
"authors": [get_cff_agent(a) for a in soft.author or []],
147+
"version": get_cff_version(soft),
148148
"title": soft.name,
149-
"repository-code": soft.codeRepository,
150149
"type": get_cff_type(soft.type_),
150+
"authors": [get_cff_agent(a) for a in soft.author or []],
151151
"abstract": soft.description,
152152
"keywords": soft.keywords,
153-
"version": get_cff_version(soft),
154153
"date-released": soft.datePublished,
154+
"repository-code": soft.codeRepository,
155155
"repository-artifact": soft.downloadUrl,
156156
}
157157

0 commit comments

Comments
 (0)