55from models .codemeta .v3_1 .codemeta_pydantic import Software
66from crosswalks .codemeta_to_citation_cff import get_citation_file_format_from_codemeta_software , get_pydantic_model_from_dict
77import sys
8+ import subprocess
89
910status = 1
1011
12+ 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 )
20+
21+ return ret
22+
1123def convert (codemeta_path : str ):
1224 # codemeta_path = 'tests/data/in/codemeta-codemeta-3.0.json'
1325 # codemeta_path = 'tests/data/in/codemeta-isicily.json'
@@ -21,7 +33,7 @@ def convert(codemeta_path: str):
2133 with open (codemeta_path , 'r' ) as f :
2234 codemeta_data = json .load (f )
2335 except Exception as e :
24- print (f'ERROR: { e } ' , sys .stderr )
36+ print (f'ERROR: { e } ' , file = sys .stderr )
2537
2638 if codemeta_data :
2739 codemeta_software = get_pydantic_model_from_dict (codemeta_data , Software )
@@ -30,8 +42,11 @@ def convert(codemeta_path: str):
3042 citation_cff = get_citation_file_format_from_codemeta_software (codemeta_software )
3143
3244 if citation_cff :
33- print (to_yaml_str (citation_cff , exclude_none = True ))
34- ret = 0
45+ citation_cff_yaml_str = to_yaml_str (citation_cff , exclude_none = True )
46+ print (citation_cff_yaml_str )
47+
48+ if validate_cff (citation_cff_yaml_str ):
49+ ret = 0
3550
3651 return ret
3752
0 commit comments