update requirements
This commit is contained in:
parent
f3151cee4c
commit
6f55d39fb6
8 changed files with 53 additions and 33 deletions
|
@ -1,7 +1,7 @@
|
|||
from __future__ import annotations
|
||||
|
||||
import datetime
|
||||
from typing import Any, Dict, List
|
||||
from typing import Dict, List
|
||||
|
||||
import aiohttp
|
||||
import pytimeparse
|
||||
|
@ -32,7 +32,7 @@ class AlertmanagerClient:
|
|||
return await response.json()
|
||||
except ClientError as e:
|
||||
raise AlertmanagerServerError(
|
||||
f"Cannot fetch alerts from Alertmanager"
|
||||
"Cannot fetch alerts from Alertmanager"
|
||||
) from e
|
||||
|
||||
async def get_alert(self, fingerprint: str) -> Dict:
|
||||
|
|
|
@ -13,8 +13,8 @@ from nio import (
|
|||
)
|
||||
|
||||
from matrix_alertbot.alertmanager import AlertmanagerClient
|
||||
from matrix_alertbot.command import Command
|
||||
from matrix_alertbot.chat_functions import make_pill, send_text_to_room, strip_fallback
|
||||
from matrix_alertbot.command import Command
|
||||
from matrix_alertbot.config import Config
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
|
|
@ -1,11 +1,24 @@
|
|||
import logging
|
||||
from typing import Optional, Union
|
||||
from typing import Dict, Optional, TypedDict, Union
|
||||
|
||||
from nio import AsyncClient, ErrorResponse, Response, RoomSendResponse, SendRetryError
|
||||
from typing_extensions import NotRequired
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
ContentEventDict = TypedDict(
|
||||
"ContentEventDict",
|
||||
{
|
||||
"msgtype": str,
|
||||
"format": str,
|
||||
"body": str,
|
||||
"formatted_body": NotRequired[str],
|
||||
"m.relates_to": NotRequired[Dict],
|
||||
},
|
||||
)
|
||||
|
||||
|
||||
async def send_text_to_room(
|
||||
client: AsyncClient,
|
||||
room_id: str,
|
||||
|
@ -37,7 +50,7 @@ async def send_text_to_room(
|
|||
# Determine whether to ping room members or not
|
||||
msgtype = "m.notice" if notice else "m.text"
|
||||
|
||||
content = {
|
||||
content: ContentEventDict = {
|
||||
"msgtype": msgtype,
|
||||
"format": "org.matrix.custom.html",
|
||||
"body": plaintext,
|
||||
|
|
5
mypy.ini
5
mypy.ini
|
@ -2,4 +2,7 @@
|
|||
ignore_missing_imports = True
|
||||
disallow_untyped_defs = True
|
||||
disallow_untyped_calls = True
|
||||
plugins = sqlalchemy.ext.mypy.plugin
|
||||
exclude =
|
||||
env
|
||||
.env
|
||||
.venv
|
||||
|
|
10
requirements.txt
Normal file
10
requirements.txt
Normal file
|
@ -0,0 +1,10 @@
|
|||
coverage>=6.4.1
|
||||
black>=22.6.0
|
||||
flake8>=4.0.1
|
||||
flake8-comprehensions>=3.10.0
|
||||
isort>=5.10.1
|
||||
mypy>=0.961
|
||||
pytest>=7.1.2
|
||||
pytest-asyncio>=0.18.3
|
||||
types-PyYAML>=6.0.9
|
||||
types-setuptools>=62.6.0
|
|
@ -7,6 +7,10 @@
|
|||
# E731: do not assign a lambda expression, use a def
|
||||
# E501: Line too long (black enforces this for us)
|
||||
ignore=W503,W504,E203,E731,E501
|
||||
exclude =
|
||||
env
|
||||
.venv
|
||||
.env
|
||||
|
||||
[isort]
|
||||
line_length = 88
|
||||
|
|
38
setup.py
38
setup.py
|
@ -1,18 +1,11 @@
|
|||
#!/usr/bin/env python3
|
||||
import os
|
||||
from typing import Dict, Tuple, Any
|
||||
from typing import Tuple
|
||||
|
||||
import pkg_resources
|
||||
from setuptools import find_packages, setup
|
||||
|
||||
|
||||
def exec_file(path_segments: Tuple) -> Dict[str, Any]:
|
||||
"""Execute a single python file to get the variables defined in it"""
|
||||
result = {}
|
||||
code = read_file(path_segments)
|
||||
exec(code, result)
|
||||
return result
|
||||
|
||||
|
||||
def read_file(path_segments: Tuple) -> str:
|
||||
"""Read a file from the package. Takes a list of strings to join to
|
||||
make the path"""
|
||||
|
@ -21,7 +14,7 @@ def read_file(path_segments: Tuple) -> str:
|
|||
return f.read()
|
||||
|
||||
|
||||
version = exec_file(("matrix_alertbot", "__init__.py"))["__version__"]
|
||||
version = pkg_resources.require("matrix_alertbot")[0].version
|
||||
long_description = read_file(("README.md",))
|
||||
|
||||
|
||||
|
@ -32,26 +25,23 @@ setup(
|
|||
description="A matrix bot to do amazing things!",
|
||||
packages=find_packages(exclude=["tests", "tests.*"]),
|
||||
install_requires=[
|
||||
"matrix-nio[e2e]>=0.10.0",
|
||||
"Markdown>=3.1.1",
|
||||
"PyYAML>=5.1.2",
|
||||
"matrix-nio>=0.19.0",
|
||||
"Markdown>=3.3.7",
|
||||
"PyYAML>=6.0",
|
||||
"aiohttp-prometheus-exporter>=0.2.4",
|
||||
"aiotools>=1.5.9",
|
||||
"aiohttp>=3.8.1",
|
||||
"diskcache>=5.4.0",
|
||||
"pytimeparse>=1.1.8",
|
||||
],
|
||||
extras_require={
|
||||
"postgres": ["psycopg2>=2.8.5"],
|
||||
"dev": [
|
||||
"isort==5.0.4",
|
||||
"flake8==3.8.3",
|
||||
"flake8-comprehensions==3.2.3",
|
||||
"black==19.10b0",
|
||||
],
|
||||
"e2e": ["matrix-nio[e2e]>=0.19.0"],
|
||||
},
|
||||
classifiers=[
|
||||
"License :: OSI Approved :: Apache Software License",
|
||||
"Programming Language :: Python :: 3 :: Only",
|
||||
"Programming Language :: Python :: 3.5",
|
||||
"Programming Language :: Python :: 3.6",
|
||||
"Programming Language :: Python :: 3.7",
|
||||
"Programming Language :: Python :: 3.8",
|
||||
"Programming Language :: Python :: 3.9",
|
||||
"Programming Language :: Python :: 3.10",
|
||||
],
|
||||
long_description=long_description,
|
||||
long_description_content_type="text/markdown",
|
||||
|
|
|
@ -3,7 +3,7 @@ from __future__ import annotations
|
|||
import json
|
||||
import unittest
|
||||
from typing import Any
|
||||
from unittest.mock import MagicMock, Mock, patch
|
||||
from unittest.mock import MagicMock, Mock
|
||||
|
||||
import aiohttp
|
||||
import aiohttp.test_utils
|
||||
|
@ -280,14 +280,14 @@ class AlertmanagerClientTestCase(unittest.IsolatedAsyncioTestCase):
|
|||
await alertmanager.delete_silences("fingerprint2")
|
||||
|
||||
async def test_find_alert_happy(self) -> None:
|
||||
alertmanager = AlertmanagerClient(f"http://localhost", self.fake_cache)
|
||||
alertmanager = AlertmanagerClient("http://localhost", self.fake_cache)
|
||||
alert = alertmanager._find_alert(
|
||||
"fingerprint1", [{"fingerprint": "fingerprint1"}]
|
||||
)
|
||||
self.assertEqual({"fingerprint": "fingerprint1"}, alert)
|
||||
|
||||
async def test_find_alert_raise_alert_not_found(self) -> None:
|
||||
alertmanager = AlertmanagerClient(f"http://localhost", self.fake_cache)
|
||||
alertmanager = AlertmanagerClient("http://localhost", self.fake_cache)
|
||||
|
||||
with self.assertRaises(AlertNotFoundError):
|
||||
alertmanager._find_alert("fingerprint2", [{"fingerprint": "fingerprint1"}])
|
||||
|
|
Loading…
Reference in a new issue