Skip to content

Commit

Permalink
Try CI with Data API keys
Browse files Browse the repository at this point in the history
  • Loading branch information
mfleschutz committed Jul 7, 2021
1 parent deb37b8 commit d02a919
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 10 deletions.
6 changes: 5 additions & 1 deletion .github/workflows/On_push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,13 @@ jobs:
auto-activate-base: false
activate-environment: elmada
- name: Run pytest and generate coverage report
env:
ENTSOE_API_KEY: ${{ secrets.ENTSOE_API_KEY }}
MORPH_API_KEY: ${{ secrets.MORPH_API_KEY }}
QUANDL_API_KEY: ${{ secrets.QUANDL_API_KEY }}
shell: bash -l {0}
run: |
pytest -v --cov=elmada --cov-report=xml -m="not apikey" .
pytest -v --cov=elmada --cov-report=xml .
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v1
with:
Expand Down
32 changes: 23 additions & 9 deletions elmada/helper.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import logging
import os
from datetime import datetime
from functools import lru_cache
from pathlib import Path
Expand All @@ -19,9 +20,14 @@
"entsoe": (
"ENTSO-E API key",
"https://transparency.entsoe.eu/content/static_content/Static%20content/web%20api/Guide.html",
"ENTSOE_API_KEY",
),
"morph": ("Morph API key", "https://morph.io/documentation/api", "MORPH_API_KEY"),
"quandl": (
"Quandl API key",
"https://docs.quandl.com/docs#section-authentication",
"QUANDL_API_KEY",
),
"morph": ("Morph API key", "https://morph.io/documentation/api"),
"quandl": ("Quandl API key", "https://docs.quandl.com/docs#section-authentication"),
}


Expand Down Expand Up @@ -407,14 +413,22 @@ def set_api_key(which: str, api_key: str) -> None:


def get_api_key(which: str = "entsoe"):
fp = paths.KEYS_DIR / f"{which}.txt"
assert which in APIS, f"`which` must be one of {list(APIS.keys())}."

var_name = APIS[which][2]

try:
return fp.read_text().strip()
return os.environ[var_name]

except FileNotFoundError as e:
raise Exception(
f"`{which}.txt` file not found. "
f"Please get a valid {APIS[which][0]} (see {APIS[which][1]}) and place it in `elmada/api_keys/{which}.txt`\n"
) from e
except KeyError:

try:
fp = paths.KEYS_DIR / f"{which}.txt"
return fp.read_text().strip()

except FileNotFoundError as e:
raise Exception(
f"`{which}.txt` file not found and {var_name} not set."
f"Please get a valid {APIS[which][0]} "
f"(see {APIS[which][1]}) and place it in `elmada/api_keys/{which}.txt`\n"
) from e

0 comments on commit d02a919

Please sign in to comment.