Skip to content

Commit

Permalink
Refactor database connection handling and update CI workflow to use T…
Browse files Browse the repository at this point in the history
…OEP_TOKEN environment variable
  • Loading branch information
joda9 committed Feb 6, 2025
1 parent 6484d2f commit 5ecc9cf
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 6 deletions.
6 changes: 5 additions & 1 deletion .github/workflows/tests-coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,16 @@ jobs:
run: |
python -m pip install pytest pytest-notebook
python -m pytest --runslow --runonlinux --disable-warnings --color=yes -v
env:
TOEP_TOKEN: ${{ secrets.TOEP_TOKEN_KH }}

- name: Run tests Windows
if: runner.os == 'Windows'
run: |
python -m pip install pytest pytest-notebook
python -m pytest --runslow --disable-warnings --color=yes -v
env:
TOEP_TOKEN: ${{ secrets.TOEP_TOKEN_KH }}

- name: Run tests, coverage and send to coveralls
if: runner.os == 'Linux' && matrix.python-version == 3.9 && matrix.name-suffix == 'coverage'
Expand All @@ -80,5 +84,5 @@ jobs:
coverage run --source=edisgo -m pytest --runslow --runonlinux --disable-warnings --color=yes -v
coveralls
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
TOEP_TOKEN: ${{ secrets.TOEP_TOKEN_KH }}
COVERALLS_SERVICE_NAME: github
11 changes: 10 additions & 1 deletion edisgo/io/db.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import annotations

import logging
import os

from contextlib import contextmanager
from pathlib import Path
Expand Down Expand Up @@ -169,9 +170,17 @@ def engine(path: Path | str = None, ssh: bool = False) -> Engine:
"""

if not ssh:
if "TOEP_TOKEN_KH" in os.environ:
env_var = os.environ["TOEP_TOKEN_KH"]
else:
try:
with open("TOEP_TOKEN.txt") as file:
env_var = file.read().strip()
except FileNotFoundError:
env_var = [""]
database_url = "toep.iks.cs.ovgu.de"
return create_engine(
"postgresql+oedialect://:@" f"{database_url}",
f"postgresql+oedialect://{env_var}@{database_url}",
echo=False,
)

Expand Down
9 changes: 5 additions & 4 deletions edisgo/tools/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@

import edisgo

from edisgo.io.db import engine as toep_engine
from edisgo.io.db import session_scope_egon_data

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -181,10 +182,10 @@ def get_database_alias_dictionaries(self) -> tuple[dict[str, str], dict[str, str
- schema_mapping: A dictionary mapping source schema names to target schema
names.
"""
OEP_CONNECTION = "postgresql+oedialect://:@{platform}"
platform = "toep.iks.cs.ovgu.de"
conn_str = OEP_CONNECTION.format(platform=platform)
engine = sa.create_engine(conn_str)
# OEP_CONNECTION = "postgresql+oedialect://:@{platform}"
# platform = "toep.iks.cs.ovgu.de"
# conn_str = OEP_CONNECTION.format(platform=platform)
engine = toep_engine()
dictionary_schema_name = (
"model_draft" # Replace with the actual schema name if needed
)
Expand Down

0 comments on commit 5ecc9cf

Please sign in to comment.