From 03128b9a58a325f1df0f5886441edc9854d9ec36 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Leynier=20Guti=C3=A9rrez=20Gonz=C3=A1lez?= Date: Wed, 17 Nov 2021 01:53:30 +0000 Subject: [PATCH 1/2] fix: interpolations erros and other things reported by sourcery-ai --- CODE_OF_CONDUCT.md | 22 ++++++++++------------ CONTRIBUTING.md | 2 +- Makefile | 17 +++++++++++++++++ postgrest_py/_async/client.py | 3 +-- postgrest_py/_async/request_builder.py | 8 ++++---- postgrest_py/_sync/client.py | 3 +-- postgrest_py/_sync/request_builder.py | 8 ++++---- tests/_async/test_request_builder.py | 4 ++-- tests/_sync/test_request_builder.py | 4 ++-- 9 files changed, 42 insertions(+), 29 deletions(-) create mode 100644 Makefile diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md index ace8809a..c42431d6 100644 --- a/CODE_OF_CONDUCT.md +++ b/CODE_OF_CONDUCT.md @@ -14,21 +14,21 @@ appearance, race, religion, or sexual identity and orientation. Examples of behavior that contributes to creating a positive environment include: -* Using welcoming and inclusive language -* Being respectful of differing viewpoints and experiences -* Gracefully accepting constructive criticism -* Focusing on what is best for the community -* Showing empathy towards other community members +- Using welcoming and inclusive language +- Being respectful of differing viewpoints and experiences +- Gracefully accepting constructive criticism +- Focusing on what is best for the community +- Showing empathy towards other community members Examples of unacceptable behavior by participants include: -* The use of sexualized language or imagery and unwelcome sexual attention or +- The use of sexualized language or imagery and unwelcome sexual attention or advances -* Trolling, insulting/derogatory comments, and personal or political attacks -* Public or private harassment -* Publishing others' private information, such as a physical or electronic +- Trolling, insulting/derogatory comments, and personal or political attacks +- Public or private harassment +- Publishing others' private information, such as a physical or electronic address, without explicit permission -* Other conduct which could reasonably be considered inappropriate in a +- Other conduct which could reasonably be considered inappropriate in a professional setting ## Our Responsibilities @@ -74,5 +74,3 @@ available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.ht For answers to common questions about this code of conduct, see https://www.contributor-covenant.org/faq - - diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 559a740a..04b91429 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -29,4 +29,4 @@ When making pull requests to the repository, make sure to follow these guideline - In your PR's description, link to any related issues or pull requests to give reviewers the full context of your change. - For commit messages, follow the [Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/) format. - For example, if you update documentation for a specific extension, your commit message might be: `docs(extension-name) updated installation documentation`. -diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md + diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md diff --git a/Makefile b/Makefile new file mode 100644 index 00000000..d05bd9a4 --- /dev/null +++ b/Makefile @@ -0,0 +1,17 @@ +install: install_poetry + poetry install + +install_poetry: + curl -sSL https://install.python-poetry.org | python - + +precommit: install + poetry run pre-commit run --all-files + +tests: install + poetry run pytest --cov=./ --cov-report=xml -vv + +build: install + poetry run unasync postgrest_py tests + +clean: + sudo rm -r .venv diff --git a/postgrest_py/_async/client.py b/postgrest_py/_async/client.py index 1fa1acbb..e1c11dc8 100644 --- a/postgrest_py/_async/client.py +++ b/postgrest_py/_async/client.py @@ -76,5 +76,4 @@ def from_table(self, table: str) -> AsyncRequestBuilder: async def rpc(self, func: str, params: dict) -> Response: """Perform a stored procedure call.""" path = f"/rpc/{func}" - r = await self.session.post(path, json=params) - return r + return await self.session.post(path, json=params) diff --git a/postgrest_py/_async/request_builder.py b/postgrest_py/_async/request_builder.py index aa7e99c4..9c6ce9c8 100644 --- a/postgrest_py/_async/request_builder.py +++ b/postgrest_py/_async/request_builder.py @@ -144,17 +144,17 @@ def in_(self, column: str, values: Iterable[str]): def cs(self, column: str, values: Iterable[str]): values = map(sanitize_param, values) values = ",".join(values) - return self.filter(column, "cs", f"{{values}}") + return self.filter(column, "cs", f"{{{values}}}") def cd(self, column: str, values: Iterable[str]): values = map(sanitize_param, values) values = ",".join(values) - return self.filter(column, "cd", f"{{values}}") + return self.filter(column, "cd", f"{{{values}}}") def ov(self, column: str, values: Iterable[str]): values = map(sanitize_param, values) values = ",".join(values) - return self.filter(column, "ov", f"{{values}}") + return self.filter(column, "ov", f"{{{values}}}") def sl(self, column: str, range: Tuple[int, int]): return self.filter(column, "sl", f"({range[0]},{range[1]})") @@ -173,7 +173,7 @@ def adj(self, column: str, range: Tuple[int, int]): def match(self, query: Dict[str, Any]): updated_query = None - for key in query.keys(): + for key in query: value = query.get(key, "") updated_query = self.eq(key, value) return updated_query diff --git a/postgrest_py/_sync/client.py b/postgrest_py/_sync/client.py index db2948ef..898d4c6e 100644 --- a/postgrest_py/_sync/client.py +++ b/postgrest_py/_sync/client.py @@ -76,5 +76,4 @@ def from_table(self, table: str) -> SyncRequestBuilder: def rpc(self, func: str, params: dict) -> Response: """Perform a stored procedure call.""" path = f"/rpc/{func}" - r = self.session.post(path, json=params) - return r + return self.session.post(path, json=params) diff --git a/postgrest_py/_sync/request_builder.py b/postgrest_py/_sync/request_builder.py index cb1d979c..08c784b1 100644 --- a/postgrest_py/_sync/request_builder.py +++ b/postgrest_py/_sync/request_builder.py @@ -144,17 +144,17 @@ def in_(self, column: str, values: Iterable[str]): def cs(self, column: str, values: Iterable[str]): values = map(sanitize_param, values) values = ",".join(values) - return self.filter(column, "cs", f"{{values}}") + return self.filter(column, "cs", f"{{{values}}}") def cd(self, column: str, values: Iterable[str]): values = map(sanitize_param, values) values = ",".join(values) - return self.filter(column, "cd", f"{{values}}") + return self.filter(column, "cd", f"{{{values}}}") def ov(self, column: str, values: Iterable[str]): values = map(sanitize_param, values) values = ",".join(values) - return self.filter(column, "ov", f"{{values}}") + return self.filter(column, "ov", f"{{{values}}}") def sl(self, column: str, range: Tuple[int, int]): return self.filter(column, "sl", f"({range[0]},{range[1]})") @@ -173,7 +173,7 @@ def adj(self, column: str, range: Tuple[int, int]): def match(self, query: Dict[str, Any]): updated_query = None - for key in query.keys(): + for key in query: value = query.get(key, "") updated_query = self.eq(key, value) return updated_query diff --git a/tests/_async/test_request_builder.py b/tests/_async/test_request_builder.py index bb77c764..2ea19dbd 100644 --- a/tests/_async/test_request_builder.py +++ b/tests/_async/test_request_builder.py @@ -19,14 +19,14 @@ def test_select(self, request_builder: AsyncRequestBuilder): builder = request_builder.select("col1", "col2") assert builder.session.params["select"] == "col1,col2" - assert builder.session.headers.get("prefer") == None + assert builder.session.headers.get("prefer") is None assert builder.http_method == "GET" assert builder.json == {} def test_select_with_count(self, request_builder: AsyncRequestBuilder): builder = request_builder.select(count="exact") - assert builder.session.params.get("select") == None + assert builder.session.params.get("select") is None assert builder.session.headers["prefer"] == "count=exact" assert builder.http_method == "HEAD" assert builder.json == {} diff --git a/tests/_sync/test_request_builder.py b/tests/_sync/test_request_builder.py index 1eedae7a..61a53375 100644 --- a/tests/_sync/test_request_builder.py +++ b/tests/_sync/test_request_builder.py @@ -19,14 +19,14 @@ def test_select(self, request_builder: SyncRequestBuilder): builder = request_builder.select("col1", "col2") assert builder.session.params["select"] == "col1,col2" - assert builder.session.headers.get("prefer") == None + assert builder.session.headers.get("prefer") is None assert builder.http_method == "GET" assert builder.json == {} def test_select_with_count(self, request_builder: SyncRequestBuilder): builder = request_builder.select(count="exact") - assert builder.session.params.get("select") == None + assert builder.session.params.get("select") is None assert builder.session.headers["prefer"] == "count=exact" assert builder.http_method == "HEAD" assert builder.json == {} From 5fd13a09860e23187431564997142fbcc7dd62ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Leynier=20Guti=C3=A9rrez=20Gonz=C3=A1lez?= Date: Sun, 2 Jan 2022 18:12:31 +0000 Subject: [PATCH 2/2] chore: bump version to v0.7.0 --- postgrest_py/__version__.py | 2 +- postgrest_py/_async/client.py | 2 +- postgrest_py/_sync/client.py | 2 +- pyproject.toml | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/postgrest_py/__version__.py b/postgrest_py/__version__.py index 906d362f..49e0fc1e 100644 --- a/postgrest_py/__version__.py +++ b/postgrest_py/__version__.py @@ -1 +1 @@ -__version__ = "0.6.0" +__version__ = "0.7.0" diff --git a/postgrest_py/_async/client.py b/postgrest_py/_async/client.py index aa0a90ce..502a36de 100644 --- a/postgrest_py/_async/client.py +++ b/postgrest_py/_async/client.py @@ -45,7 +45,7 @@ async def aclose(self) -> None: def from_(self, table: str) -> AsyncRequestBuilder: """Perform a table operation.""" return AsyncRequestBuilder(self.session, f"/{table}") - + def table(self, table: str) -> AsyncRequestBuilder: """Alias to self.from_().""" return self.from_(table) diff --git a/postgrest_py/_sync/client.py b/postgrest_py/_sync/client.py index 192271cd..d3672db7 100644 --- a/postgrest_py/_sync/client.py +++ b/postgrest_py/_sync/client.py @@ -45,7 +45,7 @@ def aclose(self) -> None: def from_(self, table: str) -> SyncRequestBuilder: """Perform a table operation.""" return SyncRequestBuilder(self.session, f"/{table}") - + def table(self, table: str) -> SyncRequestBuilder: """Alias to self.from_().""" return self.from_(table) diff --git a/pyproject.toml b/pyproject.toml index 46fc536f..a8fdce69 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,7 +1,7 @@ [tool.poetry] name = "postgrest-py" description = "PostgREST client for Python. This library provides an ORM interface to PostgREST." -version = "0.6.0" +version = "0.7.0" authors = ["Lương Quang Mạnh "] license = "MIT" readme = "README.md"