port matrix-ops-bot to uv and nix flake module

This commit is contained in:
Abel Luck 2026-03-05 15:55:47 +01:00
parent c13d5fc536
commit 3a042155af
17 changed files with 2402 additions and 3476 deletions

View file

@ -36,7 +36,7 @@ async def matrix_main(matrix_client: MatrixClient) -> None:
@asynccontextmanager
async def lifespan(app: FastAPI) -> AsyncIterator[None]:
config_fname = os.environ.get("BOT_CONFIG_FILE", "config.yaml")
config_fname = os.environ.get("BOT_CONFIG_FILE", "config.json")
bot_settings = load_config(config_fname)
c = MatrixClient(settings=bot_settings.matrix, join_rooms=bot_settings.get_rooms())
app.state.matrix_client = c
@ -46,7 +46,7 @@ async def lifespan(app: FastAPI) -> AsyncIterator[None]:
await app.state.matrix_client.shutdown()
start_http_server(9000)
# start_http_server(9000)
app = FastAPI(lifespan=lifespan)
instrumentator = Instrumentator().instrument(app)
bearer_security = HTTPBearer(auto_error=False)
@ -173,11 +173,13 @@ async def webhook_handler(
def start_dev() -> None:
uvicorn.run("ops_bot.main:app", port=1111, host="127.0.0.1", reload=True)
uvicorn.run("ops_bot.main:app", port=1112, host="127.0.0.1", reload=True)
def main() -> None:
uvicorn.run(app, port=1111, host="0.0.0.0") # nosec B104
host = os.environ.get("BOT_LISTEN_HOST", "127.0.0.1")
port = int(os.environ.get("BOT_LISTEN_PORT", "1111"))
uvicorn.run(app, port=port, host=host) # nosec B104
if __name__ == "__main__":

View file

@ -13,6 +13,7 @@
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
import os
import os.path
from pathlib import Path
from typing import Any, Callable, Dict, List, Tuple, Union
@ -113,7 +114,11 @@ class PluginTemplateLoader(BaseLoader):
macros: str
def __init__(self, base: str, directory: str) -> None:
base_path = get_project_root() / ".." / "templates" / base
template_root = os.environ.get("OPS_BOT_TEMPLATE_ROOT")
if template_root is None:
template_root = str(get_project_root() / ".." / "templates")
template_root_path = Path(template_root)
base_path = template_root_path / base
self.directory = base_path / directory
self.macros = sync_read_file(base_path / "macros.html")