diff --git a/.envrc b/.envrc
index 716ab6e..ea3e336 100644
--- a/.envrc
+++ b/.envrc
@@ -1,2 +1,3 @@
source venv/bin/activate
+pre-commit install
diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml
new file mode 100644
index 0000000..e3ab068
--- /dev/null
+++ b/.pre-commit-config.yaml
@@ -0,0 +1,11 @@
+repos:
+ - repo: https://github.com/charliermarsh/ruff-pre-commit
+ rev: 'v0.2.1'
+ hooks:
+ - id: ruff
+ args: ['--fix']
+
+ - repo: https://github.com/pre-commit/mirrors-autopep8
+ rev: 'v2.0.4'
+ hooks:
+ - id: autopep8
diff --git a/http_request_recorder/__init__.py b/http_request_recorder/__init__.py
index 768ec60..72cf5b3 100644
--- a/http_request_recorder/__init__.py
+++ b/http_request_recorder/__init__.py
@@ -1 +1 @@
-from .http_request_recorder import HttpRequestRecorder # noqa: F401
+from .http_request_recorder import HttpRequestRecorder # noqa: F401
diff --git a/http_request_recorder/http_request_recorder.py b/http_request_recorder/http_request_recorder.py
index b074b87..969e2ce 100644
--- a/http_request_recorder/http_request_recorder.py
+++ b/http_request_recorder/http_request_recorder.py
@@ -4,7 +4,7 @@
from asyncio import Event
from itertools import tee
from logging import getLogger
-from typing import Iterable, Union
+from typing import Iterable
from collections.abc import Callable
from aiohttp import web
@@ -52,7 +52,8 @@ def __init__(self, matcher: Callable[[RecordedRequest], bool], responses: Respon
if hasattr(responses, "__len__"):
self.expected_count = sum(1 for _ in responses)
else:
- raise TypeError("responses must be str | bytes | web.Response | Iterable[str] | Iterable[bytes] | Iterable[web.Response]")
+ raise TypeError(
+ "responses must be str | bytes | web.Response | Iterable[str] | Iterable[bytes] | Iterable[web.Response]")
self._recorded = []
self._next_for_response, self._next_to_return = tee(self.responses)
@@ -141,7 +142,8 @@ async def handle_request(self, request: BaseRequest):
recorded_request = await RecordedRequest.from_base_request(request)
- matches = [exp for exp in self._expectations if exp.can_respond(recorded_request)]
+ matches = [exp for exp in self._expectations if exp.can_respond(
+ recorded_request)]
if len(matches) == 0:
self._logger.warning(f"{self} got unexpected {await self._request_string_for_log(request)}")
self._unexpected_requests.append(recorded_request)
@@ -188,7 +190,8 @@ def unexpected_requests(self) -> list[RecordedRequest]:
async def _request_string_for_log(request):
request_body = await request.read()
- xml_rpc_method = re.search(b".*?", request_body)
+ xml_rpc_method = re.search(
+ b".*?", request_body)
if xml_rpc_method is not None:
return f"{request.method} - XmlRpc - {xml_rpc_method.group(0).decode('UTF-8')}"
diff --git a/requirements.txt b/requirements.txt
index dc9afb6..e694621 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -1,2 +1,3 @@
aiohttp~=3.8.4
-types-setuptools
\ No newline at end of file
+types-setuptools
+pre-commit
\ No newline at end of file
diff --git a/setup.py b/setup.py
index 0036795..e411694 100644
--- a/setup.py
+++ b/setup.py
@@ -23,4 +23,4 @@
'aiohttp~=3.8.4',
],
zip_safe=False
-)
\ No newline at end of file
+)