Skip to content
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

feat(bigtable): add 'client_options' support to Client #9289

Closed
wants to merge 3 commits into from
Closed
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
15 changes: 13 additions & 2 deletions bigtable/google/cloud/bigtable/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,15 @@ def _create_gapic_client(client_class):
def inner(self):
if self._emulator_host is None:
return client_class(
credentials=self._credentials, client_info=self._client_info
credentials=self._credentials,
client_info=self._client_info,
client_options=self._client_options,
)
else:
return client_class(
channel=self._emulator_channel, client_info=self._client_info
channel=self._emulator_channel,
client_info=self._client_info,
client_options=self._client_options,
)

return inner
Expand Down Expand Up @@ -109,6 +113,11 @@ class Client(ClientWithProject):
you only need to set this if you're developing your own library
or partner tool.

:type client_options: :class:`~google.api_core.client_options.ClientOptions`
or :class:`dict`
:param client_options: (Optional) Client options used to set user options
on the client. API Endpoint should be set through ``client_options``.

:type channel: :instance: grpc.Channel
:param channel (grpc.Channel): (Optional) DEPRECATED:
A ``Channel`` instance through which to make calls.
Expand All @@ -131,6 +140,7 @@ def __init__(
admin=False,
client_info=_CLIENT_INFO,
channel=None,
client_options=None,
):
if read_only and admin:
raise ValueError(
Expand All @@ -144,6 +154,7 @@ def __init__(
self._client_info = client_info
self._emulator_host = os.getenv(BIGTABLE_EMULATOR)
self._emulator_channel = None
self._client_options = client_options

if self._emulator_host is not None:
self._emulator_channel = grpc.insecure_channel(self._emulator_host)
Expand Down
59 changes: 29 additions & 30 deletions bigtable/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,72 +20,71 @@

# Package metadata.

name = 'google-cloud-bigtable'
description = 'Google Cloud Bigtable API client library'
version = '1.1.0'
name = "google-cloud-bigtable"
description = "Google Cloud Bigtable API client library"
version = "1.1.0"
# Should be one of:
# 'Development Status :: 3 - Alpha'
# 'Development Status :: 4 - Beta'
# 'Development Status :: 5 - Production/Stable'
release_status = 'Development Status :: 5 - Production/Stable'
release_status = "Development Status :: 5 - Production/Stable"
dependencies = [
"google-api-core[grpc] >= 1.14.0, < 2.0.0dev",
"google-cloud-core >= 1.0.3, < 2.0dev",
"grpc-google-iam-v1 >= 0.12.3, < 0.13dev",
]
extras = {
}
extras = {}


# Setup boilerplate below this line.

package_root = os.path.abspath(os.path.dirname(__file__))

readme_filename = os.path.join(package_root, 'README.rst')
with io.open(readme_filename, encoding='utf-8') as readme_file:
readme_filename = os.path.join(package_root, "README.rst")
with io.open(readme_filename, encoding="utf-8") as readme_file:
readme = readme_file.read()

# Only include packages under the 'google' namespace. Do not include tests,
# benchmarks, etc.
packages = [
package for package in setuptools.find_packages()
if package.startswith('google')]
package for package in setuptools.find_packages() if package.startswith("google")
]

# Determine which namespaces are needed.
namespaces = ['google']
if 'google.cloud' in packages:
namespaces.append('google.cloud')
namespaces = ["google"]
if "google.cloud" in packages:
namespaces.append("google.cloud")


setuptools.setup(
name=name,
version=version,
description=description,
long_description=readme,
author='Google LLC',
author_email='googleapis-packages@google.com',
license='Apache 2.0',
url='https://github.com/GoogleCloudPlatform/google-cloud-python',
author="Google LLC",
author_email="googleapis-packages@google.com",
license="Apache 2.0",
url="https://github.com/GoogleCloudPlatform/google-cloud-python",
classifiers=[
release_status,
'Intended Audience :: Developers',
'License :: OSI Approved :: Apache Software License',
'Programming Language :: Python',
'Programming Language :: Python :: 2',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.5',
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: 3.7',
'Operating System :: OS Independent',
'Topic :: Internet',
"Intended Audience :: Developers",
"License :: OSI Approved :: Apache Software License",
"Programming Language :: Python",
"Programming Language :: Python :: 2",
"Programming Language :: Python :: 2.7",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.5",
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: 3.7",
"Operating System :: OS Independent",
"Topic :: Internet",
],
platforms='Posix; MacOS X; Windows',
platforms="Posix; MacOS X; Windows",
packages=packages,
namespace_packages=namespaces,
install_requires=dependencies,
extras_require=extras,
python_requires='>=2.7,!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*',
python_requires=">=2.7,!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*",
include_package_data=True,
zip_safe=False,
)
17 changes: 15 additions & 2 deletions bigtable/tests/unit/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,23 @@ def _invoke_client_factory(self, client_class):
return _create_gapic_client(client_class)

def test_without_emulator(self):
from google.api_core.client_options import ClientOptions

client_class = mock.Mock()
credentials = _make_credentials()
client = _Client(credentials)
client_info = client._client_info = mock.Mock()
client_options = client._client_options = ClientOptions(
api_endpoint="https://www.foo-googleapis.com"
)

result = self._invoke_client_factory(client_class)(client)

self.assertIs(result, client_class.return_value)
client_class.assert_called_once_with(
credentials=client._credentials, client_info=client_info
credentials=client._credentials,
client_info=client_info,
client_options=client_options,
)

def test_with_emulator(self):
Expand All @@ -47,12 +54,17 @@ def test_with_emulator(self):
credentials, emulator_host=emulator_host, emulator_channel=emulator_channel
)
client_info = client._client_info = mock.Mock()
client_options = client._client_options = {
"api_endpoint": "https://www.foo-googleapis.com"
}

result = self._invoke_client_factory(client_class)(client)

self.assertIs(result, client_class.return_value)
client_class.assert_called_once_with(
channel=client._emulator_channel, client_info=client_info
channel=client._emulator_channel,
client_info=client_info,
client_options=client_options,
)


Expand Down Expand Up @@ -94,6 +106,7 @@ def test_constructor_defaults(self):
self.assertFalse(client._read_only)
self.assertFalse(client._admin)
self.assertIs(client._client_info, _CLIENT_INFO)
self.assertIsNone(client._client_options)
self.assertIsNone(client._channel)
self.assertIsNone(client._emulator_host)
self.assertIsNone(client._emulator_channel)
Expand Down