From 881196188c4bfc1e1ec3acaab62972bc2cd30bf8 Mon Sep 17 00:00:00 2001 From: Qubasa Date: Thu, 13 Jun 2024 18:34:29 +0200 Subject: [PATCH] matrix-bot: Init git commit summarizer --- pkgs/flake-module.nix | 1 + pkgs/matrix-bot/.envrc | 6 +++ pkgs/matrix-bot/default.nix | 36 ++++++++++++++++ pkgs/matrix-bot/flake-module.nix | 15 +++++++ pkgs/matrix-bot/matrix_bot/__init__.py | 0 pkgs/matrix-bot/matrix_bot/__main__.py | 0 pkgs/matrix-bot/matrix_bot/main.py | 3 ++ pkgs/matrix-bot/pyproject.toml | 59 ++++++++++++++++++++++++++ pkgs/matrix-bot/shell.nix | 33 ++++++++++++++ 9 files changed, 153 insertions(+) create mode 100644 pkgs/matrix-bot/.envrc create mode 100644 pkgs/matrix-bot/default.nix create mode 100644 pkgs/matrix-bot/flake-module.nix create mode 100644 pkgs/matrix-bot/matrix_bot/__init__.py create mode 100644 pkgs/matrix-bot/matrix_bot/__main__.py create mode 100644 pkgs/matrix-bot/matrix_bot/main.py create mode 100644 pkgs/matrix-bot/pyproject.toml create mode 100644 pkgs/matrix-bot/shell.nix diff --git a/pkgs/flake-module.nix b/pkgs/flake-module.nix index b4ee8e21..5d6a1cf5 100644 --- a/pkgs/flake-module.nix +++ b/pkgs/flake-module.nix @@ -8,6 +8,7 @@ ./schemas/flake-module.nix ./webview-ui/flake-module.nix ./distro-packages/flake-module.nix + ./matrix-bot/flake-module.nix ]; perSystem = diff --git a/pkgs/matrix-bot/.envrc b/pkgs/matrix-bot/.envrc new file mode 100644 index 00000000..0b941ecc --- /dev/null +++ b/pkgs/matrix-bot/.envrc @@ -0,0 +1,6 @@ +source_up + +watch_file flake-module.nix shell.nix default.nix + +# Because we depend on nixpkgs sources, uploading to builders takes a long time +use flake .#matrix-bot --builders '' diff --git a/pkgs/matrix-bot/default.nix b/pkgs/matrix-bot/default.nix new file mode 100644 index 00000000..0fda206a --- /dev/null +++ b/pkgs/matrix-bot/default.nix @@ -0,0 +1,36 @@ +{ python3, setuptools, ... }: + + +let + + pythonDependencies = [ + + ]; + + runtimeDependencies = [ ]; + + testDependencies = + runtimeDependencies ++ [ + ]; + +in +python3.pkgs.buildPythonApplication { + name = "matrix-bot"; + src = ./.; + format = "pyproject"; + + nativeBuildInputs = [ + setuptools + ]; + + propagatedBuildInputs = pythonDependencies; + + passthru.testDependencies = testDependencies; + + # Clean up after the package to avoid leaking python packages into a devshell + postFixup = '' + rm $out/nix-support/propagated-build-inputs + ''; + + meta.mainProgram = "matrix-bot"; +} diff --git a/pkgs/matrix-bot/flake-module.nix b/pkgs/matrix-bot/flake-module.nix new file mode 100644 index 00000000..0dd2b86c --- /dev/null +++ b/pkgs/matrix-bot/flake-module.nix @@ -0,0 +1,15 @@ +{ ... }: +{ + perSystem = + { self', pkgs, ... }: + { + + devShells.matrix-bot = pkgs.callPackage ./shell.nix { inherit (self'.packages) matrix-bot; }; + packages = { + matrix-bot = pkgs.python3.pkgs.callPackage ./default.nix { }; + default = self'.packages.matrix-bot; + }; + + checks = { }; + }; +} diff --git a/pkgs/matrix-bot/matrix_bot/__init__.py b/pkgs/matrix-bot/matrix_bot/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/pkgs/matrix-bot/matrix_bot/__main__.py b/pkgs/matrix-bot/matrix_bot/__main__.py new file mode 100644 index 00000000..e69de29b diff --git a/pkgs/matrix-bot/matrix_bot/main.py b/pkgs/matrix-bot/matrix_bot/main.py new file mode 100644 index 00000000..bffa1502 --- /dev/null +++ b/pkgs/matrix-bot/matrix_bot/main.py @@ -0,0 +1,3 @@ + +def main(): + print("Hello, world!") \ No newline at end of file diff --git a/pkgs/matrix-bot/pyproject.toml b/pkgs/matrix-bot/pyproject.toml new file mode 100644 index 00000000..a21466a0 --- /dev/null +++ b/pkgs/matrix-bot/pyproject.toml @@ -0,0 +1,59 @@ +[build-system] +requires = ["setuptools"] +build-backend = "setuptools.build_meta" + +[project] +name = "matrix-bot" +description = "matrix bot for release messages from git commits" +dynamic = ["version"] +scripts = { clan = "matrix_bot:main" } +license = {text = "MIT"} + +[project.urls] +Homepage = "https://clan.lol/" +Documentation = "https://docs.clan.lol/" +Repository = "https://git.clan.lol/clan/clan-core" + +[tool.setuptools.packages.find] +exclude = ["result"] + +[tool.setuptools.package-data] +matrix_bot = ["py.typed"] + +[tool.pytest.ini_options] +testpaths = "tests" +faulthandler_timeout = 60 +log_level = "DEBUG" +log_format = "%(levelname)s: %(message)s\n %(pathname)s:%(lineno)d::%(funcName)s" +addopts = "--cov . --cov-report term --cov-report html:.reports/html --no-cov-on-fail --durations 5 --color=yes --new-first" # Add --pdb for debugging +norecursedirs = "tests/helpers" +markers = ["impure", "with_core"] + +[tool.mypy] +python_version = "3.11" +warn_redundant_casts = true +disallow_untyped_calls = true +disallow_untyped_defs = true +no_implicit_optional = true + +[[tool.mypy.overrides]] +module = "argcomplete.*" +ignore_missing_imports = true + +[[tool.mypy.overrides]] +module = "ipdb.*" +ignore_missing_imports = true + +[[tool.mypy.overrides]] +module = "pytest.*" +ignore_missing_imports = true + +[[tool.mypy.overrides]] +module = "setuptools.*" +ignore_missing_imports = true + +[tool.ruff] +target-version = "py311" +line-length = 88 +lint.select = [ "E", "F", "I", "U", "N", "RUF", "ANN", "A" ] +lint.ignore = ["E501", "E402", "E731", "ANN101", "ANN401", "A003"] diff --git a/pkgs/matrix-bot/shell.nix b/pkgs/matrix-bot/shell.nix new file mode 100644 index 00000000..690857fd --- /dev/null +++ b/pkgs/matrix-bot/shell.nix @@ -0,0 +1,33 @@ +{ + matrix-bot, + mkShell, + ruff, + python3, +}: +let + devshellTestDeps = + matrix-bot.passthru.testDependencies + ++ (with python3.pkgs; [ + rope + setuptools + wheel + ipdb + pip + ]); +in +mkShell { + buildInputs = [ + + ruff + ] ++ devshellTestDeps; + + PYTHONBREAKPOINT = "ipdb.set_trace"; + + shellHook = '' + export GIT_ROOT="$(git rev-parse --show-toplevel)" + export PKG_ROOT="$GIT_ROOT/pkgs/matrix-bot" + + # Add clan command to PATH + export PATH="$PKG_ROOT/bin":"$PATH" + ''; +}