Skip to content

Inconsistencies fix #564

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 14 commits into from
Oct 20, 2022
Merged
Show file tree
Hide file tree
Changes from all 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
5 changes: 5 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ pipenv install --dev
### Tests and Linter <!-- omit in toc -->

Each PR should pass the tests, mypy type checking, and the linter to be accepted.
Your PR also needs to be formatted using black and isort.

```bash
# Tests
Expand All @@ -67,6 +68,10 @@ pipenv run pytest tests
pipenv run mypy meilisearch
# Linter
pipenv run pylint meilisearch
# Black
pipenv run black meilisearch tests
# Isort
pipenv run isort meilisearch tests
```

Optionally tox can be used to run test on all supported version of Python, mypy, and linting.
Expand Down
2 changes: 2 additions & 0 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ pytest-ordering = "*"
tox = "*"
tox-pipenv = "*"
types-requests = "*"
black = "*"
isort = "*"

[packages]
requests = "*"
Expand Down
81 changes: 62 additions & 19 deletions Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 12 additions & 11 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,14 @@
#
import os
import sys
sys.path.insert(0, os.path.abspath('..'))

sys.path.insert(0, os.path.abspath(".."))

# -- Project information -----------------------------------------------------

project = 'meilisearch-python'
copyright = '2019, Meili SAS'
author = 'Charlotte Vermandel'
project = "meilisearch-python"
copyright = "2019, Meili SAS"
author = "Charlotte Vermandel"


# -- General configuration ---------------------------------------------------
Expand All @@ -27,27 +28,27 @@
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.
extensions = [
'sphinx.ext.autodoc',
'sphinx.ext.napoleon',
'sphinx.ext.viewcode',
"sphinx.ext.autodoc",
"sphinx.ext.napoleon",
"sphinx.ext.viewcode",
]

# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']
templates_path = ["_templates"]

# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
# This pattern also affects html_static_path and html_extra_path.
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']
exclude_patterns = ["_build", "Thumbs.db", ".DS_Store"]


# -- Options for HTML output -------------------------------------------------

# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
#
html_theme = 'sphinx_rtd_theme'
#html_theme = 'alabaster'
html_theme = "sphinx_rtd_theme"
# html_theme = 'alabaster'

# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
Expand Down
32 changes: 13 additions & 19 deletions meilisearch/_httprequests.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ class HttpRequests:
def __init__(self, config: Config) -> None:
self.config = config
self.headers = {
'Authorization': f'Bearer {self.config.api_key}',
'User-Agent': qualified_version(),
"Authorization": f"Bearer {self.config.api_key}",
"User-Agent": qualified_version(),
}

def send_request(
Expand All @@ -30,22 +30,22 @@ def send_request(
content_type: str | None = None,
) -> Any:
if content_type:
self.headers['Content-Type'] = content_type
self.headers["Content-Type"] = content_type
try:
request_path = self.config.url + '/' + path
request_path = self.config.url + "/" + path
if isinstance(body, bytes):
request = http_method(
request_path,
timeout=self.config.timeout,
headers=self.headers,
data=body
data=body,
)
else:
request = http_method(
request_path,
timeout=self.config.timeout,
headers=self.headers,
data=json.dumps(body) if body else "null"
data=json.dumps(body) if body else "null",
)
return self.__validate(request)

Expand All @@ -54,32 +54,30 @@ def send_request(
except requests.exceptions.ConnectionError as err:
raise MeiliSearchCommunicationError(str(err)) from err

def get(
self, path: str
) -> Any:
def get(self, path: str) -> Any:
return self.send_request(requests.get, path)

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

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

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

Expand All @@ -91,17 +89,13 @@ def delete(
return self.send_request(requests.delete, path, body)

@staticmethod
def __to_json(
request: requests.Response
) -> Any:
if request.content == b'':
def __to_json(request: requests.Response) -> Any:
if request.content == b"":
return request
return request.json()

@staticmethod
def __validate(
request: requests.Response
) -> Any:
def __validate(request: requests.Response) -> Any:
try:
request.raise_for_status()
return HttpRequests.__to_json(request)
Expand Down
Loading