Skip to content

Commit c8051c6

Browse files
authored
Merge branch 'main' into bump-meilisearch-v0.21.0
2 parents 59762f2 + d4045a1 commit c8051c6

28 files changed

+844
-310
lines changed

.code-samples.meilisearch.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ delete_one_document_1: |-
3737
client.index('movies').delete_document(25684)
3838
delete_documents_1: |-
3939
client.index('movies').delete_documents([23488, 153738, 437035, 363869])
40-
search_1: |-
40+
search_post_1: |-
4141
client.index('movies').search('American ninja')
4242
get_update_1: |-
4343
client.index('movies').get_update_status(1)

.github/ISSUE_TEMPLATE/bug_report.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ labels: ''
66
assignees: ''
77
---
88

9-
[comment]: <> (This is not an exhaustive model but a help. No step is mandatory.)
9+
<!-- This is not an exhaustive model but a help. No step is mandatory. -->
1010

1111
**Description**
1212
Description of what the bug is about.

.github/ISSUE_TEMPLATE/feature_request.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ labels: ''
66
assignees: ''
77
---
88

9-
[comment]: <> (This is not an exhaustive model but a help. No step is mandatory.)
9+
<!-- This is not an exhaustive model but a help. No step is mandatory. -->
1010

1111
**Description**
1212
Brief explanation of the feature.

.github/dependabot.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
version: 2
2+
updates:
3+
- package-ecosystem: pip
4+
directory: "/"
5+
schedule:
6+
interval: daily
7+
time: "04:00"
8+
open-pull-requests-limit: 10
9+
labels:
10+
- skip-changelog
11+
- dependencies
12+
rebase-strategy: disabled

.github/release-draft-template.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ sort-direction: 'ascending'
2121
replacers:
2222
- search: '/(?:and )?@dependabot-preview(?:\[bot\])?,?/g'
2323
replace: ''
24+
- search: '/(?:and )?@dependabot(?:\[bot\])?,?/g'
25+
replace: ''
2426
- search: '/(?:and )?@bors(?:\[bot\])?,?/g'
2527
replace: ''
2628
- search: '/(?:and )?@meili-bot,?/g'

.github/workflows/tests.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,19 @@ jobs:
5050
run: pipenv install --dev
5151
- name: Linter with pylint
5252
run: pipenv run pylint meilisearch
53+
54+
mypy:
55+
name: mypy
56+
runs-on: ubuntu-latest
57+
steps:
58+
- uses: actions/checkout@v1
59+
- name: Set up Python 3.9
60+
uses: actions/setup-python@v1
61+
with:
62+
python-version: 3.9
63+
- name: Install pipenv
64+
uses: dschep/install-pipenv-action@v1
65+
- name: Install dependencies
66+
run: pipenv install --dev
67+
- name: mypy type check
68+
run: pipenv run mypy meilisearch

CONTRIBUTING.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,18 +34,20 @@ pipenv install --dev
3434

3535
### Tests and Linter <!-- omit in toc -->
3636

37-
Each PR should pass the tests and the linter to be accepted.
37+
Each PR should pass the tests, mypy type checking, and the linter to be accepted.
3838

3939
```bash
4040
# Tests
4141
docker pull getmeili/meilisearch:latest # Fetch the latest version of MeiliSearch image from Docker Hub
4242
docker run -p 7700:7700 getmeili/meilisearch:latest ./meilisearch --master-key=masterKey --no-analytics=true
4343
pipenv run pytest meilisearch
44+
# MyPy
45+
pipenv run mypy meilisearch
4446
# Linter
4547
pipenv run pylint meilisearch
4648
```
4749

48-
Optionally tox can be used to run test on all supported version of Python and linting.
50+
Optionally tox can be used to run test on all supported version of Python, mypy, and linting.
4951

5052
```bash
5153
docker pull getmeili/meilisearch:latest # Fetch the latest version of MeiliSearch image from Docker Hub

Pipfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,14 @@ url = "https://pypi.org/simple"
44
verify_ssl = true
55

66
[dev-packages]
7+
mypy = "*"
78
pylint = "*"
89
pytest = "*"
910
pdoc3 = "*"
1011
pytest-ordering = "*"
1112
tox = "*"
1213
tox-pipenv = "*"
14+
types-requests = "*"
1315

1416
[packages]
1517
requests = "*"

Pipfile.lock

Lines changed: 141 additions & 88 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

bors.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
status = [
22
'pylint',
3+
'mypy',
34
'integration-tests (3.6)',
45
'integration-tests (3.7)',
56
'integration-tests (3.8)',

meilisearch/_httprequests.py

Lines changed: 43 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,67 +1,82 @@
1+
import json
2+
from typing import Any, Callable, Dict, List, Optional, Union
13
import requests
4+
from meilisearch.config import Config
25
from meilisearch.errors import (
36
MeiliSearchApiError,
47
MeiliSearchCommunicationError,
58
MeiliSearchTimeoutError,
69
)
710

811
class HttpRequests:
9-
10-
config = None
11-
headers = {}
12-
13-
def __init__(self, config):
12+
def __init__(self, config: Config) -> None:
1413
self.config = config
1514
self.headers = {
1615
'X-Meili-Api-Key': self.config.api_key,
1716
'Content-Type': 'application/json'
1817
}
1918

20-
def send_request(self, http_method, path, body=None):
19+
def send_request(
20+
self,
21+
http_method: Callable,
22+
path: str,
23+
body: Optional[Union[Dict[str, Any], List[Dict[str, Any]], List[str]]] = None,
24+
) -> Any:
2125
try:
2226
request_path = self.config.url + '/' + path
23-
if body is None:
24-
request = http_method(
25-
request_path,
26-
timeout=self.config.timeout,
27-
headers=self.headers,
28-
)
29-
else:
30-
request = http_method(
31-
request_path,
32-
timeout=self.config.timeout,
33-
headers=self.headers,
34-
json=body,
35-
)
27+
request = http_method(
28+
request_path,
29+
timeout=self.config.timeout,
30+
headers=self.headers,
31+
data=json.dumps(body) if body else "null"
32+
)
3633
return self.__validate(request)
3734

3835
except requests.exceptions.Timeout as err:
39-
raise MeiliSearchTimeoutError(err) from err
36+
raise MeiliSearchTimeoutError(str(err)) from err
4037
except requests.exceptions.ConnectionError as err:
41-
raise MeiliSearchCommunicationError(err) from err
38+
raise MeiliSearchCommunicationError(str(err)) from err
4239

43-
def get(self, path):
40+
def get(
41+
self, path: str
42+
) -> Any:
4443
return self.send_request(requests.get, path)
4544

46-
def post(self, path, body=None):
45+
def post(
46+
self,
47+
path: str,
48+
body: Optional[Union[Dict[str, Any], List[Dict[str, Any]], List[str]]] = None,
49+
) -> Any:
4750
return self.send_request(requests.post, path, body)
4851

49-
def put(self, path, body=None):
52+
def put(
53+
self,
54+
path: str,
55+
body: Optional[Union[Dict[str, Any], List[Dict[str, Any]], List[str]]] = None,
56+
) -> Any:
5057
return self.send_request(requests.put, path, body)
5158

52-
def delete(self, path, body=None):
59+
def delete(
60+
self,
61+
path: str,
62+
body: Optional[Union[Dict[str, Any], List[Dict[str, Any]], List[str]]] = None,
63+
) -> Any:
5364
return self.send_request(requests.delete, path, body)
5465

5566
@staticmethod
56-
def __to_json(request):
67+
def __to_json(
68+
request: requests.Response
69+
) -> Any:
5770
if request.content == b'':
5871
return request
5972
return request.json()
6073

6174
@staticmethod
62-
def __validate(request):
75+
def __validate(
76+
request: requests.Response
77+
) -> Any:
6378
try:
6479
request.raise_for_status()
6580
return HttpRequests.__to_json(request)
6681
except requests.exceptions.HTTPError as err:
67-
raise MeiliSearchApiError(err, request) from err
82+
raise MeiliSearchApiError(str(err), request) from err

0 commit comments

Comments
 (0)