Skip to content

Commit 1c793ff

Browse files
retrieve config prefix individually (#33)
* retrieve config prefix individually * retrieve results path from config and name * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * fix bug --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 9a50252 commit 1c793ff

File tree

10 files changed

+72
-55
lines changed

10 files changed

+72
-55
lines changed

.github/workflows/codeql.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,4 +89,4 @@ jobs:
8989
- name: Perform CodeQL Analysis
9090
uses: github/codeql-action/analyze@v3
9191
with:
92-
category: "/language:${{matrix.language}}"
92+
category: "/language:${{matrix.language}}"

.github/workflows/publish-reporter-image.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ jobs:
2020
- name: 'Build Inventory Image'
2121
run: |
2222
docker build . --tag ghcr.io/${{ github.repository_owner }}/pypsa-reporter:latest --file docker/reporter/Dockerfile
23-
23+
2424
- name: 'Push Inventory Image'
25-
run: |
26-
docker push ghcr.io/${{ github.repository_owner }}/pypsa-reporter:latest
25+
run: |-
26+
docker push ghcr.io/${{ github.repository_owner }}/pypsa-reporter:latest

docker/reporter/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM python:3.12-slim
1+
FROM python:3.13-slim
22

33
LABEL org.opencontainers.image.source https://github.com/lkstrp/pypsa-validator
44

pyproject.toml

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,16 @@ authors = ["Lukas Trippe <lkstrp@pm.me>"]
1010

1111

1212
[tool.poetry.dependencies]
13-
python = "^3.7"
13+
python = "^3.12"
1414
# Add your specific dependencies here:
1515
requests = "^2.32.3"
16-
numpy = "^2.2.0"
16+
numpy = "^2.2.1"
1717
openpyxl = "^3.1.5"
18-
matplotlib = "^3.9.3"
18+
matplotlib = "^3.10.0"
1919
seaborn = "^0.13.2"
20-
GitPython = "^3.1.43"
21-
python-gitlab = "^5.1.0"
20+
GitPython = "^3.1.44"
21+
python-gitlab = "^5.3.1"
22+
pyyaml = "^6.0.2"
2223
# Add more as needed...
2324

2425

reporter/__main__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ def main():
1212
report = "".join(comps)
1313

1414
print(report)
15-
import os
1615

1716
publish(report)
1817

reporter/components/general.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
import pandas as pd
44

55
from reporter.components.utils import create_details_block
6-
from reporter.meta.config import PLOTS, PREFIX
6+
from reporter.meta.config import PLOTS
7+
from reporter.meta.repo import PATH_FEAT_RESULTS, PATH_MAIN_RESULTS
78
from reporter.utils import URL_IMAGE_PLACEHOLDER
89

910

@@ -15,8 +16,8 @@ def plots_table() -> str:
1516
for plot in plots_list:
1617
if not plot:
1718
continue
18-
url_a = URL_IMAGE_PLACEHOLDER.format(f"main/results/{PREFIX}/{plot}")
19-
url_b = URL_IMAGE_PLACEHOLDER.format(f"feat/results/{PREFIX}/{plot}")
19+
url_a = URL_IMAGE_PLACEHOLDER.format(f"{PATH_MAIN_RESULTS}/{plot}")
20+
url_b = URL_IMAGE_PLACEHOLDER.format(f"{PATH_FEAT_RESULTS}/{plot}")
2021
rows.append(
2122
[
2223
f'<img src="{url_a}" alt="Image not available">',

reporter/meta/config.py

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
1-
from reporter.meta.paths import PATH_ARTIFACTS, PATH_REPO
1+
from pathlib import Path
2+
23
from reporter.utils import read_env_var
34

5+
# Mounted Paths
6+
PATH_ARTIFACTS = Path("/artifacts")
7+
PATH_REPO = Path("/repo")
8+
49
# Project
510
PLATFORM = read_env_var("PLATFORM", "gitlab")
611
DOMAIN = read_env_var("DOMAIN", "https://gitlab.com")
@@ -15,13 +20,26 @@
1520
# Configuration
1621
PLOTS = read_env_var("PLOTS")
1722

23+
PATH_CONFIG = read_env_var("PATH_CONFIG")
1824

19-
prefixes = [
20-
prefix
21-
for prefix in (PATH_ARTIFACTS / "main" / "results").iterdir()
22-
if prefix.is_dir()
25+
# Do some checks on mounted paths
26+
if not PATH_ARTIFACTS.exists():
27+
msg = f"Path '{PATH_ARTIFACTS}' must be mounted."
28+
raise OSError(msg)
29+
needed_subdir = [
30+
"feat/benchmarks",
31+
"feat/results",
32+
"feat/logs",
33+
"feat/.snakemake/log",
34+
"main/benchmarks",
35+
"main/results",
36+
"main/logs",
37+
"main/.snakemake/log",
2338
]
39+
if not all((PATH_ARTIFACTS / subdir).exists() for subdir in needed_subdir):
40+
msg = f"Path '{PATH_ARTIFACTS}' must contain subdirectories: {needed_subdir}"
41+
raise OSError(msg)
2442

25-
PREFIX = prefixes[0].name # TODO: Handle different prefixes
26-
27-
PATH_CONFIG = PATH_REPO / read_env_var("PATH_CONFIG")
43+
if not PATH_REPO.exists():
44+
msg = f"Path '{PATH_REPO}' must be mounted."
45+
raise OSError(msg)

reporter/meta/paths.py

Lines changed: 0 additions & 27 deletions
This file was deleted.

reporter/meta/repo.py

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,12 @@
1010
- BEHIND_COUNT: Number of commits behind the main branch.
1111
"""
1212

13+
from pathlib import Path
14+
1315
import git
16+
import yaml
1417

15-
from reporter.meta.config import HASH_FEAT, HASH_MAIN, PATH_CONFIG
16-
from reporter.meta.paths import PATH_REPO
18+
from reporter.meta.config import HASH_FEAT, HASH_MAIN, PATH_CONFIG, PATH_REPO
1719

1820
repo = git.Repo(PATH_REPO)
1921

@@ -54,3 +56,23 @@
5456
)
5557
)
5658
)
59+
60+
# Read in hash specific config
61+
file_blob = repo.commit(HASH_MAIN).tree / str(PATH_CONFIG)
62+
CONFIG_MAIN = yaml.safe_load(file_blob.data_stream.read().decode("utf-8"))
63+
file_blob = repo.commit(HASH_FEAT).tree / str(PATH_CONFIG)
64+
CONFIG_FEAT = yaml.safe_load(file_blob.data_stream.read().decode("utf-8"))
65+
66+
67+
PATH_MAIN_RESULTS = (
68+
Path("main")
69+
/ "results"
70+
/ CONFIG_MAIN.get("run", {}).get("prefix", "")
71+
/ CONFIG_MAIN.get("run", {}).get("name", "")
72+
)
73+
PATH_FEAT_RESULTS = (
74+
Path("feat")
75+
/ "results"
76+
/ CONFIG_FEAT.get("run", {}).get("prefix", "")
77+
/ CONFIG_FEAT.get("run", {}).get("name", "")
78+
)

reporter/publish.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
import gitlab
21
import re
2+
3+
import gitlab
4+
5+
from reporter.meta.config import DOMAIN, PATH_ARTIFACTS, PLATFORM
36
from reporter.utils import REPORT_IDENTIFIER, read_env_var
4-
from reporter.meta.paths import PATH_ARTIFACTS
5-
from reporter.meta.config import PREFIX, PLATFORM, DOMAIN
67

78

89
def publish(text: str) -> None:
@@ -23,7 +24,9 @@ def publish_on_gitlab(text: str) -> None:
2324

2425
def _upload_image_to_github(name):
2526
path = PATH_ARTIFACTS / name
26-
assert path.exists(), f"File {path} does not exist"
27+
if not path.exists():
28+
msg = f"File {path} does not exist. Are you sure you specified the correct configuration?"
29+
raise FileNotFoundError(msg)
2730
uploaded_file = project.upload(name, filedata=open(path, "rb"))
2831
return uploaded_file["url"]
2932

0 commit comments

Comments
 (0)