77
88
99import argparse
10- import os
1110import json
11+ import os
1212import sys
13- from glob import glob
1413from datetime import datetime
14+ from glob import glob
15+
1516import requests
1617
1718
@@ -177,7 +178,6 @@ def upload_archive(self, upload, archive):
177178 """
178179 # Using requests files indicates multipart/form-data
179180 # Here we are uploading the new release file
180- url = "https://zenodo.org/api/deposit/depositions/%s/files" % upload ["id" ]
181181 bucket_url = upload ["links" ]["bucket" ]
182182
183183 with open (archive , "rb" ) as fp :
@@ -188,8 +188,8 @@ def upload_archive(self, upload, archive):
188188 )
189189 if response .status_code not in [200 , 201 ]:
190190 sys .exit (
191- "Trouble uploading artifact %s to bucket with response code %s" %
192- (archive , response .status_code )
191+ "Trouble uploading artifact %s to bucket with response code %s"
192+ % (archive , response .status_code )
193193 )
194194
195195 def publish (self , data ):
@@ -208,7 +208,7 @@ def publish(self, data):
208208 for k , v in published ["links" ].items ():
209209 set_env_and_output (k , v )
210210
211- def upload_metadata (self , upload , zenodo_json , version ):
211+ def upload_metadata (self , upload , zenodo_json , version , html_url = None ):
212212 """
213213 Given an upload response and zenodo json, upload new data
214214
@@ -220,13 +220,24 @@ def upload_metadata(self, upload, zenodo_json, version):
220220 if zenodo_json :
221221 metadata .update (read_json (zenodo_json ))
222222 metadata ["version" ] = version
223- metadata ["publication_date" ] = str (datetime .today ().strftime (' %Y-%m-%d' ))
223+ metadata ["publication_date" ] = str (datetime .today ().strftime (" %Y-%m-%d" ))
224224
225225 # New .zenodo.json may be missing this
226226 if "upload_type" not in metadata :
227227 metadata ["upload_type" ] = "software"
228228 self .headers .update ({"Content-Type" : "application/json" })
229229
230+ # Update the related info to use the url to the current release
231+ if html_url :
232+ metadata ["related_identifiers" ] = [
233+ {
234+ "identifier" : html_url ,
235+ "relation" : "isSupplementTo" ,
236+ "resource_type" : "software" ,
237+ "scheme" : "url" ,
238+ }
239+ ]
240+
230241 # Make the deposit!
231242 url = "https://zenodo.org/api/deposit/depositions/%s" % upload ["id" ]
232243 response = requests .put (
@@ -243,7 +254,9 @@ def upload_metadata(self, upload, zenodo_json, version):
243254 return response .json ()
244255
245256
246- def upload_archive (archive , version , zenodo_json = None , doi = None , sandbox = False ):
257+ def upload_archive (
258+ archive , version , html_url = None , zenodo_json = None , doi = None , sandbox = False
259+ ):
247260 """
248261 Upload an archive to an existing Zenodo "versions DOI"
249262 """
@@ -265,7 +278,7 @@ def upload_archive(archive, version, zenodo_json=None, doi=None, sandbox=False):
265278 cli .upload_archive (upload , path )
266279
267280 # Finally, load .zenodo.json and add version
268- data = cli .upload_metadata (upload , zenodo_json , version )
281+ data = cli .upload_metadata (upload , zenodo_json , version , html_url )
269282
270283 # Finally, publish
271284 cli .publish (data )
@@ -288,6 +301,9 @@ def get_parser():
288301 )
289302 upload .add_argument ("--version" , help = "version to upload" )
290303 upload .add_argument ("--doi" , help = "an existing DOI to add a new version to" )
304+ upload .add_argument (
305+ "--html-url" , dest = "html_url" , help = "url to use for the release"
306+ )
291307 return parser
292308
293309
@@ -316,6 +332,7 @@ def help(return_code=0):
316332 zenodo_json = args .zenodo_json ,
317333 version = args .version ,
318334 doi = args .doi ,
335+ html_url = args .html_url ,
319336 )
320337
321338 # We should not get here :)
0 commit comments