diff --git a/docker/soft-fork-bot/Dockerfile b/docker/soft-fork-bot/Dockerfile new file mode 100644 index 0000000..f3def24 --- /dev/null +++ b/docker/soft-fork-bot/Dockerfile @@ -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"] diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..d5c9e19 --- /dev/null +++ b/pyproject.toml @@ -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 "] + + +[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 diff --git a/src/soft_fork_bot/__init__.py b/src/soft_fork_bot/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/src/soft_fork_bot/__main__.py b/src/soft_fork_bot/__main__.py new file mode 100644 index 0000000..94e9d07 --- /dev/null +++ b/src/soft_fork_bot/__main__.py @@ -0,0 +1,6 @@ +def main(): + raise NotImplementedError + + +if __name__ == "__main__": + main() diff --git a/src/soft_fork_bot/git.py b/src/soft_fork_bot/git.py new file mode 100644 index 0000000..7f1c72b --- /dev/null +++ b/src/soft_fork_bot/git.py @@ -0,0 +1,6 @@ +""" +Soft fork bot git logic + +DRAFT: +- Logic from merge_upstream_changes.sh +""" diff --git a/src/soft_fork_bot/meta/__init__.py b/src/soft_fork_bot/meta/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/src/soft_fork_bot/meta/config.py b/src/soft_fork_bot/meta/config.py new file mode 100644 index 0000000..3f57e32 --- /dev/null +++ b/src/soft_fork_bot/meta/config.py @@ -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") diff --git a/src/soft_fork_bot/platform/__init__.py b/src/soft_fork_bot/platform/__init__.py new file mode 100644 index 0000000..7010dee --- /dev/null +++ b/src/soft_fork_bot/platform/__init__.py @@ -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"] diff --git a/src/soft_fork_bot/platform/github.py b/src/soft_fork_bot/platform/github.py new file mode 100644 index 0000000..00c946f --- /dev/null +++ b/src/soft_fork_bot/platform/github.py @@ -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") diff --git a/src/soft_fork_bot/platform/gitlab.py b/src/soft_fork_bot/platform/gitlab.py new file mode 100644 index 0000000..cf06c31 --- /dev/null +++ b/src/soft_fork_bot/platform/gitlab.py @@ -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 diff --git a/src/soft_fork_bot/utils.py b/src/soft_fork_bot/utils.py new file mode 100644 index 0000000..ed8ce88 --- /dev/null +++ b/src/soft_fork_bot/utils.py @@ -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