Skip to content

Commit

Permalink
Merge branch 'main' into bump-meilisearch-v0.29.0
Browse files Browse the repository at this point in the history
  • Loading branch information
alallema authored Oct 3, 2022
2 parents d3143b3 + 1ccc1b7 commit 6c2d1f2
Show file tree
Hide file tree
Showing 26 changed files with 323 additions and 311 deletions.
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
15 changes: 14 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,25 @@

First of all, thank you for contributing to Meilisearch! The goal of this document is to provide everything you need to know in order to contribute to Meilisearch and its different integrations.

- [Hacktoberfest](#hacktoberfest-2022)
- [Assumptions](#assumptions)
- [How to Contribute](#how-to-contribute)
- [Development Workflow](#development-workflow)
- [Git Guidelines](#git-guidelines)
- [Release Process (for internal team only)](#release-process-for-internal-team-only)

## Hacktoberfest 2022

It's [Hacktoberfest month](https://hacktoberfest.com)! 🥳

Thanks so much for participating with Meilisearch this year!

1. We will follow the quality standards set by the organizers of Hacktoberfest (see detail on their [website](https://hacktoberfest.digitalocean.com/resources/qualitystandards)). Our reviewers will not consider any PR that doesn’t match that standard.
2. PRs reviews will take place from Monday to Thursday, during usual working hours, CEST time. If you submit outside of these hours, there’s no need to panic; we will get around to your contribution.
3. There will be no issue assignment as we don’t want people to ask to be assigned specific issues and never return, discouraging the volunteer contributors from opening a PR to fix this issue. We take the liberty to choose the PR that best fixes the issue, so we encourage you to get to it as soon as possible and do your best!

You can check out the longer, more complete guideline documentation [here](https://github.com/meilisearch/.github/blob/main/Hacktoberfest_2022_contributors_guidelines.md).

## Assumptions

1. **You're familiar with [GitHub](https://github.com) and the [Pull Request](https://help.github.com/en/github/collaborating-with-issues-and-pull-requests/about-pull-requests)(PR) workflow.**
Expand All @@ -32,7 +45,7 @@ You can set up your local environment natively or using `docker`, check out the

Example of running all the checks with docker:
```bash
docker-compose run --rm package bash -c "pipenv run mypy meilisearch && pipenv run pylint meilisearch && pipenv run pytest tests"
docker-compose run --rm package bash -c "pipenv install --dev && pipenv run mypy meilisearch && pipenv run pylint meilisearch && pipenv run pytest tests"
```

To install dependencies:
Expand Down
283 changes: 125 additions & 158 deletions Pipfile.lock

Large diffs are not rendered by default.

11 changes: 10 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,29 @@

## Table of Contents <!-- omit in toc -->

- [🎃 Hacktoberfest](#-hacktoberfest)
- [📖 Documentation](#-documentation)
- [🔧 Installation](#-installation)
- [🚀 Getting Started](#-getting-started)
- [🤖 Compatibility with Meilisearch](#-compatibility-with-meilisearch)
- [💡 Learn More](#-learn-more)
- [⚙️ Development Workflow and Contributing](#️-development-workflow-and-contributing)

## 🎃 Hacktoberfest

It’s Hacktoberfest 2022 @Meilisearch

[Hacktoberfest](https://hacktoberfest.com/) is a celebration of the open-source community. This year, and for the third time in a row, Meilisearch is participating in this fantastic event.

You’d like to contribute? Don’t hesitate to check out our [contributing guidelines](./CONTRIBUTING.md).

## 📖 Documentation

See our [Documentation](https://docs.meilisearch.com/learn/tutorials/getting_started.html) or our [API References](https://docs.meilisearch.com/reference/api/).

## 🔧 Installation

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

With `pip3` in command line:

Expand Down
4 changes: 2 additions & 2 deletions 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.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
Loading

0 comments on commit 6c2d1f2

Please sign in to comment.