Skip to content

Commit

Permalink
Merge pull request #10 from FreeLeh/update-requests-lib-requirements
Browse files Browse the repository at this point in the history
Update the requests dependency version requirements
  • Loading branch information
edocsss authored Jun 28, 2024
2 parents cf78ca5 + d6d88d8 commit 0011a37
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,6 @@ cython_debug/
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/
.idea/

.vscode/
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ dependencies = [
"google-api-python-client==2.51.0",
"google-auth-httplib2==0.1.0",
"google-auth-oauthlib==0.5.2",
"requests==2.28.1"
"requests>=2.28.1, < 3"
]

[project.urls]
Expand Down Expand Up @@ -50,6 +50,7 @@ include = '\.pyi?$'
strict = true
ignore_missing_imports = true
disallow_subclassing_any = false
disallow_untyped_calls = false

[tool.pytest.ini_options]
markers = [
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
google-api-python-client==2.51.0
google-auth-httplib2==0.1.0
google-auth-oauthlib==0.5.2
requests==2.28
requests>=2.30, <3
black==22.3.0
mypy==0.961
isort==5.10.1
Expand Down
2 changes: 1 addition & 1 deletion src/pyfreedb/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
"""PyFreeDB is a Python library that provides common and simple database abstractions on top of Google Sheets."""

__version__ = "1.0.1"
__version__ = "1.0.2"
5 changes: 3 additions & 2 deletions src/pyfreedb/providers/google/auth/base.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import abc
from typing import Union

from google.oauth2.credentials import Credentials
from google.oauth2 import credentials, service_account


class GoogleAuthClient(abc.ABC):
"""An abstraction layer that represents way to authenticate with Google APIs."""

@abc.abstractmethod
def credentials(self) -> Credentials:
def credentials(self) -> Union[credentials.Credentials, service_account.Credentials]:
pass
7 changes: 4 additions & 3 deletions src/pyfreedb/providers/google/sheet/wrapper.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import json
from typing import Any, Dict, List, Union

import requests
from google.auth.transport.requests import AuthorizedSession
from googleapiclient.discovery import build

Expand All @@ -19,7 +20,7 @@ class _GoogleSheetWrapper:
def __init__(self, auth_client: GoogleAuthClient):
service = build("sheets", "v4", credentials=auth_client.credentials())
self._svc = service.spreadsheets()
self._authed_session = AuthorizedSession(auth_client.credentials())
self._authed_session: AuthorizedSession = AuthorizedSession(auth_client.credentials())

def create_spreadsheet(self, title: str) -> str:
resp = self._svc.create(body={"properties": {"title": title}}).execute()
Expand Down Expand Up @@ -137,7 +138,7 @@ def query(self, spreadsheet_id: str, sheet_name: str, query: str, has_header: bo
}

url = "https://docs.google.com/spreadsheets/d/{}/gviz/tq".format(spreadsheet_id)
response = self._authed_session.request(
response: requests.Response = self._authed_session.request(
"GET",
url,
headers={"Content-Type": "application/json"},
Expand All @@ -148,7 +149,7 @@ def query(self, spreadsheet_id: str, sheet_name: str, query: str, has_header: bo

def _convert_query_result(self, response: str) -> List[List[Any]]:
# Remove the schema header -> freeleh({...}).
# We only care about the JSON inside of the bracket.
# We only care about the JSON inside the bracket.
start, end = response.index("{"), response.rindex("}")
resp = json.loads(response[start : end + 1])
cols = resp["table"]["cols"]
Expand Down
Empty file removed tests/row/test_gsheet.py
Empty file.

0 comments on commit 0011a37

Please sign in to comment.