Skip to content

Commit

Permalink
Merge branch 'main' into feat_error_details
Browse files Browse the repository at this point in the history
  • Loading branch information
tseaver authored Oct 12, 2021
2 parents 5cebe8e + e6a3489 commit 5b3f7c1
Show file tree
Hide file tree
Showing 29 changed files with 416 additions and 33 deletions.
4 changes: 2 additions & 2 deletions .github/.OwlBot.lock.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
docker:
image: gcr.io/repo-automation-bots/owlbot-python:latest
digest: sha256:0ffe3bdd6c7159692df5f7744da74e5ef19966288a6bf76023e8e04e0c424d7d
image: gcr.io/cloud-devrel-public-resources/owlbot-python:latest
digest: sha256:58f73ba196b5414782605236dd0712a73541b44ff2ff4d3a36ec41092dd6fa5b
2 changes: 1 addition & 1 deletion .github/.OwlBot.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# limitations under the License.

docker:
image: gcr.io/repo-automation-bots/owlbot-python:latest
image: gcr.io/cloud-devrel-public-resources/owlbot-python:latest

begin-after-commit-hash: 7af2cb8b2b725641ac0d07e2f256d453682802e6

2 changes: 1 addition & 1 deletion .kokoro/samples/lint/common.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@ gfile_resources: "/bigstore/cloud-devrel-kokoro-resources/python-docs-samples"
gfile_resources: "/bigstore/cloud-devrel-kokoro-resources/trampoline"

# Use the trampoline script to run in docker.
build_file: "python-api-core/.kokoro/trampoline.sh"
build_file: "python-api-core/.kokoro/trampoline_v2.sh"
40 changes: 40 additions & 0 deletions .kokoro/samples/python3.10/common.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Format: //devtools/kokoro/config/proto/build.proto

# Build logs will be here
action {
define_artifacts {
regex: "**/*sponge_log.xml"
}
}

# Specify which tests to run
env_vars: {
key: "RUN_TESTS_SESSION"
value: "py-3.10"
}

# Declare build specific Cloud project.
env_vars: {
key: "BUILD_SPECIFIC_GCLOUD_PROJECT"
value: "python-docs-samples-tests-310"
}

env_vars: {
key: "TRAMPOLINE_BUILD_FILE"
value: "github/python-api-core/.kokoro/test-samples.sh"
}

# Configure the docker image for kokoro-trampoline.
env_vars: {
key: "TRAMPOLINE_IMAGE"
value: "gcr.io/cloud-devrel-kokoro-resources/python-samples-testing-docker"
}

# Download secrets for samples
gfile_resources: "/bigstore/cloud-devrel-kokoro-resources/python-docs-samples"

# Download trampoline resources.
gfile_resources: "/bigstore/cloud-devrel-kokoro-resources/trampoline"

# Use the trampoline script to run in docker.
build_file: "python-api-core/.kokoro/trampoline_v2.sh"
6 changes: 6 additions & 0 deletions .kokoro/samples/python3.10/continuous.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Format: //devtools/kokoro/config/proto/build.proto

env_vars: {
key: "INSTALL_LIBRARY_FROM_SOURCE"
value: "True"
}
11 changes: 11 additions & 0 deletions .kokoro/samples/python3.10/periodic-head.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Format: //devtools/kokoro/config/proto/build.proto

env_vars: {
key: "INSTALL_LIBRARY_FROM_SOURCE"
value: "True"
}

env_vars: {
key: "TRAMPOLINE_BUILD_FILE"
value: "github/python-api-core/.kokoro/test-samples-against-head.sh"
}
6 changes: 6 additions & 0 deletions .kokoro/samples/python3.10/periodic.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Format: //devtools/kokoro/config/proto/build.proto

env_vars: {
key: "INSTALL_LIBRARY_FROM_SOURCE"
value: "False"
}
6 changes: 6 additions & 0 deletions .kokoro/samples/python3.10/presubmit.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Format: //devtools/kokoro/config/proto/build.proto

env_vars: {
key: "INSTALL_LIBRARY_FROM_SOURCE"
value: "True"
}
2 changes: 1 addition & 1 deletion .kokoro/samples/python3.6/common.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,4 @@ gfile_resources: "/bigstore/cloud-devrel-kokoro-resources/python-docs-samples"
gfile_resources: "/bigstore/cloud-devrel-kokoro-resources/trampoline"

# Use the trampoline script to run in docker.
build_file: "python-api-core/.kokoro/trampoline.sh"
build_file: "python-api-core/.kokoro/trampoline_v2.sh"
2 changes: 1 addition & 1 deletion .kokoro/samples/python3.6/periodic.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
env_vars: {
key: "INSTALL_LIBRARY_FROM_SOURCE"
value: "False"
}
}
2 changes: 1 addition & 1 deletion .kokoro/samples/python3.7/common.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,4 @@ gfile_resources: "/bigstore/cloud-devrel-kokoro-resources/python-docs-samples"
gfile_resources: "/bigstore/cloud-devrel-kokoro-resources/trampoline"

# Use the trampoline script to run in docker.
build_file: "python-api-core/.kokoro/trampoline.sh"
build_file: "python-api-core/.kokoro/trampoline_v2.sh"
2 changes: 1 addition & 1 deletion .kokoro/samples/python3.7/periodic.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
env_vars: {
key: "INSTALL_LIBRARY_FROM_SOURCE"
value: "False"
}
}
2 changes: 1 addition & 1 deletion .kokoro/samples/python3.8/common.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,4 @@ gfile_resources: "/bigstore/cloud-devrel-kokoro-resources/python-docs-samples"
gfile_resources: "/bigstore/cloud-devrel-kokoro-resources/trampoline"

# Use the trampoline script to run in docker.
build_file: "python-api-core/.kokoro/trampoline.sh"
build_file: "python-api-core/.kokoro/trampoline_v2.sh"
2 changes: 1 addition & 1 deletion .kokoro/samples/python3.8/periodic.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
env_vars: {
key: "INSTALL_LIBRARY_FROM_SOURCE"
value: "False"
}
}
2 changes: 1 addition & 1 deletion .kokoro/samples/python3.9/common.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,4 @@ gfile_resources: "/bigstore/cloud-devrel-kokoro-resources/python-docs-samples"
gfile_resources: "/bigstore/cloud-devrel-kokoro-resources/trampoline"

# Use the trampoline script to run in docker.
build_file: "python-api-core/.kokoro/trampoline.sh"
build_file: "python-api-core/.kokoro/trampoline_v2.sh"
2 changes: 1 addition & 1 deletion .kokoro/samples/python3.9/periodic.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
env_vars: {
key: "INSTALL_LIBRARY_FROM_SOURCE"
value: "False"
}
}
2 changes: 0 additions & 2 deletions .kokoro/test-samples-against-head.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,4 @@ set -eo pipefail
# Enables `**` to include files nested inside sub-folders
shopt -s globstar

cd github/python-api-core

exec .kokoro/test-samples-impl.sh
2 changes: 0 additions & 2 deletions .kokoro/test-samples.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ set -eo pipefail
# Enables `**` to include files nested inside sub-folders
shopt -s globstar

cd github/python-api-core

# Run periodic samples tests at latest release
if [[ $KOKORO_BUILD_ARTIFACTS_SUBDIR = *"periodic"* ]]; then
# preserving the test runner implementation.
Expand Down
20 changes: 11 additions & 9 deletions .repo-metadata.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
{
"name": "google-api-core",
"name_pretty": "Google API client core library",
"client_documentation": "https://googleapis.dev/python/google-api-core/latest",
"release_level": "ga",
"language": "python",
"library_type": "CORE",
"repo": "googleapis/python-api-core",
"distribution_name": "google-api-core"
}
"name": "google-api-core",
"name_pretty": "Google API client core library",
"client_documentation": "https://googleapis.dev/python/google-api-core/latest",
"release_level": "ga",
"language": "python",
"library_type": "CORE",
"repo": "googleapis/python-api-core",
"distribution_name": "google-api-core",
"default_version": "",
"codeowner_team": "@googleapis/actools-python"
}
17 changes: 14 additions & 3 deletions .trampolinerc
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,26 @@

# Add required env vars here.
required_envvars+=(
"STAGING_BUCKET"
"V2_STAGING_BUCKET"
)

# Add env vars which are passed down into the container here.
pass_down_envvars+=(
"NOX_SESSION"
###############
# Docs builds
###############
"STAGING_BUCKET"
"V2_STAGING_BUCKET"
"NOX_SESSION"
##################
# Samples builds
##################
"INSTALL_LIBRARY_FROM_SOURCE"
"RUN_TESTS_SESSION"
"BUILD_SPECIFIC_GCLOUD_PROJECT"
# Target directories.
"RUN_TESTS_DIRS"
# The nox session to run.
"RUN_TESTS_SESSION"
)

# Prevent unintentional override on the default image.
Expand Down
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,15 @@

[1]: https://pypi.org/project/google-api-core/#history

## [2.1.0](https://github.com/googleapis/python-api-core/compare/v2.0.1...v2.1.0) (2021-10-05)


### Features

* add grpc transcoding + tests ([#259](https://github.com/googleapis/python-api-core/issues/259)) ([afe0fa1](https://github.com/googleapis/python-api-core/commit/afe0fa14c21289c8244606a9f81544cff8ac5f7c))
* Add helper function to format query_params for rest transport. ([#275](https://github.com/googleapis/python-api-core/issues/275)) ([1c5eb4d](https://github.com/googleapis/python-api-core/commit/1c5eb4df93d78e791082d9282330ebf0faacd222))
* add support for Python 3.10 ([#284](https://github.com/googleapis/python-api-core/issues/284)) ([a422a5d](https://github.com/googleapis/python-api-core/commit/a422a5d72cb6f363d57e7a4effe421ba8e049cde))

### [2.0.1](https://github.com/googleapis/python-api-core/compare/v2.0.0...v2.0.1) (2021-08-31)


Expand Down
6 changes: 4 additions & 2 deletions CONTRIBUTING.rst
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ In order to add a feature:
documentation.

- The feature must work fully on the following CPython versions:
3.6, 3.7, 3.8 and 3.9 on both UNIX and Windows.
3.6, 3.7, 3.8, 3.9, and 3.10 on both UNIX and Windows.

- The feature must not add unnecessary dependencies (where
"unnecessary" is of course subjective, but new dependencies should
Expand Down Expand Up @@ -71,7 +71,7 @@ We use `nox <https://nox.readthedocs.io/en/latest/>`__ to instrument our tests.

- To run a single unit test::

$ nox -s unit-3.9 -- -k <name of test>
$ nox -s unit-3.10 -- -k <name of test>


.. note::
Expand Down Expand Up @@ -201,11 +201,13 @@ We support:
- `Python 3.7`_
- `Python 3.8`_
- `Python 3.9`_
- `Python 3.10`_

.. _Python 3.6: https://docs.python.org/3.6/
.. _Python 3.7: https://docs.python.org/3.7/
.. _Python 3.8: https://docs.python.org/3.8/
.. _Python 3.9: https://docs.python.org/3.9/
.. _Python 3.10: https://docs.python.org/3.10/


Supported versions can be found in our ``noxfile.py`` `config`_.
Expand Down
2 changes: 1 addition & 1 deletion google/api_core/bidi.py
Original file line number Diff line number Diff line change
Expand Up @@ -727,7 +727,7 @@ def resume(self):
"""Resumes the response stream."""
with self._wake:
self._paused = False
self._wake.notifyAll()
self._wake.notify_all()

@property
def is_paused(self):
Expand Down
94 changes: 94 additions & 0 deletions google/api_core/rest_helpers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
# Copyright 2021 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""Helpers for rest transports."""

import functools
import operator


def flatten_query_params(obj):
"""Flatten a nested dict into a list of (name,value) tuples.
The result is suitable for setting query params on an http request.
.. code-block:: python
>>> obj = {'a':
... {'b':
... {'c': ['x', 'y', 'z']} },
... 'd': 'uvw', }
>>> flatten_query_params(obj)
[('a.b.c', 'x'), ('a.b.c', 'y'), ('a.b.c', 'z'), ('d', 'uvw')]
Note that, as described in
https://github.com/googleapis/googleapis/blob/48d9fb8c8e287c472af500221c6450ecd45d7d39/google/api/http.proto#L117,
repeated fields (i.e. list-valued fields) may only contain primitive types (not lists or dicts).
This is enforced in this function.
Args:
obj: a nested dictionary (from json), or None
Returns: a list of tuples, with each tuple having a (possibly) multi-part name
and a scalar value.
Raises:
TypeError if obj is not a dict or None
ValueError if obj contains a list of non-primitive values.
"""

if obj is not None and not isinstance(obj, dict):
raise TypeError("flatten_query_params must be called with dict object")

return _flatten(obj, key_path=[])


def _flatten(obj, key_path):
if obj is None:
return []
if isinstance(obj, dict):
return _flatten_dict(obj, key_path=key_path)
if isinstance(obj, list):
return _flatten_list(obj, key_path=key_path)
return _flatten_value(obj, key_path=key_path)


def _is_primitive_value(obj):
if obj is None:
return False

if isinstance(obj, (list, dict)):
raise ValueError("query params may not contain repeated dicts or lists")

return True


def _flatten_value(obj, key_path):
return [(".".join(key_path), obj)]


def _flatten_dict(obj, key_path):
items = (_flatten(value, key_path=key_path + [key]) for key, value in obj.items())
return functools.reduce(operator.concat, items, [])


def _flatten_list(elems, key_path):
# Only lists of scalar values are supported.
# The name (key_path) is repeated for each value.
items = (
_flatten_value(elem, key_path=key_path)
for elem in elems
if _is_primitive_value(elem)
)
return functools.reduce(operator.concat, items, [])
2 changes: 1 addition & 1 deletion google/api_core/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@
# See the License for the specific language governing permissions and
# limitations under the License.

__version__ = "2.0.1"
__version__ = "2.1.0"
2 changes: 1 addition & 1 deletion noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ def default(session):
session.run(*pytest_args)


@nox.session(python=["3.6", "3.7", "3.8", "3.9"])
@nox.session(python=["3.6", "3.7", "3.8", "3.9", "3.10"])
def unit(session):
"""Run the unit test suite."""
default(session)
Expand Down
Loading

0 comments on commit 5b3f7c1

Please sign in to comment.