7
7
8
8
9
9
import argparse
10
- import os
11
10
import json
11
+ import os
12
12
import sys
13
- from glob import glob
14
13
from datetime import datetime
14
+ from glob import glob
15
+
15
16
import requests
16
17
17
18
@@ -177,7 +178,6 @@ def upload_archive(self, upload, archive):
177
178
"""
178
179
# Using requests files indicates multipart/form-data
179
180
# Here we are uploading the new release file
180
- url = "https://zenodo.org/api/deposit/depositions/%s/files" % upload ["id" ]
181
181
bucket_url = upload ["links" ]["bucket" ]
182
182
183
183
with open (archive , "rb" ) as fp :
@@ -188,8 +188,8 @@ def upload_archive(self, upload, archive):
188
188
)
189
189
if response .status_code not in [200 , 201 ]:
190
190
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 )
193
193
)
194
194
195
195
def publish (self , data ):
@@ -208,7 +208,7 @@ def publish(self, data):
208
208
for k , v in published ["links" ].items ():
209
209
set_env_and_output (k , v )
210
210
211
- def upload_metadata (self , upload , zenodo_json , version ):
211
+ def upload_metadata (self , upload , zenodo_json , version , html_url = None ):
212
212
"""
213
213
Given an upload response and zenodo json, upload new data
214
214
@@ -220,13 +220,24 @@ def upload_metadata(self, upload, zenodo_json, version):
220
220
if zenodo_json :
221
221
metadata .update (read_json (zenodo_json ))
222
222
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" ))
224
224
225
225
# New .zenodo.json may be missing this
226
226
if "upload_type" not in metadata :
227
227
metadata ["upload_type" ] = "software"
228
228
self .headers .update ({"Content-Type" : "application/json" })
229
229
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
+
230
241
# Make the deposit!
231
242
url = "https://zenodo.org/api/deposit/depositions/%s" % upload ["id" ]
232
243
response = requests .put (
@@ -243,7 +254,9 @@ def upload_metadata(self, upload, zenodo_json, version):
243
254
return response .json ()
244
255
245
256
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
+ ):
247
260
"""
248
261
Upload an archive to an existing Zenodo "versions DOI"
249
262
"""
@@ -265,7 +278,7 @@ def upload_archive(archive, version, zenodo_json=None, doi=None, sandbox=False):
265
278
cli .upload_archive (upload , path )
266
279
267
280
# 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 )
269
282
270
283
# Finally, publish
271
284
cli .publish (data )
@@ -288,6 +301,9 @@ def get_parser():
288
301
)
289
302
upload .add_argument ("--version" , help = "version to upload" )
290
303
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
+ )
291
307
return parser
292
308
293
309
@@ -316,6 +332,7 @@ def help(return_code=0):
316
332
zenodo_json = args .zenodo_json ,
317
333
version = args .version ,
318
334
doi = args .doi ,
335
+ html_url = args .html_url ,
319
336
)
320
337
321
338
# We should not get here :)
0 commit comments