@@ -44,6 +44,9 @@ def get_repodata(url_or_path, platform=None):
4444 url_or_path += f"{ platform } /repodata.json"
4545
4646 if "://" not in url_or_path :
47+ if not os .path .exists (url_or_path ):
48+ print (f"No repodata found at { url_or_path } , assuming no existing packages" )
49+ return {"packages" : {}, "packages.conda" : {}}
4750 with open (url_or_path ) as fi :
4851 return json .load (fi )
4952 print ("Downloading repodata from " , url_or_path )
@@ -58,13 +61,32 @@ def get_repodata(url_or_path, platform=None):
5861 max_age = 100_000 # seconds == 27 hours
5962 if age < max_age :
6063 with open (fn ) as fi :
61- return json .load (fi )
64+ try :
65+ return json .load (fi )
66+ except json .JSONDecodeError :
67+ print (f"Ignoring invalid cached repodata at { fn } " )
68+ os .remove (fn )
6269
6370 repodata = requests .get (url_or_path )
71+ if repodata .status_code == 404 :
72+ print (f"No repodata found at { url_or_path } , assuming no existing packages" )
73+ return {"packages" : {}, "packages.conda" : {}}
74+ repodata .raise_for_status ()
6475 content = repodata .content
76+ if not content .strip ():
77+ print (f"No repodata found at { url_or_path } , assuming no existing packages" )
78+ return {"packages" : {}, "packages.conda" : {}}
79+ try :
80+ parsed_repodata = json .loads (content )
81+ except json .JSONDecodeError :
82+ print (
83+ f"No valid repodata found at { url_or_path } , assuming no existing packages"
84+ )
85+ return {"packages" : {}, "packages.conda" : {}}
86+
6587 with open (fn , "w" ) as fcache :
6688 fcache .write (content .decode ("utf-8" ))
67- return json . loads ( content )
89+ return parsed_repodata
6890
6991
7092def ensure_name_is_without_distro_prefix_and_with_underscores (name , vinca_conf ):
0 commit comments