Skip to content

Commit ed93fa8

Browse files
Merge pull request #3 from caltechlibrary/main
merge
2 parents 005d9cb + faa360a commit ed93fa8

File tree

9 files changed

+198
-105
lines changed

9 files changed

+198
-105
lines changed

.github/workflows/codemeta2cff.yml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
name: CodeMeta2CFF
2+
run-name: Run CodeMeta2CFF after ${{github.event_name}} by ${{github.actor}}
3+
4+
on:
5+
push:
6+
paths: ['codemeta.json']
7+
workflow_dispatch:
8+
inputs:
9+
reason:
10+
description: 'Reason'
11+
required: false
12+
default: 'Manual trigger'
13+
14+
jobs:
15+
CodeMeta2CFF:
16+
runs-on: ubuntu-latest
17+
steps:
18+
- name: Checkout
19+
uses: actions/checkout@v4
20+
- name: Convert CFF
21+
uses: caltechlibrary/codemeta2cff@main
22+
- name: Commit CFF
23+
uses: EndBug/add-and-commit@v9
24+
with:
25+
message: 'Add updated CITATION.cff from codemeta.json file'
26+
add: 'CITATION.cff'

.github/workflows/iga.yaml

Lines changed: 68 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
name: InvenioRDM GitHub Archiver and CodeMeta2CFF
21
env:
32
INVENIO_SERVER: https://data.caltech.edu
43

@@ -10,47 +9,51 @@ env:
109
parent_record: "6qhkm-7n074"
1110
debug: false
1211

13-
# ~~~~~~~~~~ The rest of this file should be left as-is ~~~~~~~~~~
12+
# This variable is a setting for post-archiving CodeMeta file updates.
13+
# If you don't have a CodeMeta file, you can remove the add_doi_codemeta
14+
# and Coremeta2CFF jobs at the bottom of this file.
15+
ref: main
16+
17+
# ╭────────────────────────────────────────────╮
18+
# │ The rest of this file should be left as-is │
19+
# ╰────────────────────────────────────────────╯
20+
21+
name: InvenioRDM GitHub Archiver
1422
on:
1523
release:
1624
types: [published]
1725
workflow_dispatch:
1826
inputs:
1927
release_tag:
20-
description: "The tag of the release to archive:"
28+
description: The release tag (empty = latest)
29+
parent_record:
30+
description: ID of parent record (for versioning)
31+
community:
32+
description: Name of InvenioRDM community (if any)
2133
draft:
22-
default: false
23-
description: "Mark the record as a draft:"
34+
description: Mark the record as a draft
35+
type: boolean
2436
all_assets:
25-
default: false
26-
description: "Attach all GitHub assets:"
37+
description: Attach all GitHub assets
38+
type: boolean
2739
all_metadata:
28-
default: false
29-
description: "Include additional GitHub metadata:"
30-
community:
31-
description: "Send record to InvenioRDM community:"
32-
parent_record:
33-
description: "ID of parent record (for versioning):"
40+
description: Include additional GitHub metadata
41+
type: boolean
42+
debug:
43+
description: Print debug info in the GitHub log
44+
type: boolean
45+
46+
run-name: Archive ${{inputs.release_tag || 'latest release'}} in InvenioRDM
3447
jobs:
35-
CodeMeta2CFF:
36-
runs-on: ubuntu-latest
37-
steps:
38-
- name: Checkout
39-
uses: actions/checkout@v4
40-
- name: Convert CFF
41-
uses: caltechlibrary/codemeta2cff@main
42-
- name: Commit CFF
43-
uses: EndBug/add-and-commit@v9
44-
with:
45-
message: 'Add CITATION.cff for release'
46-
add: "['CITATION.cff']"
47-
push: origin HEAD:main
4848
run_iga:
49-
name: "Send to ${{needs.get_repository.outputs.server}}"
49+
name: Send to ${{needs.get_repository.outputs.server}}
5050
runs-on: ubuntu-latest
51-
needs: [get_repository, CodeMeta2CFF]
51+
needs: get_repository
52+
outputs:
53+
record_doi: ${{steps.iga.outputs.record_doi}}
5254
steps:
53-
- uses: caltechlibrary/iga@main
55+
- uses: caltechlibrary/iga@v1
56+
id: iga
5457
with:
5558
INVENIO_SERVER: ${{env.INVENIO_SERVER}}
5659
INVENIO_TOKEN: ${{secrets.INVENIO_TOKEN}}
@@ -62,10 +65,44 @@ jobs:
6265
parent_record: ${{github.event.inputs.parent_record || env.parent_record}}
6366
release_tag: ${{github.event.inputs.release_tag || 'latest'}}
6467
get_repository:
65-
name: "Get repository name"
68+
name: Get repository name
6669
runs-on: ubuntu-latest
6770
outputs:
6871
server: ${{steps.parse.outputs.host}}
6972
steps:
70-
- id: parse
73+
- name: Extract name from INVENIO_SERVER
74+
id: parse
7175
run: echo "host=$(cut -d'/' -f3 <<< ${{env.INVENIO_SERVER}} | cut -d':' -f1)" >> $GITHUB_OUTPUT
76+
add_doi_codemeta:
77+
name: "Add ${{needs.run_iga.outputs.record_doi}} to codemeta.json"
78+
needs: run_iga
79+
runs-on: ubuntu-latest
80+
steps:
81+
- name: Checkout
82+
uses: actions/checkout@v4
83+
with:
84+
ref: ${{ env.ref }}
85+
- name: Install sde
86+
run: pip install sde
87+
- name: Add DOI to CodeMeta File
88+
run: sde identifier ${{needs.run_iga.outputs.record_doi}} codemeta.json
89+
- name: Commit CFF
90+
uses: EndBug/add-and-commit@v9
91+
with:
92+
message: 'Add DOI to codemeta.json file'
93+
add: 'codemeta.json'
94+
CodeMeta2CFF:
95+
runs-on: ubuntu-latest
96+
needs: add_doi_codemeta
97+
steps:
98+
- name: Checkout
99+
uses: actions/checkout@v4
100+
with:
101+
ref: ${{ env.ref }}
102+
- name: Convert CFF
103+
uses: caltechlibrary/codemeta2cff@main
104+
- name: Commit CFF
105+
uses: EndBug/add-and-commit@v9
106+
with:
107+
message: 'Add updated CITATION.cff from codemeta.json file'
108+
add: 'CITATION.cff'

CITATION.cff

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ authors:
1111
abstract: Python wrapper for CaltechDATA API.
1212
repository-code: "https://github.com/caltechlibrary/caltechdata_api"
1313
type: software
14-
version: 1.8.1
14+
version: 1.8.2
1515
license-url: "https://data.caltech.edu/license"
1616
keywords:
1717
- GitHub
1818
- metadata
1919
- software
2020
- InvenioRDM
21-
date-released: 2024-10-18
21+
date-released: 2024-11-06

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# CaltechDATA API Python Library
22

3+
[![DOI](https://img.shields.io/badge/dynamic/json.svg?label=DOI&query=$.pids.doi.identifier&uri=https://data.caltech.edu/api/records/wfjr5-kw507/versions/latest)](https://data.caltech.edu/records/wfjr5-kw507/latest)
4+
35
The `caltechdata_api` Python library provides a convenient interface for interacting with the CaltechDATA API. It allows users to write files, create DataCite 4 standard JSON records, edit existing records, and retrieve metadata from the CaltechDATA repository.
46

57
## Features

caltechdata_api/cli.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,11 @@ def get_or_set_token(production=True):
7171
with open(token_file, "rb") as f:
7272
encrypted_token = f.read()
7373
token = decrypt_token(encrypted_token, key)
74+
print(
75+
"Using saved CaltechDATA production token."
76+
if production
77+
else "Using saved CaltechDATA test token."
78+
)
7479
return token
7580
except FileNotFoundError:
7681
while True:
@@ -422,8 +427,6 @@ def main():
422427

423428
def create_record(production):
424429
token = get_or_set_token(production)
425-
# keep_file = input("Do you want to keep your existing files? (yes/no): ").lower() == "yes"
426-
print("Using CaltechDATA token:", token)
427430
while True:
428431
choice = get_user_input(
429432
"Do you want to use metadata from an existing file or create new metadata? (existing/create): "

caltechdata_api/customize_schema.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
# Convert a DataCite 4 or 4.3 standard schema json record to the customized internal
2-
# schema used by TIND in CaltechDATA
1+
# Convert a DataCite 4.3 standard schema json record to the InvenioRDM schema
32
import argparse
43
import json
54
from datetime import date

caltechdata_api/get_metadata.py

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,26 +8,43 @@
88

99

1010
def get_metadata(
11-
idv, production=True, validate=True, emails=False, schema="43", token=False
11+
idv,
12+
production=True,
13+
validate=True,
14+
emails=False,
15+
schema="43",
16+
token=False,
17+
authors=False,
1218
):
1319
# Returns just DataCite metadata or DataCite metadata with emails
1420

1521
if production == True:
16-
url = "https://data.caltech.edu/api/records/"
22+
if authors:
23+
url = "https://authors.library.caltech.edu/api/records/"
24+
else:
25+
url = "https://data.caltech.edu/api/records/"
1726
verify = True
1827
else:
19-
url = "https://data.caltechlibrary.dev/api/records/"
28+
if authors:
29+
url = "https://authors.caltechlibrary.dev/api/records/"
30+
else:
31+
url = "https://data.caltechlibrary.dev/api/records/"
2032
verify = True
2133

22-
headers = {
23-
"accept": "application/vnd.datacite.datacite+json",
24-
}
34+
if authors:
35+
headers = {
36+
"accept": "application/json",
37+
}
38+
validate = False
39+
else:
40+
headers = {
41+
"accept": "application/vnd.datacite.datacite+json",
42+
}
2543

2644
if token:
2745
headers["Authorization"] = "Bearer %s" % token
2846

2947
response = requests.get(url + idv, headers=headers, verify=verify)
30-
print(response.headers)
3148
if response.status_code != 200:
3249
raise Exception(response.text)
3350
else:
@@ -59,6 +76,7 @@ def get_metadata(
5976
help="The CaltechDATA ID for each record of interest",
6077
)
6178
parser.add_argument("-test", dest="production", action="store_false")
79+
parser.add_argument("-authors", dest="authors", action="store_true")
6280
parser.add_argument("-xml", dest="save_xml", action="store_true")
6381
parser.add_argument(
6482
"-skip_validate",
@@ -72,14 +90,17 @@ def get_metadata(
7290

7391
production = args.production
7492
schema = args.schema
93+
authors = args.authors
7594
skip_validate = args.skip_validate
7695
if skip_validate:
7796
validate = False
7897
else:
7998
validate = True
8099

81100
for idv in args.ids:
82-
metadata = get_metadata(idv, production, validate, schema)
101+
metadata = get_metadata(
102+
idv, production, validate, schema=schema, authors=authors
103+
)
83104
outfile = open(str(idv) + ".json", "w")
84105
outfile.write(json.dumps(metadata, indent=4))
85106
outfile.close()

0 commit comments

Comments
 (0)