Skip to content

Commit 9e65d95

Browse files
committed
merge
2 parents c15066e + d0c7d6d commit 9e65d95

11 files changed

Lines changed: 448 additions & 111 deletions

File tree

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
"""Sync package metadata from codemeta.json into pyproject.toml.
2+
3+
Run by the CodeMeta2CFF workflow whenever codemeta.json changes. tomlkit is used
4+
rather than a plain rewrite so that comments, key order, and formatting in
5+
pyproject.toml survive the update.
6+
"""
7+
8+
import json
9+
10+
import tomlkit
11+
12+
CODEMETA = "codemeta.json"
13+
PYPROJECT = "pyproject.toml"
14+
15+
16+
def people(entries):
17+
"""Convert codemeta Person entries into PEP 621 name/email tables."""
18+
if isinstance(entries, dict):
19+
entries = [entries]
20+
array = tomlkit.array().multiline(True)
21+
for person in entries or []:
22+
names = (person.get("givenName"), person.get("familyName"))
23+
name = " ".join(part for part in names if part)
24+
if not name:
25+
continue
26+
entry = tomlkit.inline_table()
27+
entry["name"] = name
28+
if person.get("email"):
29+
entry["email"] = person["email"]
30+
array.append(entry)
31+
return array
32+
33+
34+
def main():
35+
with open(CODEMETA) as handle:
36+
codemeta = json.load(handle)
37+
38+
with open(PYPROJECT) as handle:
39+
document = tomlkit.parse(handle.read())
40+
41+
project = document["project"]
42+
43+
for key in ("name", "version", "description"):
44+
if codemeta.get(key):
45+
project[key] = codemeta[key]
46+
47+
for key, source in (("authors", "author"), ("maintainers", "maintainer")):
48+
values = people(codemeta.get(source))
49+
if len(values):
50+
project[key] = values
51+
52+
urls = project.get("urls")
53+
if urls is not None:
54+
repository = codemeta.get("codeRepository") or codemeta.get("url")
55+
if repository:
56+
urls["Homepage"] = repository
57+
urls["Repository"] = repository
58+
if codemeta.get("issueTracker"):
59+
urls["Issues"] = codemeta["issueTracker"]
60+
61+
with open(PYPROJECT, "w") as handle:
62+
handle.write(tomlkit.dumps(document))
63+
64+
65+
if __name__ == "__main__":
66+
main()

‎.github/workflows/bot.yaml‎

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,34 +5,25 @@ on: [push, pull_request]
55
jobs:
66
validate-metadata:
77
runs-on: ubuntu-latest
8-
8+
99
steps:
1010
- uses: actions/checkout@v7
1111
with:
1212
fetch-depth: 0
13-
14-
- name: Set up Python
15-
uses: actions/setup-python@v7
13+
14+
- name: Install uv
15+
uses: astral-sh/setup-uv@v7
1616
with:
17-
python-version: '3.x'
18-
19-
- name: Install dependencies
20-
run: |
21-
python -m pip install --upgrade pip
22-
pip install pytest requests s3fs cryptography
23-
pip install .
17+
python-version: "3.14"
2418

2519
- name: Run against CaltechData Test system
2620
env:
2721
RDMTOK: ${{ secrets.CALTECHDATA_TOKEN }}
2822
run: |
29-
cd tests
30-
pytest test_unit.py
31-
pytest test_rdm.py
23+
uv run pytest tests/test_unit.py
24+
uv run pytest tests/test_rdm.py
25+
3226
- name: Run Medata Validation Test and RDM
3327
env:
3428
RDMTOK: ${{ secrets.CALTECHDATA_TOKEN }}
35-
run: |
36-
cd tests
37-
python bot_yaml.py
38-
29+
run: uv run python tests/bot_yaml.py

‎.github/workflows/codemeta2cff.yml‎

Lines changed: 8 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -19,27 +19,14 @@ jobs:
1919
uses: actions/checkout@v7
2020
- name: Convert CFF
2121
uses: caltechlibrary/codemeta2cff@main
22-
- name: Install jq for JSON parsing
23-
run: sudo apt-get install -y jq
24-
- name: Parse and update setup.cfg
25-
run: |
26-
# Extract values from codemeta.json
27-
NAME=$(jq -r '.name' codemeta.json)
28-
VERSION=$(jq -r '.version' codemeta.json)
29-
AUTHORS=$(jq -r '[.author[] | .givenName + " " + .familyName] | join(", ")' codemeta.json)
30-
AUTHOR_EMAILS=$(jq -r '[.author[] | .email // empty] | join(", ")' codemeta.json)
31-
DESCRIPTION=$(jq -r '.description' codemeta.json)
32-
URL=$(jq -r '.codeRepository // .url' codemeta.json)
33-
34-
# Update setup.cfg fields
35-
sed -i "s/^name = .*/name = $NAME/" setup.cfg
36-
sed -i "s/^version = .*/version = $VERSION/" setup.cfg
37-
sed -i "s/^author = .*/author = $AUTHORS/" setup.cfg
38-
sed -i "s/^author_email = .*/author_email = $AUTHOR_EMAILS/" setup.cfg
39-
sed -i "s/^description = .*/description = $DESCRIPTION/" setup.cfg
40-
sed -i "s|^url = .*|url = $URL|" setup.cfg
22+
- name: Install uv
23+
uses: astral-sh/setup-uv@v7
24+
with:
25+
python-version: "3.14"
26+
- name: Update pyproject.toml from codemeta.json
27+
run: uv run --no-project --with tomlkit python .github/scripts/codemeta_to_pyproject.py
4128
- name: Commit CFF
4229
uses: EndBug/add-and-commit@v11
4330
with:
44-
message: 'Add updated CITATION.cff and setup.cfg from codemeta.json file'
45-
add: '["setup.cfg", "CITATION.cff"]'
31+
message: 'Add updated CITATION.cff and pyproject.toml from codemeta.json file'
32+
add: '["pyproject.toml", "CITATION.cff"]'

‎.github/workflows/pypi-publish.yaml‎

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,12 @@ jobs:
1010
runs-on: ubuntu-latest
1111
steps:
1212
- uses: actions/checkout@v7
13-
- name: Set up Python 3.9
14-
uses: actions/setup-python@v7
13+
- name: Install uv
14+
uses: astral-sh/setup-uv@v7
1515
with:
16-
python-version: 3.9
17-
- name: Install dependencies
18-
run: |
19-
python -m pip install --upgrade pip
20-
pip install setuptools wheel
16+
python-version: "3.14"
2117
- name: Build package
22-
run: |
23-
python setup.py sdist bdist_wheel
18+
run: uv build
2419
- name: Publish
2520
uses: pypa/gh-action-pypi-publish@v1.14.2
2621
with:

‎.gitignore‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
build/
22
dist/
33
data/
4-
caltechdata_api.egg-info/
5-
caltechdata_api/__pycache__/
6-
tests/__pycache__/
4+
*.egg-info/
5+
__pycache__/
6+
.pytest_cache/
7+
.venv/

‎README.md‎

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ The `caltechdata_api` Python library provides a convenient interface for interac
1515

1616
## Requirements
1717

18-
- Python 3.6+
18+
- Python 3.9+
1919

2020
## Installation
2121

@@ -25,14 +25,26 @@ Install the library via pip:
2525
pip install caltechdata_api
2626
```
2727

28+
Or add it to a [uv](https://docs.astral.sh/uv/) project:
29+
30+
```shell
31+
uv add caltechdata_api
32+
```
33+
34+
You can also run a script using uv:
35+
36+
```shell
37+
uv run write.py
38+
```
39+
2840
## Examples
2941

3042
There are some example python scripts in the GitHub repository.
3143

3244
### Create a record:
3345

3446
```shell
35-
python write.py example.json -fnames logo.gif
47+
uv run write.py example.json -fnames logo.gif
3648
# Output: pbkn6-m9y63 (unique identifier)
3749
```
3850
> The response will be the unique identifier for the record. You can put this at
@@ -42,7 +54,7 @@ https://data.caltechlibrary.dev/records/pbkn6-m9y63)
4254
### Edit a record
4355
Make changes to the example.json file to see a change)
4456
```
45-
python edit.py example.json -id pbkn6-m9y63
57+
uv run edit.py example.json -id pbkn6-m9y63
4658
10.33569/pbkn6-m9y63
4759
```
4860
> The response is the DOI for the record, which includes the unique identifier
@@ -53,13 +65,13 @@ Some groups have worked with the library to create custom DOIs. These can be
5365
passed in the metadata like:
5466

5567
```shell
56-
python write.py example_custom.json -fnames logo.gif
68+
uv run write.py example_custom.json -fnames logo.gif
5769
m6zxz-p4j22
5870
```
5971

6072
And then you can edit with
6173
```
62-
python edit.py example_custom.json -id m6zxz-p4j22
74+
uv run edit.py example_custom.json -id m6zxz-p4j22
6375
10.5281/inveniordm.1234
6476
```
6577

0 commit comments

Comments
 (0)