diff --git a/core/.flake8 b/core/.flake8 index 7f4ddb8072b0..3db9b737d6bc 100644 --- a/core/.flake8 +++ b/core/.flake8 @@ -1,5 +1,8 @@ [flake8] import-order-style=google +# Note: this forces all google imports to be in the third group. See +# https://github.com/PyCQA/flake8-import-order/issues/111 +application-import-names=google exclude = __pycache__, .git, diff --git a/core/google/cloud/_helpers.py b/core/google/cloud/_helpers.py index 62bbccf74b15..fdb22ecdf09c 100644 --- a/core/google/cloud/_helpers.py +++ b/core/google/cloud/_helpers.py @@ -25,10 +25,14 @@ import re from threading import local as Local +import google_auth_httplib2 +import httplib2 +import six +from six.moves import http_client + import google.auth from google.protobuf import duration_pb2 from google.protobuf import timestamp_pb2 -import google_auth_httplib2 try: import grpc @@ -36,10 +40,6 @@ except ImportError: # pragma: NO COVER grpc = None -import httplib2 -import six -from six.moves import http_client - _NOW = datetime.datetime.utcnow # To be replaced by tests. _RFC3339_MICROS = '%Y-%m-%dT%H:%M:%S.%fZ' diff --git a/core/google/cloud/_http.py b/core/google/cloud/_http.py index ada60b4fb2c3..186d6216e7eb 100644 --- a/core/google/cloud/_http.py +++ b/core/google/cloud/_http.py @@ -16,8 +16,8 @@ import json import platform -from pkg_resources import get_distribution +from pkg_resources import get_distribution import six from six.moves.urllib.parse import urlencode diff --git a/core/google/cloud/client.py b/core/google/cloud/client.py index 5fa7f7ef95a2..5906ab5ed108 100644 --- a/core/google/cloud/client.py +++ b/core/google/cloud/client.py @@ -18,13 +18,13 @@ import json from pickle import PicklingError -import google.auth.credentials -from google.oauth2 import service_account import google_auth_httplib2 import six +import google.auth.credentials from google.cloud._helpers import _determine_default_project from google.cloud.credentials import get_credentials +from google.oauth2 import service_account _GOOGLE_AUTH_CREDENTIALS_HELP = ( diff --git a/core/google/cloud/credentials.py b/core/google/cloud/credentials.py index e5fe30245ea5..29c4a5d310f4 100644 --- a/core/google/cloud/credentials.py +++ b/core/google/cloud/credentials.py @@ -16,15 +16,15 @@ import base64 import datetime + import six from six.moves.urllib.parse import urlencode import google.auth import google.auth.credentials - -from google.cloud._helpers import UTC -from google.cloud._helpers import _NOW from google.cloud._helpers import _microseconds_from_datetime +from google.cloud._helpers import _NOW +from google.cloud._helpers import UTC def get_credentials(): diff --git a/core/google/cloud/exceptions.py b/core/google/cloud/exceptions.py index 32080de7ff50..e911980c6328 100644 --- a/core/google/cloud/exceptions.py +++ b/core/google/cloud/exceptions.py @@ -22,17 +22,18 @@ import copy import json + import six from google.cloud._helpers import _to_bytes -_HTTP_CODE_TO_EXCEPTION = {} # populated at end of module - try: from grpc._channel import _Rendezvous except ImportError: # pragma: NO COVER _Rendezvous = None +_HTTP_CODE_TO_EXCEPTION = {} # populated at end of module + # pylint: disable=invalid-name GrpcRendezvous = _Rendezvous diff --git a/core/google/cloud/future/operation.py b/core/google/cloud/future/operation.py index 21da738ca0ff..ec430cd9c55b 100644 --- a/core/google/cloud/future/operation.py +++ b/core/google/cloud/future/operation.py @@ -17,13 +17,12 @@ import functools import threading -from google.longrunning import operations_pb2 -from google.protobuf import json_format -from google.rpc import code_pb2 - from google.cloud import _helpers from google.cloud import exceptions from google.cloud.future import polling +from google.longrunning import operations_pb2 +from google.protobuf import json_format +from google.rpc import code_pb2 class Operation(polling.PollingFuture): diff --git a/core/nox.py b/core/nox.py index 8f025cce8b61..48b55332283e 100644 --- a/core/nox.py +++ b/core/nox.py @@ -53,7 +53,7 @@ def lint(session): session.install( 'flake8', 'flake8-import-order', 'pylint', 'gcp-devrel-py-tools') session.install('.') - session.run('flake8', 'google/cloud/core') + session.run('flake8', 'google', 'tests') session.run( 'gcp-devrel-py-tools', 'run-pylint', '--config', 'pylint.config.py', diff --git a/core/tests/unit/test_credentials.py b/core/tests/unit/test_credentials.py index 53370a061494..aaffa907dda1 100644 --- a/core/tests/unit/test_credentials.py +++ b/core/tests/unit/test_credentials.py @@ -15,6 +15,7 @@ import unittest import mock +import six class Test_get_credentials(unittest.TestCase): @@ -169,12 +170,10 @@ def test_w_int(self): self.assertEqual(self._call_fut(123), 123) def test_w_long(self): - try: - long - except NameError: # pragma: NO COVER Py3K - pass - else: - self.assertEqual(self._call_fut(long(123)), 123) + if six.PY3: + raise unittest.SkipTest('No long on Python 3') + + self.assertEqual(self._call_fut(long(123)), 123) # noqa: F821 def test_w_naive_datetime(self): import datetime diff --git a/core/tests/unit/test_iam.py b/core/tests/unit/test_iam.py index d076edd6eba9..4a17c61ce173 100644 --- a/core/tests/unit/test_iam.py +++ b/core/tests/unit/test_iam.py @@ -200,7 +200,6 @@ def test_from_api_repr_complete(self): {'role': VIEWER_ROLE, 'members': [VIEWER1, VIEWER2]}, ], } - empty = frozenset() klass = self._get_target_class() policy = klass.from_api_repr(RESOURCE) self.assertEqual(policy.etag, 'DEADBEEF')