update requirements

This commit is contained in:
HgO 2022-07-09 15:25:16 +02:00
parent f3151cee4c
commit 6f55d39fb6
8 changed files with 53 additions and 33 deletions

View file

@ -1,7 +1,7 @@
from __future__ import annotations from __future__ import annotations
import datetime import datetime
from typing import Any, Dict, List from typing import Dict, List
import aiohttp import aiohttp
import pytimeparse import pytimeparse
@ -32,7 +32,7 @@ class AlertmanagerClient:
return await response.json() return await response.json()
except ClientError as e: except ClientError as e:
raise AlertmanagerServerError( raise AlertmanagerServerError(
f"Cannot fetch alerts from Alertmanager" "Cannot fetch alerts from Alertmanager"
) from e ) from e
async def get_alert(self, fingerprint: str) -> Dict: async def get_alert(self, fingerprint: str) -> Dict:

View file

@ -13,8 +13,8 @@ from nio import (
) )
from matrix_alertbot.alertmanager import AlertmanagerClient 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.chat_functions import make_pill, send_text_to_room, strip_fallback
from matrix_alertbot.command import Command
from matrix_alertbot.config import Config from matrix_alertbot.config import Config
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)

View file

@ -1,11 +1,24 @@
import logging import logging
from typing import Optional, Union from typing import Dict, Optional, TypedDict, Union
from nio import AsyncClient, ErrorResponse, Response, RoomSendResponse, SendRetryError from nio import AsyncClient, ErrorResponse, Response, RoomSendResponse, SendRetryError
from typing_extensions import NotRequired
logger = logging.getLogger(__name__) 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( async def send_text_to_room(
client: AsyncClient, client: AsyncClient,
room_id: str, room_id: str,
@ -37,7 +50,7 @@ async def send_text_to_room(
# Determine whether to ping room members or not # Determine whether to ping room members or not
msgtype = "m.notice" if notice else "m.text" msgtype = "m.notice" if notice else "m.text"
content = { content: ContentEventDict = {
"msgtype": msgtype, "msgtype": msgtype,
"format": "org.matrix.custom.html", "format": "org.matrix.custom.html",
"body": plaintext, "body": plaintext,

View file

@ -2,4 +2,7 @@
ignore_missing_imports = True ignore_missing_imports = True
disallow_untyped_defs = True disallow_untyped_defs = True
disallow_untyped_calls = True disallow_untyped_calls = True
plugins = sqlalchemy.ext.mypy.plugin exclude =
env
.env
.venv

10
requirements.txt Normal file
View 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

View file

@ -7,6 +7,10 @@
# E731: do not assign a lambda expression, use a def # E731: do not assign a lambda expression, use a def
# E501: Line too long (black enforces this for us) # E501: Line too long (black enforces this for us)
ignore=W503,W504,E203,E731,E501 ignore=W503,W504,E203,E731,E501
exclude =
env
.venv
.env
[isort] [isort]
line_length = 88 line_length = 88

View file

@ -1,18 +1,11 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
import os import os
from typing import Dict, Tuple, Any from typing import Tuple
import pkg_resources
from setuptools import find_packages, setup 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: def read_file(path_segments: Tuple) -> str:
"""Read a file from the package. Takes a list of strings to join to """Read a file from the package. Takes a list of strings to join to
make the path""" make the path"""
@ -21,7 +14,7 @@ def read_file(path_segments: Tuple) -> str:
return f.read() 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",)) long_description = read_file(("README.md",))
@ -32,26 +25,23 @@ setup(
description="A matrix bot to do amazing things!", description="A matrix bot to do amazing things!",
packages=find_packages(exclude=["tests", "tests.*"]), packages=find_packages(exclude=["tests", "tests.*"]),
install_requires=[ install_requires=[
"matrix-nio[e2e]>=0.10.0", "matrix-nio>=0.19.0",
"Markdown>=3.1.1", "Markdown>=3.3.7",
"PyYAML>=5.1.2", "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={ extras_require={
"postgres": ["psycopg2>=2.8.5"], "e2e": ["matrix-nio[e2e]>=0.19.0"],
"dev": [
"isort==5.0.4",
"flake8==3.8.3",
"flake8-comprehensions==3.2.3",
"black==19.10b0",
],
}, },
classifiers=[ classifiers=[
"License :: OSI Approved :: Apache Software License", "License :: OSI Approved :: Apache Software License",
"Programming Language :: Python :: 3 :: Only", "Programming Language :: Python :: 3 :: Only",
"Programming Language :: Python :: 3.5", "Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.6", "Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
], ],
long_description=long_description, long_description=long_description,
long_description_content_type="text/markdown", long_description_content_type="text/markdown",

View file

@ -3,7 +3,7 @@ from __future__ import annotations
import json import json
import unittest import unittest
from typing import Any from typing import Any
from unittest.mock import MagicMock, Mock, patch from unittest.mock import MagicMock, Mock
import aiohttp import aiohttp
import aiohttp.test_utils import aiohttp.test_utils
@ -280,14 +280,14 @@ class AlertmanagerClientTestCase(unittest.IsolatedAsyncioTestCase):
await alertmanager.delete_silences("fingerprint2") await alertmanager.delete_silences("fingerprint2")
async def test_find_alert_happy(self) -> None: 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( alert = alertmanager._find_alert(
"fingerprint1", [{"fingerprint": "fingerprint1"}] "fingerprint1", [{"fingerprint": "fingerprint1"}]
) )
self.assertEqual({"fingerprint": "fingerprint1"}, alert) self.assertEqual({"fingerprint": "fingerprint1"}, alert)
async def test_find_alert_raise_alert_not_found(self) -> None: 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): with self.assertRaises(AlertNotFoundError):
alertmanager._find_alert("fingerprint2", [{"fingerprint": "fingerprint1"}]) alertmanager._find_alert("fingerprint2", [{"fingerprint": "fingerprint1"}])