Skip to content

Commit 703cdfe

Browse files
committed
Improved Zenodo Sync
1 parent c0815b3 commit 703cdfe

File tree

4 files changed

+27
-6
lines changed

4 files changed

+27
-6
lines changed

docs/advanced_topics/sync_zenodo.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ metadata:
3737
keywords:
3838
- keyword1
3939
- keyword2
40-
license: cc-by-nc-4.0
40+
license:
41+
- cc-by-nc-4.0
4142
resource_type: dataset
4243
publisher: 'Publisher name'
4344
creators:
@@ -151,9 +152,11 @@ Documentation of the fields in the `zenodo.yaml` configuration file:
151152
(Optional)
152153

153154
- `license`:
154-
Lowercase license SPDX identifier.
155+
A list of license SPDX identifier (will be converted to lowercase).
155156
The list of licenses supported by Zenodo (and their identifiers)
156157
can be found in [SPDX License list](https://spdx.org/licenses/).
158+
When specifying multiple licenses, it is recommended to clarify in the Zenodo readme
159+
how the different licenses apply to different parts of the dataset.
157160

158161
- `resource_type`
159162
Select one of:

docs/changelog.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,13 @@ and this project adheres to [Effort-based Versioning](https://jacobtomlinson.dev
1515
### Added
1616

1717
- Verbose option for [`sync_zenodo()`][stepup.reprep.api.sync_zenodo]
18+
- Allow overriding `path_token` in [`sync_zenodo()`][stepup.reprep.api.sync_zenodo]
19+
with the `REPREP_PATH_ZENODO_TOKEN` environment variable.
20+
- Add support for multiple licenses in [`sync_zenodo()`][stepup.reprep.api.sync_zenodo].
21+
22+
### Fixed
23+
24+
- Fix Zenodo draft publication REST API.
1825

1926
## [3.1.3][] - 2025-09-28 {: v3.1.3 }
2027

stepup/reprep/sync_zenodo.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@
6767
from path import Path
6868
from rich import print # noqa: A004
6969

70-
from stepup.core.api import amend
70+
from stepup.core.api import amend, getenv
7171

7272

7373
class RESTError(Exception):
@@ -490,6 +490,12 @@ def to_zenodo(self) -> dict[str, Any]:
490490
}
491491

492492

493+
def _convert_license(arg):
494+
if isinstance(arg, str):
495+
arg = [arg]
496+
return [lic.lower() for lic in arg]
497+
498+
493499
@attrs.define
494500
class Metadata:
495501
"""A subset of Invenio RDM metadata.
@@ -499,7 +505,7 @@ class Metadata:
499505

500506
title: str = attrs.field(validator=attrs.validators.min_len(1))
501507
version: str = attrs.field()
502-
license: str = attrs.field(converter=lambda s: s.strip().lower())
508+
license: str | list[str] = attrs.field(converter=_convert_license)
503509
resource_type: str = attrs.field(validator=attrs.validators.in_(RESOURCE_TYPES))
504510
copyright: str | None = attrs.field(default=None)
505511
publisher: str | None = attrs.field(default=None)
@@ -514,7 +520,7 @@ def to_zenodo(self) -> dict[str, Any]:
514520
data = {
515521
"title": self.title,
516522
"version": self.version,
517-
"rights": [{"id": self.license}],
523+
"rights": [{"id": lic} for lic in self.license],
518524
"resource_type": {"id": self.resource_type},
519525
"creators": [creator.to_zenodo() for creator in self.creators],
520526
"description": self.description,
@@ -608,7 +614,7 @@ def edit_record(self, rid: int):
608614

609615
def publish_record(self, rid: int):
610616
"""Publish are draft record or a record in edit mode."""
611-
self.rest.post(f"records/{rid}/actions/publish")
617+
self.rest.post(f"records/{rid}/draft/actions/publish")
612618

613619
def start_uploads(self, rid: int, paths: list[Path]):
614620
self.rest.post(f"records/{rid}/draft/files", json=[{"key": path.name} for path in paths])
@@ -676,6 +682,10 @@ def sync_zenodo_tool(args: argparse.Namespace) -> int:
676682
for line in cattrs.transform_error(exc, repr(args.config)):
677683
print(line)
678684
raise
685+
# Override the token path from the config file if the environment variable is set.
686+
path_token = getenv("REPREP_PATH_ZENODO_TOKEN")
687+
if path_token is not None:
688+
config.path_token = path_token
679689
if args.clean:
680690
clean_online(config, args.verbose)
681691
update_online(config, args.verbose)

tests/examples/sync_zenodo/expected_graph.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ file:zenodo.yaml
5050

5151
step:sync-zenodo zenodo.yaml
5252
state = SUCCEEDED
53+
env_var = REPREP_PATH_ZENODO_TOKEN [amended]
5354
created by step:runpy ./plan.py
5455
consumes file:./
5556
consumes file:README.txt [amended]

0 commit comments

Comments
 (0)