Skip to content
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
45 changes: 16 additions & 29 deletions .github/renovate.json5
Original file line number Diff line number Diff line change
@@ -1,32 +1,19 @@
{
"assignees": ["TheKevJames"],
"extends": [
"github>thekevjames/tools",
"github>thekevjames/tools:trustedpackages"
],
"packageRules": [
{
// only autoupdate python patches, we'll handle minors more explicitly
"matchPackageNames": ["python"],
"matchUpdateTypes": ["major", "minor"],
"enabled": false,
"extends": [
"github>thekevjames/tools",
"github>thekevjames/tools//renovate/version-as-lib.json5"
],
"assignees": ["TheKevJames"],
"packageRules": [
{
// only autoupdate python patches, we'll handle minors more explicitly
"matchPackageNames": ["python"],
"matchUpdateTypes": ["major", "minor"],
"enabled": false,
},
],
"lockFileMaintenance": {
"enabled": true,
"schedule": "before 1pm on monday"
},
{
"matchDepTypes": ["dependencies"],
"rangeStrategy": "widen",
},
{
"matchDepTypes": ["dev", "devDependencies"],
"rangeStrategy": "pin",
"automerge": true,
},
{
"matchUpdateTypes": ["patch"],
"automerge": true
},
],
"lockFileMaintenance": {
"enabled": true,
"schedule": "before 1pm on monday"
},
}
6 changes: 3 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ default_language_version:

repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v5.0.0
rev: v6.0.0
hooks:
- id: check-case-conflict
- id: check-executables-have-shebangs
Expand Down Expand Up @@ -80,7 +80,7 @@ repos:
# hooks:
# - id: add-trailing-comma
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.16.1
rev: v1.17.1
hooks:
- &mypy
id: mypy
Expand Down Expand Up @@ -186,7 +186,7 @@ repos:
language: python
additional_dependencies:
# renovate: datasource=pypi depName=poetry
- poetry==1.8.5
- poetry==2.1.4
pass_filenames: true
files: 'pyproject\.toml$'
- id: poetry-use-version-ranges
Expand Down
1,029 changes: 551 additions & 478 deletions auth/poetry.lock

Large diffs are not rendered by default.

273 changes: 150 additions & 123 deletions auth/poetry.rest.lock

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions auth/pyproject.rest.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ requests = ">= 2.2.1, < 3.0.0"

[tool.poetry.group.dev.dependencies]
pytest = "8.3.5"
# pytest-asyncio = "0.26.0"
pytest-mock = "3.14.0"
# pytest-asyncio = "1.1.0"
pytest-mock = "3.14.1"

[[tool.poetry.source]]
name = "pypi"
Expand Down
2 changes: 1 addition & 1 deletion auth/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ pyjwt = ">= 1.5.3, < 3.0.0"

[tool.poetry.group.dev.dependencies]
pytest = "8.3.5"
pytest-asyncio = "1.0.0"
pytest-asyncio = "1.1.0"
pytest-mock = "3.14.1"

[[tool.poetry.source]]
Expand Down
1,051 changes: 562 additions & 489 deletions bigquery/poetry.lock

Large diffs are not rendered by default.

293 changes: 163 additions & 130 deletions bigquery/poetry.rest.lock

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions bigquery/pyproject.rest.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ gcloud-rest-auth = { path = "../auth" }
gcloud-rest-datastore = { path = "../datastore" }
gcloud-rest-storage = { path = "../storage" }
pytest = "8.3.5"
# pytest-asyncio = "0.26.0"
pytest-mock = "3.14.0"
# pytest-asyncio = "1.1.0"
pytest-mock = "3.14.1"

[[tool.poetry.source]]
name = "pypi"
Expand Down
2 changes: 1 addition & 1 deletion bigquery/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ gcloud-aio-auth = { path = "../auth" }
gcloud-aio-datastore = { path = "../datastore" }
gcloud-aio-storage = { path = "../storage" }
pytest = "8.3.5"
pytest-asyncio = "1.0.0"
pytest-asyncio = "1.1.0"
pytest-mock = "3.14.1"

[[tool.poetry.source]]
Expand Down
45 changes: 20 additions & 25 deletions datastore/gcloud/aio/datastore/datastore.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,6 @@ class Datastore:
_api_root: str
_api_is_dev: bool

Timeout = Union[int, float]

def __init__(
self, project: Optional[str] = None,
service_file: Optional[Union[str, IO[AnyStr]]] = None,
Expand Down Expand Up @@ -161,7 +159,7 @@ def make_mutation(
async def allocateIds(
self, keys: List[Key],
session: Optional[Session] = None,
timeout: Timeout = 10,
timeout: float = 10.,
) -> List[Key]:
project = await self.project()
url = f'{self._api_root}/projects/{project}:allocateIds'
Expand Down Expand Up @@ -189,7 +187,7 @@ async def allocateIds(
# TODO: support readwrite vs readonly transaction types
async def beginTransaction(
self, session: Optional[Session] = None,
timeout: Timeout = 10,
timeout: float = 10.,
) -> str:
project = await self.project()
url = f'{self._api_root}/projects/{project}:beginTransaction'
Expand All @@ -212,7 +210,7 @@ async def commit(
transaction: Optional[str] = None,
mode: Mode = Mode.TRANSACTIONAL,
session: Optional[Session] = None,
timeout: Timeout = 10,
timeout: float = 10.,
) -> Dict[str, Any]:
project = await self.project()
url = f'{self._api_root}/projects/{project}:commit'
Expand Down Expand Up @@ -251,7 +249,7 @@ async def export(
namespaces: Optional[List[str]] = None,
labels: Optional[Dict[str, str]] = None,
session: Optional[Session] = None,
timeout: Timeout = 10,
timeout: float = 10.,
) -> DatastoreOperation:
project = await self.project()
url = f'{self._api_root}/projects/{project}:export'
Expand Down Expand Up @@ -284,7 +282,7 @@ async def export(
async def get_datastore_operation(
self, name: str,
session: Optional[Session] = None,
timeout: Timeout = 10,
timeout: float = 10.,
) -> DatastoreOperation:
url = f'{self._api_root}/{name}'

Expand All @@ -299,21 +297,22 @@ async def get_datastore_operation(

return self.datastore_operation_kind.from_repr(data)

# pylint: disable=too-many-locals
# https://cloud.google.com/datastore/docs/reference/data/rest/v1/projects/lookup
async def lookup(
self, keys: List[Key],
transaction: Optional[str] = None,
newTransaction: Optional[TransactionOptions] = None,
consistency: Consistency = Consistency.STRONG,
read_time: Optional[str] = None,
session: Optional[Session] = None, timeout: Timeout = 10,
session: Optional[Session] = None, timeout: float = 10.,
) -> LookUpResult:
# pylint: disable=too-many-locals
project = await self.project()
url = f'{self._api_root}/projects/{project}:lookup'

read_options = self._build_read_options(
consistency, newTransaction, transaction, read_time)
consistency, newTransaction, transaction, read_time,
)

payload = json.dumps({
'keys': [k.to_repr() for k in keys],
Expand Down Expand Up @@ -360,12 +359,11 @@ def _build_lookup_result(self, data: Dict[str, Any]) -> LookUpResult:
return result

# https://cloud.google.com/datastore/docs/reference/data/rest/v1/ReadOptions
def _build_read_options(self,
consistency: Consistency,
newTransaction: Optional[TransactionOptions],
transaction: Optional[str],
read_time: Optional[str],
) -> Dict[str, Any]:
def _build_read_options(
self, consistency: Consistency,
newTransaction: Optional[TransactionOptions],
transaction: Optional[str], read_time: Optional[str],
) -> Dict[str, Any]:
# TODO: expose ReadOptions directly to users
if transaction:
return {'transaction': transaction}
Expand All @@ -382,7 +380,7 @@ def _build_read_options(self,
async def reserveIds(
self, keys: List[Key], database_id: str = '',
session: Optional[Session] = None,
timeout: Timeout = 10,
timeout: float = 10.,
) -> None:
project = await self.project()
url = f'{self._api_root}/projects/{project}:reserveIds'
Expand All @@ -405,7 +403,7 @@ async def reserveIds(
async def rollback(
self, transaction: str,
session: Optional[Session] = None,
timeout: Timeout = 10,
timeout: float = 10.,
) -> None:
project = await self.project()
url = f'{self._api_root}/projects/{project}:rollback'
Expand All @@ -424,7 +422,6 @@ async def rollback(
await s.post(url, data=payload, headers=headers, timeout=timeout)

# https://cloud.google.com/datastore/docs/reference/data/rest/v1/projects/runQuery
# pylint: disable=too-many-locals
async def runQuery(
self, query: BaseQuery,
explain_options: Optional[ExplainOptions] = None,
Expand All @@ -433,14 +430,15 @@ async def runQuery(
consistency: Consistency = Consistency.EVENTUAL,
read_time: Optional[str] = None,
session: Optional[Session] = None,
timeout: Timeout = 10,
timeout: float = 10.,
) -> QueryResult:

# pylint: disable=too-many-locals
project = await self.project()
url = f'{self._api_root}/projects/{project}:runQuery'

read_options = self._build_read_options(
consistency, newTransaction, transaction, read_time)
consistency, newTransaction, transaction, read_time,
)

payload_dict = {
'partitionId': {
Expand All @@ -450,10 +448,8 @@ async def runQuery(
query.json_key: query.to_repr(),
'readOptions': read_options,
}

if explain_options:
payload_dict['explainOptions'] = explain_options.to_repr()

payload = json.dumps(payload_dict).encode('utf-8')

headers = await self.headers()
Expand All @@ -469,7 +465,6 @@ async def runQuery(
)

data: Dict[str, Any] = await resp.json()

return self.query_result_kind.from_repr(data)

async def delete(
Expand Down
8 changes: 5 additions & 3 deletions datastore/gcloud/aio/datastore/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,9 +281,11 @@ class QueryResult:
"""
query_result_batch_kind = QueryResultBatch

def __init__(self, result_batch: Optional[QueryResultBatch] = None,
explain_metrics: Optional[ExplainMetrics] = None,
transaction: Optional[str] = None):
def __init__(
self, result_batch: Optional[QueryResultBatch] = None,
explain_metrics: Optional[ExplainMetrics] = None,
transaction: Optional[str] = None,
):
self.result_batch = result_batch
self.explain_metrics = explain_metrics
self.transaction = transaction
Expand Down
34 changes: 22 additions & 12 deletions datastore/gcloud/aio/datastore/query_explain.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,13 @@ class IndexDefinition:

_PROPERTIES_PATTERN = re.compile(
r'\s*([^\s,()]+)\s+(ASC|DESC)\s*',
flags=re.IGNORECASE)
flags=re.IGNORECASE,
)

def __init__(self, query_scope: str = '',
properties: Optional[List[Tuple[str, str]]] = None):
def __init__(
self, query_scope: str = '',
properties: Optional[List[Tuple[str, str]]] = None,
):
self.query_scope = query_scope
self.properties = properties or []

Expand Down Expand Up @@ -106,10 +109,11 @@ def to_repr(self) -> Dict[str, Any]:
class ExecutionStats:
"""Container class for executionStats returned by analyze mode."""

def __init__(self, results_returned: int = 0,
execution_duration: float = 0.0,
read_operations: int = 0,
debug_stats: Optional[Dict[str, Any]] = None):
def __init__(
self, results_returned: int = 0, execution_duration: float = 0.0,
read_operations: int = 0,
debug_stats: Optional[Dict[str, Any]] = None,
):
self.results_returned = results_returned
self.execution_duration = execution_duration
self.read_operations = read_operations
Expand All @@ -128,13 +132,17 @@ def __eq__(self, other: object) -> bool:

@staticmethod
def _parse_execution_duration(
execution_duration: Optional[Union[str, float]]) -> float:
execution_duration: Optional[Union[str, float]],
) -> float:
"""Convert execution_duration from str (e.g. "0.01785s") to float."""
if isinstance(execution_duration, float):
# avoid parsing if already a float
return execution_duration
if not isinstance(execution_duration,
str) or not execution_duration.endswith('s'):

if (
not isinstance(execution_duration, str)
or not execution_duration.endswith('s')
):
raise ValueError(f'executionDuration must be a str ending with '
f'"s", got: {execution_duration}.')
return float(execution_duration.rstrip('s'))
Expand Down Expand Up @@ -174,8 +182,10 @@ def to_repr(self) -> Dict[str, Any]:
class ExplainMetrics:
"""Container class for explainMetrics returned by query explain."""

def __init__(self, plan_summary: Optional[PlanSummary] = None,
execution_stats: Optional[ExecutionStats] = None):
def __init__(
self, plan_summary: Optional[PlanSummary] = None,
execution_stats: Optional[ExecutionStats] = None,
):
self.plan_summary = plan_summary
self.execution_stats = execution_stats

Expand Down
Loading