Skip to content

Drop python 3.6 support #529

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Sep 21, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/pre-release-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: [3.6, 3.7, 3.8, 3.9, '3.10.0-beta - 3.10.0']
python-version: ["3.7", "3.8", "3.9", "3.10"]
name: integration-tests-against-rc
runs-on: ubuntu-latest
steps:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: [3.6, 3.7, 3.8, 3.9, '3.10.0-beta - 3.10.0']
python-version: ["3.7", "3.8", "3.9", "3.10"]
name: integration-tests
runs-on: ubuntu-latest
steps:
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ See our [Documentation](https://docs.meilisearch.com/learn/tutorials/getting_sta

## 🔧 Installation

**Note**: Python 3.6+ is required.
**Note**: Python 3.7+ is required.

With `pip3` in command line:

Expand Down
2 changes: 1 addition & 1 deletion bors.toml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
status = [
'pylint',
'mypy',
'integration-tests (3.6)',
'integration-tests (3.7)',
'integration-tests (3.8)',
'integration-tests (3.9)'
'integration-tests (3.10)'
]
# 1 hour timeout
timeout-sec = 3600
25 changes: 15 additions & 10 deletions meilisearch/_httprequests.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
from __future__ import annotations

import json
from typing import Any, Callable, Dict, List, Optional, Union
from typing import Any, Callable

import requests

from meilisearch.config import Config
from meilisearch.errors import (
MeiliSearchApiError,
Expand All @@ -9,6 +13,7 @@
)
from meilisearch.version import qualified_version


class HttpRequests:
def __init__(self, config: Config) -> None:
self.config = config
Expand All @@ -21,8 +26,8 @@ def send_request(
self,
http_method: Callable,
path: str,
body: Optional[Union[Dict[str, Any], List[Dict[str, Any]], List[str], str]] = None,
content_type: Optional[str] = None,
body: dict[str, Any] | list[dict[str, Any]] | list[str] | str | None = None,
content_type: str | None = None,
) -> Any:
if content_type:
self.headers['Content-Type'] = content_type
Expand Down Expand Up @@ -57,31 +62,31 @@ def get(
def post(
self,
path: str,
body: Optional[Union[Dict[str, Any], List[Dict[str, Any]], List[str], str]] = None,
content_type: Optional[str] = 'application/json',
body: dict[str, Any] | list[dict[str, Any]] | list[str] | str | None = None,
content_type: str | None = 'application/json',
) -> Any:
return self.send_request(requests.post, path, body, content_type)

def patch(
self,
path: str,
body: Optional[Union[Dict[str, Any], List[Dict[str, Any]], List[str], str]] = None,
content_type: Optional[str] = 'application/json',
body: dict[str, Any] | list[dict[str, Any]] | list[str] | str | None = None,
content_type: str | None = 'application/json',
) -> Any:
return self.send_request(requests.patch, path, body, content_type)

def put(
self,
path: str,
body: Optional[Union[Dict[str, Any], List[Dict[str, Any]], List[str]]] = None,
content_type: Optional[str] = 'application/json',
body: dict[str, Any] | list[dict[str, Any]] | list[str] | None = None,
content_type: str | None = 'application/json',
) -> Any:
return self.send_request(requests.put, path, body, content_type)

def delete(
self,
path: str,
body: Optional[Union[Dict[str, Any], List[Dict[str, Any]], List[str]]] = None,
body: dict[str, Any] | list[dict[str, Any]] | list[str] | None = None,
) -> Any:
return self.send_request(requests.delete, path, body)

Expand Down
64 changes: 34 additions & 30 deletions meilisearch/client.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
import re
from __future__ import annotations

import base64
import datetime
import hashlib
import hmac
import json
import datetime
import re
from typing import Any
from urllib import parse
from typing import Any, Dict, List, Optional, Union
from meilisearch.index import Index
from meilisearch.config import Config
from meilisearch.task import get_task, get_tasks, wait_for_task

from meilisearch._httprequests import HttpRequests
from meilisearch.config import Config
from meilisearch.errors import MeiliSearchError
from meilisearch.index import Index
from meilisearch.task import get_task, get_tasks, wait_for_task


class Client():
"""
Expand All @@ -21,7 +25,7 @@ class Client():
"""

def __init__(
self, url: str, api_key: Optional[str] = None, timeout: Optional[int] = None
self, url: str, api_key: str | None = None, timeout: int | None = None
) -> None:
"""
Parameters
Expand All @@ -35,7 +39,7 @@ def __init__(

self.http = HttpRequests(self.config)

def create_index(self, uid: str, options: Optional[Dict[str, Any]] = None) -> Dict[str, Any]:
def create_index(self, uid: str, options: dict[str, Any] | None = None) -> dict[str, Any]:
"""Create an index.

Parameters
Expand All @@ -58,7 +62,7 @@ def create_index(self, uid: str, options: Optional[Dict[str, Any]] = None) -> Di
"""
return Index.create(self.config, uid, options)

def delete_index(self, uid: str) -> Dict[str, Any]:
def delete_index(self, uid: str) -> dict[str, Any]:
"""Deletes an index

Parameters
Expand All @@ -80,7 +84,7 @@ def delete_index(self, uid: str) -> Dict[str, Any]:

return self.http.delete(f'{self.config.paths.index}/{uid}')

def get_indexes(self, parameters: Optional[Dict[str, Any]] = None) -> Dict[str, List[Index]]:
def get_indexes(self, parameters: dict[str, Any] | None = None) -> dict[str, list[Index]]:
"""Get all indexes.

Parameters
Expand Down Expand Up @@ -115,7 +119,7 @@ def get_indexes(self, parameters: Optional[Dict[str, Any]] = None) -> Dict[str,
]
return response

def get_raw_indexes(self, parameters: Optional[Dict[str, Any]] = None) -> List[Dict[str, Any]]:
def get_raw_indexes(self, parameters: dict[str, Any] | None = None) -> list[dict[str, Any]]:
"""Get all indexes in dictionary format.

Parameters
Expand Down Expand Up @@ -160,7 +164,7 @@ def get_index(self, uid: str) -> Index:
"""
return Index(self.config, uid).fetch_info()

def get_raw_index(self, uid: str) -> Dict[str, Any]:
def get_raw_index(self, uid: str) -> dict[str, Any]:
"""Get the index as a dictionary.
This index should already exist.

Expand Down Expand Up @@ -199,7 +203,7 @@ def index(self, uid: str) -> Index:
return Index(self.config, uid=uid)
raise Exception('The index UID should not be None')

def get_all_stats(self) -> Dict[str, Any]:
def get_all_stats(self) -> dict[str, Any]:
"""Get all stats of Meilisearch

Get information about database size and all indexes
Expand All @@ -217,7 +221,7 @@ def get_all_stats(self) -> Dict[str, Any]:
"""
return self.http.get(self.config.paths.stat)

def health(self) -> Dict[str, str]:
def health(self) -> dict[str, str]:
"""Get health of the Meilisearch server.

Returns
Expand All @@ -241,7 +245,7 @@ def is_healthy(self) -> bool:
return False
return True

def get_key(self, key_or_uid: str) -> Dict[str, Any]:
def get_key(self, key_or_uid: str) -> dict[str, Any]:
"""Gets information about a specific API key.

Parameters
Expand All @@ -262,7 +266,7 @@ def get_key(self, key_or_uid: str) -> Dict[str, Any]:
"""
return self.http.get(f'{self.config.paths.keys}/{key_or_uid}')

def get_keys(self, parameters: Optional[Dict[str, Any]] = None) -> Dict[str, Any]:
def get_keys(self, parameters: dict[str, Any] | None = None) -> dict[str, Any]:
"""Gets the Meilisearch API keys.

Parameters
Expand All @@ -289,8 +293,8 @@ def get_keys(self, parameters: Optional[Dict[str, Any]] = None) -> Dict[str, Any

def create_key(
self,
options: Dict[str, Any]
) -> Dict[str, Any]:
options: dict[str, Any]
) -> dict[str, Any]:
"""Creates a new API key.

Parameters
Expand Down Expand Up @@ -318,8 +322,8 @@ def create_key(
def update_key(
self,
key_or_uid: str,
options: Dict[str, Any]
) -> Dict[str, Any]:
options: dict[str, Any]
) -> dict[str, Any]:
"""Update an API key.

Parameters
Expand All @@ -345,7 +349,7 @@ def update_key(
url = f'{self.config.paths.keys}/{key_or_uid}'
return self.http.patch(url, options)

def delete_key(self, key_or_uid: str) -> Dict[str, int]:
def delete_key(self, key_or_uid: str) -> dict[str, int]:
"""Deletes an API key.

Parameters
Expand All @@ -366,7 +370,7 @@ def delete_key(self, key_or_uid: str) -> Dict[str, int]:
"""
return self.http.delete(f'{self.config.paths.keys}/{key_or_uid}')

def get_version(self) -> Dict[str, str]:
def get_version(self) -> dict[str, str]:
"""Get version Meilisearch

Returns
Expand All @@ -381,7 +385,7 @@ def get_version(self) -> Dict[str, str]:
"""
return self.http.get(self.config.paths.version)

def version(self) -> Dict[str, str]:
def version(self) -> dict[str, str]:
"""Alias for get_version

Returns
Expand All @@ -396,7 +400,7 @@ def version(self) -> Dict[str, str]:
"""
return self.get_version()

def create_dump(self) -> Dict[str, str]:
def create_dump(self) -> dict[str, str]:
"""Trigger the creation of a Meilisearch dump.

Returns
Expand All @@ -412,7 +416,7 @@ def create_dump(self) -> Dict[str, str]:
"""
return self.http.post(self.config.paths.dumps)

def get_tasks(self, parameters: Optional[Dict[str, Any]] = None) -> Dict[str, List[Dict[str, Any]]]:
def get_tasks(self, parameters: dict[str, Any] | None = None) -> dict[str, list[dict[str, Any]]]:
"""Get all tasks.

Parameters
Expand All @@ -433,7 +437,7 @@ def get_tasks(self, parameters: Optional[Dict[str, Any]] = None) -> Dict[str, Li
"""
return get_tasks(self.config, parameters=parameters)

def get_task(self, uid: int) -> Dict[str, Any]:
def get_task(self, uid: int) -> dict[str, Any]:
"""Get one task.

Parameters
Expand All @@ -457,7 +461,7 @@ def wait_for_task(
self, uid: int,
timeout_in_ms: int = 5000,
interval_in_ms: int = 50,
) -> Dict[str, Any]:
) -> dict[str, Any]:
"""Wait until Meilisearch processes a task until it fails or succeeds.

Parameters
Expand All @@ -484,10 +488,10 @@ def wait_for_task(
def generate_tenant_token(
self,
api_key_uid: str,
search_rules: Union[Dict[str, Any], List[str]],
search_rules: dict[str, Any] | list[str],
*,
expires_at: Optional[datetime.datetime] = None,
api_key: Optional[str] = None
expires_at: datetime.datetime | None = None,
api_key: str | None = None
) -> str:
"""Generate a JWT token for the use of multitenancy.

Expand Down
6 changes: 3 additions & 3 deletions meilisearch/config.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Optional
from __future__ import annotations


class Config:
Expand Down Expand Up @@ -33,8 +33,8 @@ class Paths():
def __init__(
self,
url: str,
api_key: Optional[str] = None,
timeout: Optional[int] = None
api_key: str | None = None,
timeout: int | None = None
) -> None:
"""
Parameters
Expand Down
3 changes: 3 additions & 0 deletions meilisearch/errors.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
from __future__ import annotations
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for this question but why did we import __future__ here if we did use it on this file?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Technically it isn't needed but it doesn't hurt anything to have it. I added it because I have had cases where I didn't put it, then later went back and added something that need it and forgot to import __future__. The issue there is python 3.10+ works without it so everything seems good, but then errors show up if you try to use < 3.10.

So it's just there as a future __future__ 😄 safety net. If you would rather remove I can.


import json

from requests import Response


class MeiliSearchError(Exception):
"""Generic class for Meilisearch error handling"""

Expand Down
Loading