Skip to content

Commit

Permalink
Add test and option to disable online retrieve rules
Browse files Browse the repository at this point in the history
  • Loading branch information
euronion committed Jul 13, 2023
1 parent 3fc84a5 commit 30a81a5
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
5 changes: 4 additions & 1 deletion Snakefile
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,10 @@ wildcard_constraints:

include: "rules/common.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_sector.smk"
include: "rules/solve_electricity.smk"
Expand Down
1 change: 1 addition & 0 deletions config/config.default.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ snapshots:
inclusive: 'left' # include start, not end

enable:
retrieve: auto
prepare_links_p_nom: false
retrieve_databundle: true
retrieve_sector_databundle: true
Expand Down
16 changes: 16 additions & 0 deletions rules/common.smk
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,22 @@ def memory(w):
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):
# 2016 includes BA, 2017 does not
report_year = config["energy"]["eurostat_report_year"]
Expand Down

0 comments on commit 30a81a5

Please sign in to comment.