From d65f5084b42bdecddafff2fcd9a34f5d269cd840 Mon Sep 17 00:00:00 2001 From: Bu Sun Kim Date: Tue, 26 Jan 2021 23:03:28 +0000 Subject: [PATCH 1/7] feat: drop python<3.6 --- README.rst | 6 +----- google/__init__.py | 24 ------------------------ noxfile.py | 30 ++++++------------------------ setup.py | 8 ++------ 4 files changed, 9 insertions(+), 59 deletions(-) delete mode 100644 google/__init__.py diff --git a/README.rst b/README.rst index 244043ea..d4bffd57 100644 --- a/README.rst +++ b/README.rst @@ -16,8 +16,4 @@ common helpers used by all Google API clients. For more information, see the Supported Python Versions ------------------------- -Python >= 3.5 - -Deprecated Python Versions --------------------------- -Python == 2.7. Python 2.7 support will be removed on January 1, 2020. +Python >= 3.6 diff --git a/google/__init__.py b/google/__init__.py deleted file mode 100644 index 0d0a4c3a..00000000 --- a/google/__init__.py +++ /dev/null @@ -1,24 +0,0 @@ -# Copyright 2016 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. - -"""Google namespace package.""" - -try: - import pkg_resources - - pkg_resources.declare_namespace(__name__) -except ImportError: - import pkgutil - - __path__ = pkgutil.extend_path(__path__, __name__) diff --git a/noxfile.py b/noxfile.py index 650cef28..16e07525 100644 --- a/noxfile.py +++ b/noxfile.py @@ -22,17 +22,6 @@ CURRENT_DIRECTORY = pathlib.Path(__file__).parent.absolute() -_MINIMAL_ASYNCIO_SUPPORT_PYTHON_VERSION = [3, 6] - -def _greater_or_equal_than_36(version_string): - tokens = version_string.split(".") - for i, token in enumerate(tokens): - try: - tokens[i] = int(token) - except ValueError: - pass - return tokens >= [3, 6] - def default(session): """Default unit test session. @@ -47,7 +36,7 @@ def default(session): ) # Install all test dependencies, then install this package in-place. - session.install("mock", "pytest", "pytest-cov", "grpcio >= 1.0.2") + session.install("mock", "pytest", "pytest-cov", "grpcio >= 1.0.2", "asyncmock", "pytest-asyncio") session.install("-e", ".", "-c", constraints_path) pytest_args = [ @@ -57,33 +46,26 @@ def default(session): "--quiet", "--cov=google.api_core", "--cov=tests.unit", + "--cov=tests.asyncio" "--cov-append", "--cov-config=.coveragerc", "--cov-report=", "--cov-fail-under=0", os.path.join("tests", "unit"), + os.path.join("tests", "asyncio") ] pytest_args.extend(session.posargs) + session.run(*pytest_args) - # Inject AsyncIO content, if version >= 3.6. - if _greater_or_equal_than_36(session.python): - session.install("asyncmock", "pytest-asyncio") - - pytest_args.append("--cov=tests.asyncio") - pytest_args.append(os.path.join("tests", "asyncio")) - session.run(*pytest_args) - else: - # Run py.test against the unit tests. - session.run(*pytest_args) -@nox.session(python=["2.7", "3.6", "3.7", "3.8", "3.9"]) +@nox.session(python=["3.6", "3.7", "3.8", "3.9"]) def unit(session): """Run the unit test suite.""" default(session) -@nox.session(python=["2.7", "3.6", "3.7", "3.8", "3.9"]) +@nox.session(python=["3.6", "3.7", "3.8", "3.9"]) def unit_grpc_gcp(session): """Run the unit test suite with grpcio-gcp installed.""" constraints_path = str( diff --git a/setup.py b/setup.py index 30adb954..9d42c168 100644 --- a/setup.py +++ b/setup.py @@ -31,12 +31,11 @@ dependencies = [ "googleapis-common-protos >= 1.6.0, < 2.0dev", "protobuf >= 3.12.0", - "google-auth >= 1.21.1, < 2.0dev", + "google-auth >= 1.21.1, < 3.0dev", "requests >= 2.18.0, < 3.0.0dev", "setuptools >= 40.3.0", "six >= 1.13.0", "pytz", - 'futures >= 3.2.0; python_version < "3.2"', ] extras = { "grpc": "grpcio >= 1.29.0, < 2.0dev", @@ -85,10 +84,7 @@ "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", "Programming Language :: Python :: 3.8", @@ -101,7 +97,7 @@ namespace_packages=namespaces, install_requires=dependencies, extras_require=extras, - python_requires=">=2.7,!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,!=3.4.*,!=3.5.*", + python_requires=">=3.6", include_package_data=True, zip_safe=False, ) From 742d96c976aa6f91e23835ecdf12d2a8e058c52c Mon Sep 17 00:00:00 2001 From: Bu Sun Kim Date: Tue, 26 Jan 2021 23:10:09 +0000 Subject: [PATCH 2/7] chore: update version --- google/api_core/version.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/google/api_core/version.py b/google/api_core/version.py index 5966ec4e..258353a0 100644 --- a/google/api_core/version.py +++ b/google/api_core/version.py @@ -12,4 +12,4 @@ # See the License for the specific language governing permissions and # limitations under the License. -__version__ = "1.25.1" +__version__ = "1.26.0dev1" From f5c493d0ea166333c2c1087e0d6a5222c212e138 Mon Sep 17 00:00:00 2001 From: Bu Sun Kim Date: Tue, 26 Jan 2021 23:30:02 +0000 Subject: [PATCH 3/7] fix: fix package detection --- setup.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 9d42c168..5a3b3da9 100644 --- a/setup.py +++ b/setup.py @@ -61,7 +61,9 @@ # 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.PEP420PackageFinder.find() + if package.startswith("google") ] # Determine which namespaces are needed. From 6ca7470eefaecc697a1c7670e7e412fc6c1d5e0f Mon Sep 17 00:00:00 2001 From: Bu Sun Kim Date: Wed, 27 Jan 2021 21:47:41 +0000 Subject: [PATCH 4/7] fix: remove namespace_packages from setup.py --- noxfile.py | 26 ++++++++++++++++++++++---- setup.py | 7 ------- 2 files changed, 22 insertions(+), 11 deletions(-) diff --git a/noxfile.py b/noxfile.py index 16e07525..6f9e61d1 100644 --- a/noxfile.py +++ b/noxfile.py @@ -22,6 +22,17 @@ CURRENT_DIRECTORY = pathlib.Path(__file__).parent.absolute() +_MINIMAL_ASYNCIO_SUPPORT_PYTHON_VERSION = [3, 6] + +def _greater_or_equal_than_36(version_string): + tokens = version_string.split(".") + for i, token in enumerate(tokens): + try: + tokens[i] = int(token) + except ValueError: + pass + return tokens >= [3, 6] + def default(session): """Default unit test session. @@ -36,7 +47,7 @@ def default(session): ) # Install all test dependencies, then install this package in-place. - session.install("mock", "pytest", "pytest-cov", "grpcio >= 1.0.2", "asyncmock", "pytest-asyncio") + session.install("mock", "pytest", "pytest-cov", "grpcio >= 1.0.2") session.install("-e", ".", "-c", constraints_path) pytest_args = [ @@ -46,17 +57,24 @@ def default(session): "--quiet", "--cov=google.api_core", "--cov=tests.unit", - "--cov=tests.asyncio" "--cov-append", "--cov-config=.coveragerc", "--cov-report=", "--cov-fail-under=0", os.path.join("tests", "unit"), - os.path.join("tests", "asyncio") ] pytest_args.extend(session.posargs) - session.run(*pytest_args) + # Inject AsyncIO content, if version >= 3.6. + if _greater_or_equal_than_36(session.python): + session.install("asyncmock", "pytest-asyncio") + + pytest_args.append("--cov=tests.asyncio") + pytest_args.append(os.path.join("tests", "asyncio")) + session.run(*pytest_args) + else: + # Run py.test against the unit tests. + session.run(*pytest_args) @nox.session(python=["3.6", "3.7", "3.8", "3.9"]) diff --git a/setup.py b/setup.py index 5a3b3da9..ab94ba16 100644 --- a/setup.py +++ b/setup.py @@ -66,12 +66,6 @@ if package.startswith("google") ] -# Determine which namespaces are needed. -namespaces = ["google"] -if "google.cloud" in packages: - namespaces.append("google.cloud") - - setuptools.setup( name=name, version=version, @@ -96,7 +90,6 @@ ], platforms="Posix; MacOS X; Windows", packages=packages, - namespace_packages=namespaces, install_requires=dependencies, extras_require=extras, python_requires=">=3.6", From 6efa594cab95159e01f60ef586ccce59062e8496 Mon Sep 17 00:00:00 2001 From: Bu Sun Kim Date: Thu, 28 Jan 2021 01:17:42 +0000 Subject: [PATCH 5/7] fix: remove abstractmethod from non-abstract class --- google/api_core/future/polling.py | 1 - 1 file changed, 1 deletion(-) diff --git a/google/api_core/future/polling.py b/google/api_core/future/polling.py index 6466838f..936d15c2 100644 --- a/google/api_core/future/polling.py +++ b/google/api_core/future/polling.py @@ -65,7 +65,6 @@ def __init__(self, retry=DEFAULT_RETRY): self._polling_thread = None self._done_callbacks = [] - @abc.abstractmethod def done(self, retry=DEFAULT_RETRY): """Checks to see if the operation is complete. From 69e0e565403ca69049677b4947cea21a24628e9b Mon Sep 17 00:00:00 2001 From: Bu Sun Kim Date: Thu, 28 Jan 2021 16:21:20 +0000 Subject: [PATCH 6/7] fix: fix pytype and coverage --- google/api_core/future/polling.py | 5 ++++- google/api_core/gapic_v1/__init__.py | 10 +++------- google/api_core/gapic_v1/routing_header.py | 3 --- google/api_core/iam.py | 6 +----- google/api_core/operations_v1/__init__.py | 6 ++---- google/api_core/protobuf_helpers.py | 6 +----- 6 files changed, 11 insertions(+), 25 deletions(-) diff --git a/google/api_core/future/polling.py b/google/api_core/future/polling.py index 936d15c2..f6ae7b22 100644 --- a/google/api_core/future/polling.py +++ b/google/api_core/future/polling.py @@ -38,7 +38,9 @@ class _OperationNotComplete(Exception): DEFAULT_RETRY = retry.Retry(predicate=RETRY_PREDICATE) -class PollingFuture(base.Future): +# pytype incorrectly determines that this class is not abstract +# and errors on the @abstractmethod annotation on done(). +class PollingFuture(base.Future): # pytype: disable=ignored-abstractmethod """A Future that needs to poll some service to check its status. The :meth:`done` method should be implemented by subclasses. The polling @@ -65,6 +67,7 @@ def __init__(self, retry=DEFAULT_RETRY): self._polling_thread = None self._done_callbacks = [] + @abc.abstractmethod def done(self, retry=DEFAULT_RETRY): """Checks to see if the operation is complete. diff --git a/google/api_core/gapic_v1/__init__.py b/google/api_core/gapic_v1/__init__.py index ed95da13..621aeb4d 100644 --- a/google/api_core/gapic_v1/__init__.py +++ b/google/api_core/gapic_v1/__init__.py @@ -18,11 +18,7 @@ from google.api_core.gapic_v1 import config from google.api_core.gapic_v1 import method from google.api_core.gapic_v1 import routing_header +from google.api_core.gapic_v1 import config_async +from google.api_core.gapic_v1 import method_async -__all__ = ["client_info", "config", "method", "routing_header"] - -if sys.version_info >= (3, 6): - from google.api_core.gapic_v1 import config_async # noqa: F401 - from google.api_core.gapic_v1 import method_async # noqa: F401 - __all__.append("config_async") - __all__.append("method_async") +__all__ = ["client_info", "config", "method", "routing_header", "config_async", "method_async"] \ No newline at end of file diff --git a/google/api_core/gapic_v1/routing_header.py b/google/api_core/gapic_v1/routing_header.py index 3fb12a6f..49a87eb1 100644 --- a/google/api_core/gapic_v1/routing_header.py +++ b/google/api_core/gapic_v1/routing_header.py @@ -37,9 +37,6 @@ def to_routing_header(params): Returns: str: The routing header string. """ - if sys.version_info[0] < 3: - # Python 2 does not have the "safe" parameter for urlencode. - return urlencode(params).replace("%2F", "/") return urlencode( params, # Per Google API policy (go/api-url-encoding), / is not encoded. diff --git a/google/api_core/iam.py b/google/api_core/iam.py index f1309360..ad10e499 100644 --- a/google/api_core/iam.py +++ b/google/api_core/iam.py @@ -54,11 +54,7 @@ import collections import operator import warnings - -try: - from collections import abc as collections_abc -except ImportError: # Python 2.7 - import collections as collections_abc +from collections import abc as collections_abc # Generic IAM roles diff --git a/google/api_core/operations_v1/__init__.py b/google/api_core/operations_v1/__init__.py index bc9befcb..aba7a742 100644 --- a/google/api_core/operations_v1/__init__.py +++ b/google/api_core/operations_v1/__init__.py @@ -17,8 +17,6 @@ import sys from google.api_core.operations_v1.operations_client import OperationsClient +from google.api_core.operations_v1.operations_async_client import OperationsAsyncClient -__all__ = ["OperationsClient"] -if sys.version_info >= (3, 6, 0): - from google.api_core.operations_v1.operations_async_client import OperationsAsyncClient # noqa: F401 - __all__.append("OperationsAsyncClient") +__all__ = ["OperationsClient", "OperationsAsyncClient"] \ No newline at end of file diff --git a/google/api_core/protobuf_helpers.py b/google/api_core/protobuf_helpers.py index 365ef25c..0a329e4d 100644 --- a/google/api_core/protobuf_helpers.py +++ b/google/api_core/protobuf_helpers.py @@ -17,16 +17,12 @@ import collections import copy import inspect +from collections import abc as collections_abc from google.protobuf import field_mask_pb2 from google.protobuf import message from google.protobuf import wrappers_pb2 -try: - from collections import abc as collections_abc -except ImportError: # Python 2.7 - import collections as collections_abc - _SENTINEL = object() _WRAPPER_TYPES = ( From 899a986d96758a96c07f46932705022869970a87 Mon Sep 17 00:00:00 2001 From: Bu Sun Kim Date: Thu, 28 Jan 2021 16:28:56 +0000 Subject: [PATCH 7/7] chore: fix lint --- google/api_core/future/polling.py | 2 +- google/api_core/gapic_v1/__init__.py | 8 ++++---- google/api_core/gapic_v1/routing_header.py | 2 -- google/api_core/iam.py | 3 +-- google/api_core/operations_v1/__init__.py | 6 ++---- google/api_core/protobuf_helpers.py | 2 +- 6 files changed, 9 insertions(+), 14 deletions(-) diff --git a/google/api_core/future/polling.py b/google/api_core/future/polling.py index f6ae7b22..fa8f6d71 100644 --- a/google/api_core/future/polling.py +++ b/google/api_core/future/polling.py @@ -40,7 +40,7 @@ class _OperationNotComplete(Exception): # pytype incorrectly determines that this class is not abstract # and errors on the @abstractmethod annotation on done(). -class PollingFuture(base.Future): # pytype: disable=ignored-abstractmethod +class PollingFuture(base.Future): # pytype: disable=ignored-abstractmethod """A Future that needs to poll some service to check its status. The :meth:`done` method should be implemented by subclasses. The polling diff --git a/google/api_core/gapic_v1/__init__.py b/google/api_core/gapic_v1/__init__.py index 621aeb4d..9becfc46 100644 --- a/google/api_core/gapic_v1/__init__.py +++ b/google/api_core/gapic_v1/__init__.py @@ -12,13 +12,13 @@ # See the License for the specific language governing permissions and # limitations under the License. -import sys from google.api_core.gapic_v1 import client_info from google.api_core.gapic_v1 import config -from google.api_core.gapic_v1 import method -from google.api_core.gapic_v1 import routing_header from google.api_core.gapic_v1 import config_async +from google.api_core.gapic_v1 import method from google.api_core.gapic_v1 import method_async +from google.api_core.gapic_v1 import routing_header + -__all__ = ["client_info", "config", "method", "routing_header", "config_async", "method_async"] \ No newline at end of file +__all__ = ["client_info", "config", "method", "routing_header", "config_async", "method_async"] diff --git a/google/api_core/gapic_v1/routing_header.py b/google/api_core/gapic_v1/routing_header.py index 49a87eb1..21c86ec9 100644 --- a/google/api_core/gapic_v1/routing_header.py +++ b/google/api_core/gapic_v1/routing_header.py @@ -20,8 +20,6 @@ Generally, these headers are specified as gRPC metadata. """ -import sys - from six.moves.urllib.parse import urlencode ROUTING_METADATA_KEY = "x-goog-request-params" diff --git a/google/api_core/iam.py b/google/api_core/iam.py index ad10e499..49c0334e 100644 --- a/google/api_core/iam.py +++ b/google/api_core/iam.py @@ -51,10 +51,9 @@ resource.set_iam_policy(policy) """ -import collections +from collections import abc as collections_abc import operator import warnings -from collections import abc as collections_abc # Generic IAM roles diff --git a/google/api_core/operations_v1/__init__.py b/google/api_core/operations_v1/__init__.py index aba7a742..fd54b385 100644 --- a/google/api_core/operations_v1/__init__.py +++ b/google/api_core/operations_v1/__init__.py @@ -14,9 +14,7 @@ """Package for interacting with the google.longrunning.operations meta-API.""" -import sys - -from google.api_core.operations_v1.operations_client import OperationsClient from google.api_core.operations_v1.operations_async_client import OperationsAsyncClient +from google.api_core.operations_v1.operations_client import OperationsClient -__all__ = ["OperationsClient", "OperationsAsyncClient"] \ No newline at end of file +__all__ = ["OperationsClient", "OperationsAsyncClient"] diff --git a/google/api_core/protobuf_helpers.py b/google/api_core/protobuf_helpers.py index 0a329e4d..33094ee6 100644 --- a/google/api_core/protobuf_helpers.py +++ b/google/api_core/protobuf_helpers.py @@ -15,9 +15,9 @@ """Helpers for :mod:`protobuf`.""" import collections +from collections import abc as collections_abc import copy import inspect -from collections import abc as collections_abc from google.protobuf import field_mask_pb2 from google.protobuf import message