+def load_current_requirements():
+ """Loads dict of current requirements or empty dict if file doesn't exist"""
+ try:
+ r = requests.get(NEEDS_JSON_URL)
+ if r.headers.get("content-type") == "application/json":
+ with open(NEEDS_PATH, "wb") as needs:
+ needs.write(r.content)
+ else:
+ warnings.warn(
+ (
+ "Unexpected content-type ({}) encountered downloading "
+ + "requirements.json, using last saved copy"
+ ).format(r.headers.get("content-type"))
+ )
+ except requests.exceptions.RequestException as e:
+ warnings.warn("Error downloading latest JSON, using last saved copy.")
+ warnings.warn(UserWarning(e))
+ with open(NEEDS_PATH, "r") as f:
+ return json.load(f)
+