Add section using git-annex-remote-zenodo to Third Party chapter #941

Open
opened 2023-04-18 08:01:54 +00:00 by adswa · 3 comments
adswa commented 2023-04-18 08:01:54 +00:00 (Migrated from github.com)

The question whether one can publish datalad datasets to Zenodo came up in the office hour chatroom. We found a resource by CONP which did not deal with annexed contents on first read, and a dedicated git-annex special remote for Zenodo that none of us yet tried.
Content-wise, a section describing a workflow to publish to Zenodo with these tools could fit into the third-party sharing chapter.

The question whether one can publish datalad datasets to Zenodo came up in the office hour chatroom. We found a [resource by CONP]( https://portal.conp.ca/share#datalad) which did not deal with annexed contents on first read, and a dedicated [git-annex special remote for Zenodo](https://github.com/alegrand/git-annex-remote-zenodo) that none of us yet tried. Content-wise, a section describing a workflow to publish to Zenodo with these tools could fit into the third-party sharing chapter.
adswa commented 2023-04-21 13:34:53 +00:00 (Migrated from github.com)

I have started to look into how this could be done. Currently, its not very convenient, and half-way broken. With the tutorial and a few fixes I got it to a state where you can push files to zenodo, and retrieve them back, but only in one and same dataset:

For anyone who wants to repeat my steps:

  1. Clone https://github.com/alegrand/git-annex-remote-zenodo
  2. Ensure that the file git-annex-remote-zenodo is executable: chmod +x git-annex-remote-zenodo
  3. Add it to PATH: export PATH=$PATH:$(pwd)
  4. Go to Zenodo and create yourself a token with account-wide permissions: https://zenodo.org/account/settings/applications/tokens/new/

image

  1. apply the following fixes to the special remote source code
diff --git a/git-annex-remote-zenodo b/git-annex-remote-zenodo
index 965f6cb..c316042 100755
--- a/git-annex-remote-zenodo
+++ b/git-annex-remote-zenodo
@@ -143,10 +142,10 @@ class ZenodoRemote(ExportRemote):
         # getting the url of the remote (Zenodo or Sandbox)
         # the user would need the key for both of them and it's created on the website of the one they chose
         url = self.annex.getconfig('url') 
-        if url is None:
-            self.url = 'https://zenodo.org/api/deposit/depositions'
-        else:
+        if url == 'sandbox':
             self.url = 'https://sandbox.zenodo.org/api/deposit/depositions'
+        else:
+            self.url = 'https://zenodo.org/api/deposit/depositions'
 
         # the key is passed as an argument when using the commant initremote (ex: key='')
         # if it's not been added as an argument, we raise an 
@@ -189,11 +188,11 @@ class ZenodoRemote(ExportRemote):
         # let's try to connect to the API, if the status code is not 200: there is an error 
         self.key = self.annex.getconfig('key')
         url = self.annex.getconfig('url')
-        if url is None:
-            self.url = 'https://zenodo.org/api/deposit/depositions'
-        else:
+        if url == 'sandbox':
             self.url = 'https://sandbox.zenodo.org/api/deposit/depositions'
-        
+        else:
+            self.url = 'https://zenodo.org/api/deposit/depositions'

then, you can use it to create a Zenodo deposit, push data there, and retrieve it back:

(handbook) adina@muninn in /tmp
❱ datalad create my-zenodo-deposit
create(ok): /tmp/my-zenodo-deposit (dataset)
(handbook) adina@muninn in /tmp
❱ cd my-zenodo-deposit 
(handbook) adina@muninn in /tmp/my-zenodo-deposit on git:master
❱ echo 12345 > file
(handbook) adina@muninn in /tmp/my-zenodo-deposit on git:master
❱ datalad save
add(ok): file (file)                                                                                              
save(ok): . (dataset)                                                                                             
action summary:                                                                                                   
  add (ok: 1)
  save (ok: 1)
(handbook) adina@muninn in /tmp/my-zenodo-deposit on git:master
❱ git annex initremote zenodo type=external externaltype=zenodo key=FPnuCDH1TjYeQbK5h1tWhK2ReR3udRmiubE3Wazf2kuk7gwFZfdit1S6pnry encryption=none url=None
initremote zenodo <Response [201]>

  ------------ git-annex-remote-zenodo------------

  Finished initializing a Zenodo remote successfully.

  ------------------------------------------------
ok
(recording state in git...)
(handbook) adina@muninn in /tmp/my-zenodo-deposit on git:master
❱ datalad create-sibling-github my-zenodo-deposit --publish-depends zenodo --access-protocol ssh
create_sibling_github(ok): [sibling repository 'github' created at https://github.com/adswa/my-zenodo-deposit]
[INFO   ] Configure additional publication dependency on "zenodo" 
configure-sibling(ok): . (sibling)
action summary:
  configure-sibling (ok: 1)
  create_sibling_github (ok: 1)
datalad push --to github
copy(ok): my-file (file) [to zenodo-test...]     
publish(ok): . (dataset) [refs/heads/master->github:refs/heads/master [new branch]]                               
publish(ok): . (dataset) [refs/heads/git-annex->github:refs/heads/git-annex [new branch]]                         
                                                                                                                 action summary:     
                                                                                           
  publish (ok: 2)
  copy (ok: 1)
(handbook) adina@muninn in /tmp/zenodo on git:master
❱ datalad drop file
drop(ok): file (file)
(handbook) adina@muninn in /tmp/zenodo on git:master
❱ datalad get file
get(ok): file (file) [from zenodo...]               

The special remote does not publish zenodo records, you can find them as untitled drafts in your account and edit their metadata:

image
Be a bit careful here, if you publish something you can't delete it yourself. If you use url=sandbox in initremote and a token from sandbox.zenodo.org, you can test in a sandbox:

image

Things then fall apart quite quickly when I want to enable the remote in a clone.

(handbook) adina@muninn in /tmp
 ❱ datalad clone git@github.com:adswa/my-zenodo-deposit.git retrieval-from-zenodo                              1 !
[INFO   ] Unable to parse git config from origin                                                                  
[INFO   ] Remote origin does not have git-annex installed; setting annex-ignore                                   
[INFO   ] This could be a problem with the git-annex installation on the remote. Please make sure that git-annex-shell is available in PATH when you ssh into the remote. Once you have fixed the git-annex installation, run: git annex enableremote origin 
[INFO   ] access to 1 dataset sibling zenodo not auto-enabled, enable with:
| 		datalad siblings -d "/tmp/retrieval-from-zenodo" enable -s zenodo 
install(ok): /tmp/retrieval-from-zenodo (dataset)
(handbook) adina@muninn in /tmp
❱ cd retrieval-from-zenodo 
(handbook) adina@muninn in /tmp/retrieval-from-zenodo on git:master
❱ datalad siblings -d "/tmp/retrieval-from-zenodo" enable -s zenodo 
.: zenodo(?) [git]
❱ datalad get file
get(error): file (file) [Verification of content failed]  

I have investigated this a bit, and it seems like this enableremote triggers an initremote in the specialremote with a completly new deposition id - instead of finding the former deposit, it creates a new one.

I think the deposition ID needs to be recorded in the special remote to later get enabled. But I ran out of time, and will leave this investigation for the next time or person.
Sadly, the git repository the special remote implementation lives in does not have an issue tracker enabled.

I have started to look into how this could be done. Currently, its not very convenient, and half-way broken. With the [tutorial](https://github.com/alegrand/git-annex-remote-zenodo/blob/main/walkthrough.org) and a few fixes I got it to a state where you can push files to zenodo, and retrieve them back, but only in one and same dataset: For anyone who wants to repeat my steps: 1. Clone https://github.com/alegrand/git-annex-remote-zenodo 2. Ensure that the file ``git-annex-remote-zenodo`` is executable: ``chmod +x git-annex-remote-zenodo`` 3. Add it to ``PATH``: ``export PATH=$PATH:$(pwd)`` 4. Go to Zenodo and create yourself a token with account-wide permissions: https://zenodo.org/account/settings/applications/tokens/new/ ![image](https://user-images.githubusercontent.com/29738718/233629483-c2a0e7fa-f1d9-445e-8023-d7922e816ad0.png) 5. apply the following fixes to the special remote source code ```diff diff --git a/git-annex-remote-zenodo b/git-annex-remote-zenodo index 965f6cb..c316042 100755 --- a/git-annex-remote-zenodo +++ b/git-annex-remote-zenodo @@ -143,10 +142,10 @@ class ZenodoRemote(ExportRemote): # getting the url of the remote (Zenodo or Sandbox) # the user would need the key for both of them and it's created on the website of the one they chose url = self.annex.getconfig('url') - if url is None: - self.url = 'https://zenodo.org/api/deposit/depositions' - else: + if url == 'sandbox': self.url = 'https://sandbox.zenodo.org/api/deposit/depositions' + else: + self.url = 'https://zenodo.org/api/deposit/depositions' # the key is passed as an argument when using the commant initremote (ex: key='') # if it's not been added as an argument, we raise an @@ -189,11 +188,11 @@ class ZenodoRemote(ExportRemote): # let's try to connect to the API, if the status code is not 200: there is an error self.key = self.annex.getconfig('key') url = self.annex.getconfig('url') - if url is None: - self.url = 'https://zenodo.org/api/deposit/depositions' - else: + if url == 'sandbox': self.url = 'https://sandbox.zenodo.org/api/deposit/depositions' - + else: + self.url = 'https://zenodo.org/api/deposit/depositions' ``` then, you can use it to create a Zenodo deposit, push data there, and retrieve it back: ``` (handbook) adina@muninn in /tmp ❱ datalad create my-zenodo-deposit create(ok): /tmp/my-zenodo-deposit (dataset) (handbook) adina@muninn in /tmp ❱ cd my-zenodo-deposit (handbook) adina@muninn in /tmp/my-zenodo-deposit on git:master ❱ echo 12345 > file (handbook) adina@muninn in /tmp/my-zenodo-deposit on git:master ❱ datalad save add(ok): file (file) save(ok): . (dataset) action summary: add (ok: 1) save (ok: 1) (handbook) adina@muninn in /tmp/my-zenodo-deposit on git:master ❱ git annex initremote zenodo type=external externaltype=zenodo key=FPnuCDH1TjYeQbK5h1tWhK2ReR3udRmiubE3Wazf2kuk7gwFZfdit1S6pnry encryption=none url=None initremote zenodo <Response [201]> ------------ git-annex-remote-zenodo------------ Finished initializing a Zenodo remote successfully. ------------------------------------------------ ok (recording state in git...) (handbook) adina@muninn in /tmp/my-zenodo-deposit on git:master ❱ datalad create-sibling-github my-zenodo-deposit --publish-depends zenodo --access-protocol ssh create_sibling_github(ok): [sibling repository 'github' created at https://github.com/adswa/my-zenodo-deposit] [INFO ] Configure additional publication dependency on "zenodo" configure-sibling(ok): . (sibling) action summary: configure-sibling (ok: 1) create_sibling_github (ok: 1) datalad push --to github copy(ok): my-file (file) [to zenodo-test...] publish(ok): . (dataset) [refs/heads/master->github:refs/heads/master [new branch]] publish(ok): . (dataset) [refs/heads/git-annex->github:refs/heads/git-annex [new branch]] action summary: publish (ok: 2) copy (ok: 1) (handbook) adina@muninn in /tmp/zenodo on git:master ❱ datalad drop file drop(ok): file (file) (handbook) adina@muninn in /tmp/zenodo on git:master ❱ datalad get file get(ok): file (file) [from zenodo...] ``` The special remote does not publish zenodo records, you can find them as untitled drafts in your account and edit their metadata: ![image](https://user-images.githubusercontent.com/29738718/233644400-4e322c47-7056-4ac9-b30f-d01ca31d6c73.png) Be a bit careful here, if you publish something you can't delete it yourself. If you use `url=sandbox` in initremote and a token from sandbox.zenodo.org, you can test in a sandbox: ![image](https://user-images.githubusercontent.com/29738718/233631512-e47dff99-39e0-40c4-ae3c-155b502c387d.png) Things then fall apart quite quickly when I want to enable the remote in a clone. ``` (handbook) adina@muninn in /tmp ❱ datalad clone git@github.com:adswa/my-zenodo-deposit.git retrieval-from-zenodo 1 ! [INFO ] Unable to parse git config from origin [INFO ] Remote origin does not have git-annex installed; setting annex-ignore [INFO ] This could be a problem with the git-annex installation on the remote. Please make sure that git-annex-shell is available in PATH when you ssh into the remote. Once you have fixed the git-annex installation, run: git annex enableremote origin [INFO ] access to 1 dataset sibling zenodo not auto-enabled, enable with: | datalad siblings -d "/tmp/retrieval-from-zenodo" enable -s zenodo install(ok): /tmp/retrieval-from-zenodo (dataset) (handbook) adina@muninn in /tmp ❱ cd retrieval-from-zenodo (handbook) adina@muninn in /tmp/retrieval-from-zenodo on git:master ❱ datalad siblings -d "/tmp/retrieval-from-zenodo" enable -s zenodo .: zenodo(?) [git] ❱ datalad get file get(error): file (file) [Verification of content failed] ``` I have investigated this a bit, and it seems like this enableremote triggers an `initremote` in the specialremote with a completly new deposition id - instead of finding the former deposit, it creates a new one. I think the deposition ID needs to be recorded in the special remote to later get enabled. But I ran out of time, and will leave this investigation for the next time or person. Sadly, the git repository the special remote implementation lives in does not have an issue tracker enabled.
jkuhl-uni commented 2024-08-12 14:46:05 +00:00 (Migrated from github.com)

Hey, I had a look into this and tried to fix the script that @adswa found.
Can someone maybe take a look at this before I continue?
Currently, the advantages are, that a new clone does not open a new deposit (so far I only checked this for the case that we have one user pushing into the deposit) and the script now checks if the deposit is published or not. If it the lastest draft is published and therefore not writeable, a new draft is made and we subsequently push into that draft.
Could be cool to have some feedback :)

Hey, I had a look into this and tried to fix the script that @adswa found. Can someone maybe take a look at [this](https://github.com/jkuhl-uni/git-annex-remote-zenodo) before I continue? Currently, the advantages are, that a new clone does not open a new deposit (so far I only checked this for the case that we have one user pushing into the deposit) and the script now checks if the deposit is published or not. If it the lastest draft is published and therefore not writeable, a new draft is made and we subsequently push into that draft. Could be cool to have some feedback :)
adswa commented 2024-08-19 15:05:38 +00:00 (Migrated from github.com)

hey @jkuhl-uni! This is fantastic, thanks a lot! Maybe we can use this momentum to turn this into a fully functioning special remote! I was wondering whether you could enable issues in your fork so that we could explore and develop over there? I also send a very small PR.

I only tried it out briefly, and it indeed works nicely for a single-user use case. I like how it creates a new draft when a dataset was previously published already. I was not able to add to an existing draft with a different user (I believe this is because the draft is not listed under that second user's drafts in zenodos API, even if they're authorized to manage the draft). And I have struggled to obtain files when using a second user's API key. I hope to look at this further this week. :)

hey @jkuhl-uni! This is fantastic, thanks a lot! Maybe we can use this momentum to turn this into a fully functioning special remote! I was wondering whether you could enable issues in your fork so that we could explore and develop over there? I also send a very small PR. I only tried it out briefly, and it indeed works nicely for a single-user use case. I like how it creates a new draft when a dataset was previously published already. I was not able to add to an existing draft with a different user (I believe this is because the draft is not listed under that second user's drafts in zenodos API, even if they're authorized to manage the draft). And I have struggled to obtain files when using a second user's API key. I hope to look at this further this week. :)
Sign in to join this conversation.
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
handbook/book#941
No description provided.