From a581550e5649a665c8ada5f85665cb253d009bcb Mon Sep 17 00:00:00 2001 From: Leonid Emar-Kar Date: Tue, 24 Sep 2019 13:57:38 +0300 Subject: [PATCH 1/2] add client_options --- bigtable/google/cloud/bigtable/client.py | 15 +++++- bigtable/setup.py | 63 ++++++++++++------------ bigtable/tests/unit/test_client.py | 17 ++++++- 3 files changed, 59 insertions(+), 36 deletions(-) diff --git a/bigtable/google/cloud/bigtable/client.py b/bigtable/google/cloud/bigtable/client.py index f9a625b15843..62f7c5d1c214 100644 --- a/bigtable/google/cloud/bigtable/client.py +++ b/bigtable/google/cloud/bigtable/client.py @@ -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 @@ -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. @@ -131,6 +140,7 @@ def __init__( admin=False, client_info=_CLIENT_INFO, channel=None, + client_options=None, ): if read_only and admin: raise ValueError( @@ -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) diff --git a/bigtable/setup.py b/bigtable/setup.py index 26956b393471..3a9ecfce6909 100644 --- a/bigtable/setup.py +++ b/bigtable/setup.py @@ -20,41 +20,40 @@ # Package metadata. -name = 'google-cloud-bigtable' -description = 'Google Cloud Bigtable API client library' -version = '1.0.0' +name = "google-cloud-bigtable" +description = "Google Cloud Bigtable API client library" +version = "1.0.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.0, < 2.0dev", + "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( @@ -62,30 +61,30 @@ 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, ) diff --git a/bigtable/tests/unit/test_client.py b/bigtable/tests/unit/test_client.py index 05a017d898af..336f76bd6dc9 100644 --- a/bigtable/tests/unit/test_client.py +++ b/bigtable/tests/unit/test_client.py @@ -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): @@ -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, ) @@ -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) From cb9194aaec24798e6688f3d9ba6c0e17d2eb6ba1 Mon Sep 17 00:00:00 2001 From: Leonid Emar-Kar Date: Tue, 24 Sep 2019 17:35:59 +0300 Subject: [PATCH 2/2] update_comments --- bigtable/google/cloud/bigtable/client.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bigtable/google/cloud/bigtable/client.py b/bigtable/google/cloud/bigtable/client.py index 62f7c5d1c214..62d9811dc77b 100644 --- a/bigtable/google/cloud/bigtable/client.py +++ b/bigtable/google/cloud/bigtable/client.py @@ -116,7 +116,7 @@ class Client(ClientWithProject): :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. + on the client. API Endpoint should be set through ``client_options``. :type channel: :instance: grpc.Channel :param channel (grpc.Channel): (Optional) DEPRECATED: