Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add structure for rewrite #1

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions docker/soft-fork-bot/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
FROM python:3.13-slim

LABEL org.opencontainers.image.source https://github.com/open-energy-transition/soft-fork-bot/

RUN apt-get update && apt-get install -y \
git

WORKDIR /workdir

COPY ./src/soft_fork_bot ./soft_fork_bot
COPY pyproject.toml ./

RUN pip install .
CMD ["python", "-m", "soft_fork_bot"]
37 changes: 37 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
[build-system]
requires = ["poetry-core>=1.0.0"]
build-backend = "poetry.core.masonry.api"

[tool.poetry]
name="soft_fork_bot"
version="0.1.0"
description = "Create PyPSA validation reports"
authors = ["Lukas Trippe <[email protected]>"]


[tool.poetry.dependencies]
python = "^3.13"
GitPython = "^3.1.43"
python-gitlab = "^5.1.0"


# Formatter and linter settings
[tool.ruff]
extend-include = ["*.ipynb"]

[tool.ruff.lint]
select = [
'F', # pyflakes
'E', # pycodestyle: Error
'W', # pycodestyle: Warning
'I', # isort
'D', # pydocstyle
'UP', # pyupgrade
'TID', # flake8-tidy-imports
'NPY', # numpy
'RUF013', # ruff
]
ignore = ['D203', 'D212', 'D400', 'ANN101', 'ANN204', 'PD901']

[tool.ruff.lint.mccabe]
max-complexity = 20
Empty file added src/soft_fork_bot/__init__.py
Empty file.
6 changes: 6 additions & 0 deletions src/soft_fork_bot/__main__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
def main():
raise NotImplementedError


if __name__ == "__main__":
main()
6 changes: 6 additions & 0 deletions src/soft_fork_bot/git.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
"""
Soft fork bot git logic

DRAFT:
- Logic from merge_upstream_changes.sh
"""
Empty file.
7 changes: 7 additions & 0 deletions src/soft_fork_bot/meta/config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from reporter.utils import read_env_var

# Project
PLATFORM = read_env_var("PLATFORM")
DOMAIN = read_env_var("DOMAIN")
OWNER = read_env_var("OWNER")
REPO = read_env_var("REPO")
6 changes: 6 additions & 0 deletions src/soft_fork_bot/platform/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from reporter.components.config_diff import text as config_diff
from reporter.components.footer import text as footer
from reporter.components.general import text as general
from reporter.components.header import text as header

__all__ = ["header", "footer", "general", "config_diff"]
10 changes: 10 additions & 0 deletions src/soft_fork_bot/platform/github.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
"""
Create Pull Request on GitHub

DRAFT:
- Get branch of local repo
- Get report/ pr text with some data on diff
- Create pr in remote repo
"""

raise NotImplementedError("GitHub support is not implemented yet")
12 changes: 12 additions & 0 deletions src/soft_fork_bot/platform/gitlab.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
"""
Create Pull Request on GitLab

DRAFT:
- Get branch of local repo
- Get report/ pr text with some data on diff
- Create pr in remote repo
"""

raise NotImplementedError("GitLab support is not implemented yet")

# See https://github.com/PyPSA/pypsa-validator/blob/main/reporter/publish.py for similar implementation
18 changes: 18 additions & 0 deletions src/soft_fork_bot/utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import os
from typing import Any


def read_env_var(var_name: str, default: Any = None, optional: bool = False) -> Any:
"""Get environment variable or raise an error if not set and no default provided."""
value = os.getenv(var_name, default)

# Check if set
if not optional and value is None:
msg = f"The environment variable '{var_name}' is not set."
raise OSError(msg)

# Type conversions
if str(value).lower() in ["true", "false"]:
value = str(value).lower() == "true"

return value