Skip to content
Merged
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
2 changes: 1 addition & 1 deletion .flake8
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ 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
ignore = E203, E266, E501, W503
ignore = E203, E266, E501, W503, I202
exclude =
__pycache__,
.git,
Expand Down
14 changes: 2 additions & 12 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -313,13 +313,7 @@
# One entry per manual page. List of tuples
# (source start file, name, description, authors, manual section).
man_pages = [
(
master_doc,
"google-cloud-core",
u"google-cloud-core Documentation",
[author],
1,
)
(master_doc, "google-cloud-core", u"google-cloud-core Documentation", [author], 1,)
]

# If true, show URL addresses after external links.
Expand Down Expand Up @@ -360,14 +354,10 @@
intersphinx_mapping = {
"python": ("https://python.readthedocs.org/en/latest/", None),
"google-auth": ("https://googleapis.dev/python/google-auth/latest/", None),
"google.api_core": (
"https://googleapis.dev/python/google-api-core/latest/",
None,
),
"google.api_core": ("https://googleapis.dev/python/google-api-core/latest/", None,),
"grpc": ("https://grpc.github.io/grpc/python/", None),
"proto-plus": ("https://proto-plus-python.readthedocs.io/en/latest/", None),
"protobuf": ("https://googleapis.dev/python/protobuf/latest/", None),

}


Expand Down
23 changes: 12 additions & 11 deletions google/cloud/_http.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@
"""Shared implementation of connections to API servers."""

import collections

try:
import collections.abc as collections_abc
except ImportError:
except ImportError: # Python2
import collections as collections_abc
import json
import os
Expand All @@ -34,9 +35,7 @@
API_BASE_URL = "https://www.googleapis.com"
"""The base of the API call URL."""

DEFAULT_USER_AGENT = "gcloud-python/{0}".format(
version.__version__
)
DEFAULT_USER_AGENT = "gcloud-python/{0}".format(version.__version__)
"""The user agent for google-cloud-python requests."""

CLIENT_INFO_HEADER = "X-Goog-API-Client"
Expand Down Expand Up @@ -83,14 +82,12 @@ def USER_AGENT(self):
:rtype: str
:returns: user agent
"""
warnings.warn(
_USER_AGENT_ALL_CAPS_DEPRECATED, DeprecationWarning, stacklevel=2)
warnings.warn(_USER_AGENT_ALL_CAPS_DEPRECATED, DeprecationWarning, stacklevel=2)
return self.user_agent

@USER_AGENT.setter
def USER_AGENT(self, value):
warnings.warn(
_USER_AGENT_ALL_CAPS_DEPRECATED, DeprecationWarning, stacklevel=2)
warnings.warn(_USER_AGENT_ALL_CAPS_DEPRECATED, DeprecationWarning, stacklevel=2)
self.user_agent = value

@property
Expand All @@ -114,13 +111,15 @@ def _EXTRA_HEADERS(self):
:returns: header keys / values
"""
warnings.warn(
_EXTRA_HEADERS_ALL_CAPS_DEPRECATED, DeprecationWarning, stacklevel=2)
_EXTRA_HEADERS_ALL_CAPS_DEPRECATED, DeprecationWarning, stacklevel=2
)
return self.extra_headers

@_EXTRA_HEADERS.setter
def _EXTRA_HEADERS(self, value):
warnings.warn(
_EXTRA_HEADERS_ALL_CAPS_DEPRECATED, DeprecationWarning, stacklevel=2)
_EXTRA_HEADERS_ALL_CAPS_DEPRECATED, DeprecationWarning, stacklevel=2
)
self.extra_headers = value

@property
Expand Down Expand Up @@ -222,7 +221,9 @@ def get_api_base_url_for_mtls(self, api_base_url=None):
url_to_use = self.API_BASE_URL
else:
if self.ALLOW_AUTO_SWITCH_TO_MTLS_URL:
url_to_use = self.API_BASE_MTLS_URL if self.http.is_mtls else self.API_BASE_URL
url_to_use = (
self.API_BASE_MTLS_URL if self.http.is_mtls else self.API_BASE_URL
)
else:
url_to_use = self.API_BASE_URL
return url_to_use
Expand Down
27 changes: 17 additions & 10 deletions google/cloud/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,12 @@ def __init__(self, credentials=None, _http=None, client_options=None):

if credentials and client_options.credentials_file:
raise google.api_core.exceptions.DuplicateCredentialArgs(
"'credentials' and 'client_options.credentials_file' are mutually exclusive.")
"'credentials' and 'client_options.credentials_file' are mutually exclusive."
)

if credentials and not isinstance(credentials, google.auth.credentials.Credentials):
if credentials and not isinstance(
credentials, google.auth.credentials.Credentials
):
raise ValueError(_GOOGLE_AUTH_CREDENTIALS_HELP)

scopes = client_options.scopes or self.SCOPE
Expand All @@ -169,15 +172,19 @@ def __init__(self, credentials=None, _http=None, client_options=None):
if not _http and credentials is None:
if client_options.credentials_file:
credentials, _ = google.auth.load_credentials_from_file(
client_options.credentials_file, scopes=scopes)
client_options.credentials_file, scopes=scopes
)
else:
credentials, _ = google.auth.default(scopes=scopes)

self._credentials = google.auth.credentials.with_scopes_if_required(
credentials, scopes=scopes)
credentials, scopes=scopes
)

if client_options.quota_project_id:
self._credentials = self._credentials.with_quota_project(client_options.quota_project_id)
self._credentials = self._credentials.with_quota_project(
client_options.quota_project_id
)

self._http_internal = _http
self._client_cert_source = client_options.client_cert_source
Expand All @@ -202,8 +209,7 @@ def _http(self):
"""
if self._http_internal is None:
self._http_internal = google.auth.transport.requests.AuthorizedSession(
self._credentials,
refresh_timeout=_CREDENTIALS_REFRESH_TIMEOUT,
self._credentials, refresh_timeout=_CREDENTIALS_REFRESH_TIMEOUT,
)
self._http_internal.configure_mtls_channel(self._client_cert_source)
return self._http_internal
Expand Down Expand Up @@ -233,8 +239,7 @@ def __init__(self, project=None, credentials=None):
# https://github.com/googleapis/python-cloud-core/issues/27
if project is None:
project = os.getenv(
environment_vars.PROJECT,
os.getenv(environment_vars.LEGACY_PROJECT),
environment_vars.PROJECT, os.getenv(environment_vars.LEGACY_PROJECT),
)

# Project set on explicit credentials overrides discovery from
Expand Down Expand Up @@ -296,4 +301,6 @@ class ClientWithProject(Client, _ClientProjectMixin):

def __init__(self, project=None, credentials=None, client_options=None, _http=None):
_ClientProjectMixin.__init__(self, project=project, credentials=credentials)
Client.__init__(self, credentials=credentials, client_options=client_options, _http=_http)
Client.__init__(
self, credentials=credentials, client_options=client_options, _http=_http
)
39 changes: 26 additions & 13 deletions noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,35 @@
import nox


BLACK_VERSION = "black==19.10b0"
BLACK_PATHS = ["docs", "google", "tests", "noxfile.py", "setup.py"]

DEFAULT_PYTHON_VERSION = "3.7"
CURRENT_DIRECTORY = os.path.abspath(os.path.dirname(__file__))


@nox.session(python=DEFAULT_PYTHON_VERSION)
def lint(session):
"""Run linters.

Returns a failure if the linters find linting errors or sufficiently
serious code quality issues.
"""
session.install("flake8", "flake8-import-order", BLACK_VERSION)
session.install(".")
session.run("flake8", "google", "tests")


@nox.session(python=DEFAULT_PYTHON_VERSION)
def blacken(session):
"""Run black.

Format code to uniform standard.
"""
session.install(BLACK_VERSION)
session.run("black", *BLACK_PATHS)


def default(session):
"""Default unit test session.
This is intended to be run **without** an interpreter set, so
Expand Down Expand Up @@ -51,7 +76,7 @@ def default(session):
"--cov-report=",
"--cov-fail-under=0",
os.path.join("tests", "unit"),
*session.posargs
*session.posargs,
)


Expand All @@ -61,18 +86,6 @@ def unit(session):
default(session)


@nox.session(python=DEFAULT_PYTHON_VERSION)
def lint(session):
"""Run linters.

Returns a failure if the linters find linting errors or sufficiently
serious code quality issues.
"""
session.install("flake8", "flake8-import-order")
session.install(".")
session.run("flake8", "google", "tests")


@nox.session(python=DEFAULT_PYTHON_VERSION)
def lint_setup_py(session):
"""Verify that setup.py is valid (including RST check)."""
Expand Down
2 changes: 2 additions & 0 deletions owlbot.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,5 @@
"setup.cfg",
],
)

s.shell.run(["nox", "-s", "blacken"], hide_output=False)
12 changes: 9 additions & 3 deletions tests/unit/test__http.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,14 +186,18 @@ def test_build_api_url_no_extra_query_params(self):
client = object()
conn = self._make_mock_one(client)
# Intended to emulate self.mock_template
URI = "/".join([conn.API_BASE_URL, "mock", conn.API_VERSION, "foo?prettyPrint=false"])
URI = "/".join(
[conn.API_BASE_URL, "mock", conn.API_VERSION, "foo?prettyPrint=false"]
)
self.assertEqual(conn.build_api_url("/foo"), URI)

def test_build_api_url_w_pretty_print_query_params(self):
client = object()
conn = self._make_mock_one(client)
uri = conn.build_api_url("/foo", {"prettyPrint": "true"})
URI = "/".join([conn.API_BASE_URL, "mock", conn.API_VERSION, "foo?prettyPrint=true"])
URI = "/".join(
[conn.API_BASE_URL, "mock", conn.API_VERSION, "foo?prettyPrint=true"]
)
self.assertEqual(uri, URI)

def test_build_api_url_w_extra_query_params(self):
Expand All @@ -220,7 +224,9 @@ def test_build_api_url_w_extra_query_params_tuples(self):

client = object()
conn = self._make_mock_one(client)
uri = conn.build_api_url("/foo", [("bar", "baz"), ("qux", "quux"), ("qux", "corge")])
uri = conn.build_api_url(
"/foo", [("bar", "baz"), ("qux", "quux"), ("qux", "corge")]
)

scheme, netloc, path, qs, _ = urlsplit(uri)
self.assertEqual("%s://%s" % (scheme, netloc), conn.API_BASE_URL)
Expand Down
Loading