Skip to content

Commit f7db69b

Browse files
authored
chore: add 'blacken' stanza to noxfile (#99)
Closes #98.
1 parent bbffd42 commit f7db69b

File tree

8 files changed

+102
-74
lines changed

8 files changed

+102
-74
lines changed

packages/google-cloud-core/.flake8

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import-order-style=google
33
# Note: this forces all google imports to be in the third group. See
44
# https://github.com/PyCQA/flake8-import-order/issues/111
55
application-import-names=google
6-
ignore = E203, E266, E501, W503
6+
ignore = E203, E266, E501, W503, I202
77
exclude =
88
__pycache__,
99
.git,

packages/google-cloud-core/docs/conf.py

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -313,13 +313,7 @@
313313
# One entry per manual page. List of tuples
314314
# (source start file, name, description, authors, manual section).
315315
man_pages = [
316-
(
317-
master_doc,
318-
"google-cloud-core",
319-
u"google-cloud-core Documentation",
320-
[author],
321-
1,
322-
)
316+
(master_doc, "google-cloud-core", u"google-cloud-core Documentation", [author], 1,)
323317
]
324318

325319
# If true, show URL addresses after external links.
@@ -360,14 +354,10 @@
360354
intersphinx_mapping = {
361355
"python": ("https://python.readthedocs.org/en/latest/", None),
362356
"google-auth": ("https://googleapis.dev/python/google-auth/latest/", None),
363-
"google.api_core": (
364-
"https://googleapis.dev/python/google-api-core/latest/",
365-
None,
366-
),
357+
"google.api_core": ("https://googleapis.dev/python/google-api-core/latest/", None,),
367358
"grpc": ("https://grpc.github.io/grpc/python/", None),
368359
"proto-plus": ("https://proto-plus-python.readthedocs.io/en/latest/", None),
369360
"protobuf": ("https://googleapis.dev/python/protobuf/latest/", None),
370-
371361
}
372362

373363

packages/google-cloud-core/google/cloud/_http.py

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,10 @@
1515
"""Shared implementation of connections to API servers."""
1616

1717
import collections
18+
1819
try:
1920
import collections.abc as collections_abc
20-
except ImportError:
21+
except ImportError: # Python2
2122
import collections as collections_abc
2223
import json
2324
import os
@@ -34,9 +35,7 @@
3435
API_BASE_URL = "https://www.googleapis.com"
3536
"""The base of the API call URL."""
3637

37-
DEFAULT_USER_AGENT = "gcloud-python/{0}".format(
38-
version.__version__
39-
)
38+
DEFAULT_USER_AGENT = "gcloud-python/{0}".format(version.__version__)
4039
"""The user agent for google-cloud-python requests."""
4140

4241
CLIENT_INFO_HEADER = "X-Goog-API-Client"
@@ -83,14 +82,12 @@ def USER_AGENT(self):
8382
:rtype: str
8483
:returns: user agent
8584
"""
86-
warnings.warn(
87-
_USER_AGENT_ALL_CAPS_DEPRECATED, DeprecationWarning, stacklevel=2)
85+
warnings.warn(_USER_AGENT_ALL_CAPS_DEPRECATED, DeprecationWarning, stacklevel=2)
8886
return self.user_agent
8987

9088
@USER_AGENT.setter
9189
def USER_AGENT(self, value):
92-
warnings.warn(
93-
_USER_AGENT_ALL_CAPS_DEPRECATED, DeprecationWarning, stacklevel=2)
90+
warnings.warn(_USER_AGENT_ALL_CAPS_DEPRECATED, DeprecationWarning, stacklevel=2)
9491
self.user_agent = value
9592

9693
@property
@@ -114,13 +111,15 @@ def _EXTRA_HEADERS(self):
114111
:returns: header keys / values
115112
"""
116113
warnings.warn(
117-
_EXTRA_HEADERS_ALL_CAPS_DEPRECATED, DeprecationWarning, stacklevel=2)
114+
_EXTRA_HEADERS_ALL_CAPS_DEPRECATED, DeprecationWarning, stacklevel=2
115+
)
118116
return self.extra_headers
119117

120118
@_EXTRA_HEADERS.setter
121119
def _EXTRA_HEADERS(self, value):
122120
warnings.warn(
123-
_EXTRA_HEADERS_ALL_CAPS_DEPRECATED, DeprecationWarning, stacklevel=2)
121+
_EXTRA_HEADERS_ALL_CAPS_DEPRECATED, DeprecationWarning, stacklevel=2
122+
)
124123
self.extra_headers = value
125124

126125
@property
@@ -222,7 +221,9 @@ def get_api_base_url_for_mtls(self, api_base_url=None):
222221
url_to_use = self.API_BASE_URL
223222
else:
224223
if self.ALLOW_AUTO_SWITCH_TO_MTLS_URL:
225-
url_to_use = self.API_BASE_MTLS_URL if self.http.is_mtls else self.API_BASE_URL
224+
url_to_use = (
225+
self.API_BASE_MTLS_URL if self.http.is_mtls else self.API_BASE_URL
226+
)
226227
else:
227228
url_to_use = self.API_BASE_URL
228229
return url_to_use

packages/google-cloud-core/google/cloud/client.py

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -158,9 +158,12 @@ def __init__(self, credentials=None, _http=None, client_options=None):
158158

159159
if credentials and client_options.credentials_file:
160160
raise google.api_core.exceptions.DuplicateCredentialArgs(
161-
"'credentials' and 'client_options.credentials_file' are mutually exclusive.")
161+
"'credentials' and 'client_options.credentials_file' are mutually exclusive."
162+
)
162163

163-
if credentials and not isinstance(credentials, google.auth.credentials.Credentials):
164+
if credentials and not isinstance(
165+
credentials, google.auth.credentials.Credentials
166+
):
164167
raise ValueError(_GOOGLE_AUTH_CREDENTIALS_HELP)
165168

166169
scopes = client_options.scopes or self.SCOPE
@@ -169,15 +172,19 @@ def __init__(self, credentials=None, _http=None, client_options=None):
169172
if not _http and credentials is None:
170173
if client_options.credentials_file:
171174
credentials, _ = google.auth.load_credentials_from_file(
172-
client_options.credentials_file, scopes=scopes)
175+
client_options.credentials_file, scopes=scopes
176+
)
173177
else:
174178
credentials, _ = google.auth.default(scopes=scopes)
175179

176180
self._credentials = google.auth.credentials.with_scopes_if_required(
177-
credentials, scopes=scopes)
181+
credentials, scopes=scopes
182+
)
178183

179184
if client_options.quota_project_id:
180-
self._credentials = self._credentials.with_quota_project(client_options.quota_project_id)
185+
self._credentials = self._credentials.with_quota_project(
186+
client_options.quota_project_id
187+
)
181188

182189
self._http_internal = _http
183190
self._client_cert_source = client_options.client_cert_source
@@ -202,8 +209,7 @@ def _http(self):
202209
"""
203210
if self._http_internal is None:
204211
self._http_internal = google.auth.transport.requests.AuthorizedSession(
205-
self._credentials,
206-
refresh_timeout=_CREDENTIALS_REFRESH_TIMEOUT,
212+
self._credentials, refresh_timeout=_CREDENTIALS_REFRESH_TIMEOUT,
207213
)
208214
self._http_internal.configure_mtls_channel(self._client_cert_source)
209215
return self._http_internal
@@ -233,8 +239,7 @@ def __init__(self, project=None, credentials=None):
233239
# https://github.com/googleapis/python-cloud-core/issues/27
234240
if project is None:
235241
project = os.getenv(
236-
environment_vars.PROJECT,
237-
os.getenv(environment_vars.LEGACY_PROJECT),
242+
environment_vars.PROJECT, os.getenv(environment_vars.LEGACY_PROJECT),
238243
)
239244

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

297302
def __init__(self, project=None, credentials=None, client_options=None, _http=None):
298303
_ClientProjectMixin.__init__(self, project=project, credentials=credentials)
299-
Client.__init__(self, credentials=credentials, client_options=client_options, _http=_http)
304+
Client.__init__(
305+
self, credentials=credentials, client_options=client_options, _http=_http
306+
)

packages/google-cloud-core/noxfile.py

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,35 @@
1919
import nox
2020

2121

22+
BLACK_VERSION = "black==19.10b0"
23+
BLACK_PATHS = ["docs", "google", "tests", "noxfile.py", "setup.py"]
24+
2225
DEFAULT_PYTHON_VERSION = "3.7"
2326
CURRENT_DIRECTORY = os.path.abspath(os.path.dirname(__file__))
2427

2528

29+
@nox.session(python=DEFAULT_PYTHON_VERSION)
30+
def lint(session):
31+
"""Run linters.
32+
33+
Returns a failure if the linters find linting errors or sufficiently
34+
serious code quality issues.
35+
"""
36+
session.install("flake8", "flake8-import-order", BLACK_VERSION)
37+
session.install(".")
38+
session.run("flake8", "google", "tests")
39+
40+
41+
@nox.session(python=DEFAULT_PYTHON_VERSION)
42+
def blacken(session):
43+
"""Run black.
44+
45+
Format code to uniform standard.
46+
"""
47+
session.install(BLACK_VERSION)
48+
session.run("black", *BLACK_PATHS)
49+
50+
2651
def default(session):
2752
"""Default unit test session.
2853
This is intended to be run **without** an interpreter set, so
@@ -51,7 +76,7 @@ def default(session):
5176
"--cov-report=",
5277
"--cov-fail-under=0",
5378
os.path.join("tests", "unit"),
54-
*session.posargs
79+
*session.posargs,
5580
)
5681

5782

@@ -61,18 +86,6 @@ def unit(session):
6186
default(session)
6287

6388

64-
@nox.session(python=DEFAULT_PYTHON_VERSION)
65-
def lint(session):
66-
"""Run linters.
67-
68-
Returns a failure if the linters find linting errors or sufficiently
69-
serious code quality issues.
70-
"""
71-
session.install("flake8", "flake8-import-order")
72-
session.install(".")
73-
session.run("flake8", "google", "tests")
74-
75-
7689
@nox.session(python=DEFAULT_PYTHON_VERSION)
7790
def lint_setup_py(session):
7891
"""Verify that setup.py is valid (including RST check)."""

packages/google-cloud-core/owlbot.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,5 @@
3535
"setup.cfg",
3636
],
3737
)
38+
39+
s.shell.run(["nox", "-s", "blacken"], hide_output=False)

packages/google-cloud-core/tests/unit/test__http.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -186,14 +186,18 @@ def test_build_api_url_no_extra_query_params(self):
186186
client = object()
187187
conn = self._make_mock_one(client)
188188
# Intended to emulate self.mock_template
189-
URI = "/".join([conn.API_BASE_URL, "mock", conn.API_VERSION, "foo?prettyPrint=false"])
189+
URI = "/".join(
190+
[conn.API_BASE_URL, "mock", conn.API_VERSION, "foo?prettyPrint=false"]
191+
)
190192
self.assertEqual(conn.build_api_url("/foo"), URI)
191193

192194
def test_build_api_url_w_pretty_print_query_params(self):
193195
client = object()
194196
conn = self._make_mock_one(client)
195197
uri = conn.build_api_url("/foo", {"prettyPrint": "true"})
196-
URI = "/".join([conn.API_BASE_URL, "mock", conn.API_VERSION, "foo?prettyPrint=true"])
198+
URI = "/".join(
199+
[conn.API_BASE_URL, "mock", conn.API_VERSION, "foo?prettyPrint=true"]
200+
)
197201
self.assertEqual(uri, URI)
198202

199203
def test_build_api_url_w_extra_query_params(self):
@@ -220,7 +224,9 @@ def test_build_api_url_w_extra_query_params_tuples(self):
220224

221225
client = object()
222226
conn = self._make_mock_one(client)
223-
uri = conn.build_api_url("/foo", [("bar", "baz"), ("qux", "quux"), ("qux", "corge")])
227+
uri = conn.build_api_url(
228+
"/foo", [("bar", "baz"), ("qux", "quux"), ("qux", "corge")]
229+
)
224230

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

0 commit comments

Comments
 (0)