Skip to content

Commit 7a8ed50

Browse files
committed
fix: convert override kwargs
1 parent a4e60c2 commit 7a8ed50

File tree

3 files changed

+89
-72
lines changed

3 files changed

+89
-72
lines changed

codemeticulous/cff/convert.py

Lines changed: 36 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -219,34 +219,42 @@ def canonical_to_cff(data: CanonicalCodeMeta, **custom_fields) -> CitationFileFo
219219
licenses, license_urls = codemeta_license_to_cff(data.license)
220220
primary_doi = extract_doi_from_identifier(data.identifier)
221221
return CitationFileFormat(
222-
cff_version="1.2.0",
223-
message="If you use this software, please cite it using the metadata from this file.",
224-
abstract=data.description,
225-
authors=codemeta_actors_to_cff(data.author),
226-
date_released=(
227-
data.datePublished.date()
228-
if isinstance(data.datePublished, datetime)
229-
else data.datePublished
230-
),
231-
doi=primary_doi,
232-
identifiers=extract_identifiers_from_codemeta(data, primary_doi=primary_doi),
233-
keywords=ensure_list(data.keywords) or None,
234-
license=get_first_if_single_list(licenses) or None,
235-
license_url=get_first_if_single_list(license_urls) or None,
236-
# we cannot confidently say anything in citation should be the preferred-citation
237-
preferred_citation=None,
238-
references=codemeta_references_to_cff(data.citation, data.softwareRequirements),
239-
# repository or repository-artifact could be in codemeta url, downloadUrl, installUrl,
240-
# or relatedLink, but the semantics do not match up, so there is no reliable way to
241-
# extract this information
242-
repository=None,
243-
repository_artifact=None,
244-
repository_code=data.codeRepository,
245-
title=data.name,
246-
type="software",
247-
url=extract_main_url_from_codemeta(data),
248-
version=data.version,
249-
**custom_fields,
222+
**{
223+
**dict(
224+
cff_version="1.2.0",
225+
message="If you use this software, please cite it using the metadata from this file.",
226+
abstract=data.description,
227+
authors=codemeta_actors_to_cff(data.author),
228+
date_released=(
229+
data.datePublished.date()
230+
if isinstance(data.datePublished, datetime)
231+
else data.datePublished
232+
),
233+
doi=primary_doi,
234+
identifiers=extract_identifiers_from_codemeta(
235+
data, primary_doi=primary_doi
236+
),
237+
keywords=ensure_list(data.keywords) or None,
238+
license=get_first_if_single_list(licenses) or None,
239+
license_url=get_first_if_single_list(license_urls) or None,
240+
# we cannot confidently say anything in citation should be the preferred-citation
241+
preferred_citation=None,
242+
references=codemeta_references_to_cff(
243+
data.citation, data.softwareRequirements
244+
),
245+
# repository or repository-artifact could be in codemeta url, downloadUrl, installUrl,
246+
# or relatedLink, but the semantics do not match up, so there is no reliable way to
247+
# extract this information
248+
repository=None,
249+
repository_artifact=None,
250+
repository_code=data.codeRepository,
251+
title=data.name,
252+
type="software",
253+
url=extract_main_url_from_codemeta(data),
254+
version=data.version,
255+
),
256+
**custom_fields,
257+
}
250258
)
251259

252260

codemeticulous/codemeta/convert.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44

55
def canonical_to_codemeta(data: CanonicalCodeMeta, **custom_fields) -> CodeMeta:
6-
return CodeMeta(**data.dict(), **custom_fields)
6+
return CodeMeta(**{**data.dict(), **custom_fields})
77

88

99
def codemeta_to_canonical(data: CodeMeta) -> CanonicalCodeMeta:

codemeticulous/datacite/convert.py

Lines changed: 52 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -341,49 +341,58 @@ def canonical_to_datacite(
341341
]
342342
)
343343
return DataCite(
344-
doi=primary_doi,
345-
prefix=doi_prefix,
346-
suffix=doi_suffix,
347-
url=get_first_if_list(data.url),
348-
types=Types(
349-
resourceType=data.applicationCategory, resourceTypeGeneral="Software"
350-
),
351-
creators=codemeta_actors_to_datacite(data.author, Creator),
352-
titles=[Title(title=data.name)],
353-
publisher=get_first_if_list(
354-
codemeta_actors_to_datacite(data.publisher, Publisher)
355-
),
356-
publicationYear=str(data.datePublished.year) if data.datePublished else None,
357-
subjects=[Subject(subject=subject) for subject in ensure_list(data.keywords)]
358-
or None,
359-
contributors=codemeta_actors_to_datacite(data.contributor, Contributor),
360-
dates=[
361-
DateModel(
362-
date=date.date() if isinstance(date, datetime) else date,
363-
dateType=date_type,
364-
)
365-
for date, date_type in [
366-
(data.dateCreated, "Created"),
367-
(data.dateModified, "Updated"),
368-
]
369-
if date is not None
370-
],
371-
# we have no way of knowing what the relationships are for relatedLinks since
372-
# they are just urls
373-
# TODO: though, it may be possible to use the following codemeta fields:
374-
# hasPart, isPartOf, readme, sameAs, review, releaseNotes
375-
# relatedIdentifiers=data.relatedLink,
376-
sizes=[data.fileSize] if data.fileSize else None,
377-
formats=codemeta_language_fileformat_to_datacite_format(
378-
data.programmingLanguage, data.fileFormat
379-
),
380-
version=str(data.version) if data.version else None,
381-
rightsList=codemeta_license_to_datacite_rights(data.license),
382-
descriptions=descriptions,
383-
# codemeta.funding is a plain string, can't really ensure that the string
384-
# is the required name field
385-
# fundingReferences=None,
386-
**custom_fields,
344+
**{
345+
**dict(
346+
doi=primary_doi,
347+
prefix=doi_prefix,
348+
suffix=doi_suffix,
349+
url=get_first_if_list(data.url),
350+
types=Types(
351+
resourceType=data.applicationCategory,
352+
resourceTypeGeneral="Software",
353+
),
354+
creators=codemeta_actors_to_datacite(data.author, Creator),
355+
titles=[Title(title=data.name)],
356+
publisher=get_first_if_list(
357+
codemeta_actors_to_datacite(data.publisher, Publisher)
358+
),
359+
publicationYear=(
360+
str(data.datePublished.year) if data.datePublished else None
361+
),
362+
subjects=[
363+
Subject(subject=subject) for subject in ensure_list(data.keywords)
364+
]
365+
or None,
366+
contributors=codemeta_actors_to_datacite(data.contributor, Contributor),
367+
dates=[
368+
DateModel(
369+
date=date.date() if isinstance(date, datetime) else date,
370+
dateType=date_type,
371+
)
372+
for date, date_type in [
373+
(data.dateCreated, "Created"),
374+
(data.dateModified, "Updated"),
375+
]
376+
if date is not None
377+
],
378+
# we have no way of knowing what the relationships are for relatedLinks since
379+
# they are just urls
380+
# TODO: though, it may be possible to use the following codemeta fields:
381+
# hasPart, isPartOf, readme, sameAs, review, releaseNotes
382+
# relatedIdentifiers=data.relatedLink,
383+
sizes=[data.fileSize] if data.fileSize else None,
384+
formats=codemeta_language_fileformat_to_datacite_format(
385+
data.programmingLanguage, data.fileFormat
386+
),
387+
version=str(data.version) if data.version else None,
388+
rightsList=codemeta_license_to_datacite_rights(data.license),
389+
descriptions=descriptions,
390+
# codemeta.funding is a plain string, can't really ensure that the string
391+
# is the required name field
392+
# fundingReferences=None,
393+
),
394+
**custom_fields,
395+
}
387396
)
388397

389398

0 commit comments

Comments
 (0)