Add test and option to disable online retrieve rules

This commit is contained in:
euronion 2023-07-13 08:22:22 +02:00
parent 3fc84a51e5
commit 30a81a559f
3 changed files with 21 additions and 1 deletions

View File

@ -48,7 +48,10 @@ wildcard_constraints:
include: "rules/common.smk" include: "rules/common.smk"
include: "rules/collect.smk" include: "rules/collect.smk"
include: "rules/retrieve.smk" if (config["enable"].get("retrieve","auto") == "auto" and has_internet_access())or config["enable"]["retrieve"] is True:
include: "rules/retrieve.smk"
else:
print("Datafile downloads disabled in config[retrieve] or no internet access.")
include: "rules/build_electricity.smk" include: "rules/build_electricity.smk"
include: "rules/build_sector.smk" include: "rules/build_sector.smk"
include: "rules/solve_electricity.smk" include: "rules/solve_electricity.smk"

View File

@ -67,6 +67,7 @@ snapshots:
inclusive: 'left' # include start, not end inclusive: 'left' # include start, not end
enable: enable:
retrieve: auto
prepare_links_p_nom: false prepare_links_p_nom: false
retrieve_databundle: true retrieve_databundle: true
retrieve_sector_databundle: true retrieve_sector_databundle: true

View File

@ -23,6 +23,22 @@ def memory(w):
return int(factor * (10000 + 195 * int(w.clusters))) return int(factor * (10000 + 195 * int(w.clusters)))
# Check if the workflow has access to the internet by trying to access the HEAD of specified url
def has_internet_access(url="www.zenodo.org") -> bool:
import http.client as http_client
# based on answer and comments from
# https://stackoverflow.com/a/29854274/11318472
conn = http_client.HTTPConnection(url, timeout=5) # need access to zenodo anyway
try:
conn.request("HEAD", "/")
return True
except:
return False
finally:
conn.close()
def input_eurostat(w): def input_eurostat(w):
# 2016 includes BA, 2017 does not # 2016 includes BA, 2017 does not
report_year = config["energy"]["eurostat_report_year"] report_year = config["energy"]["eurostat_report_year"]