Skip to content

Commit

Permalink
chore(python): use black==22.3.0 (#181)
Browse files Browse the repository at this point in the history
* chore(python): use black==22.3.0

Source-Link: googleapis/synthtool@6fab84a
Post-Processor: gcr.io/cloud-devrel-public-resources/owlbot-python:latest@sha256:7cffbc10910c3ab1b852c05114a08d374c195a81cdec1d4a67a1d129331d0bfe

* chore: update black version in noxfile

* 🦉 Updates from OwlBot post-processor

See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md

* ci: add commit to trigger gh actions

Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
Co-authored-by: Anthonios Partheniou <partheniou@google.com>
  • Loading branch information
3 people authored Mar 30, 2022
1 parent 8575b67 commit 8ca0faa
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 23 deletions.
3 changes: 2 additions & 1 deletion .github/.OwlBot.lock.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@
# limitations under the License.
docker:
image: gcr.io/cloud-devrel-public-resources/owlbot-python:latest
digest: sha256:4e1991042fe54b991db9ca17c8fb386e61b22fe4d1472a568bf0fcac85dcf5d3
digest: sha256:7cffbc10910c3ab1b852c05114a08d374c195a81cdec1d4a67a1d129331d0bfe

13 changes: 11 additions & 2 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,13 @@
# One entry per manual page. List of tuples
# (source start file, name, description, authors, manual section).
man_pages = [
(root_doc, "google-cloud-core", "google-cloud-core Documentation", [author], 1,)
(
root_doc,
"google-cloud-core",
"google-cloud-core Documentation",
[author],
1,
)
]

# If true, show URL addresses after external links.
Expand Down Expand Up @@ -355,7 +361,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
12 changes: 5 additions & 7 deletions google/cloud/_helpers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,11 @@ def __init__(self):
self._stack = []

def __iter__(self):
"""Iterate the stack in LIFO order.
"""
"""Iterate the stack in LIFO order."""
return iter(reversed(self._stack))

def push(self, resource):
"""Push a resource onto our stack.
"""
"""Push a resource onto our stack."""
self._stack.append(resource)

def pop(self):
Expand Down Expand Up @@ -284,7 +282,7 @@ def _rfc3339_nanos_to_datetime(dt_str):
micros = 0
else:
scale = 9 - len(fraction)
nanos = int(fraction) * (10 ** scale)
nanos = int(fraction) * (10**scale)
micros = nanos // 1000
return bare_seconds.replace(microsecond=micros, tzinfo=UTC)

Expand Down Expand Up @@ -416,8 +414,8 @@ def _datetime_to_pb_timestamp(when):
:returns: A timestamp protobuf corresponding to the object.
"""
ms_value = _microseconds_from_datetime(when)
seconds, micros = divmod(ms_value, 10 ** 6)
nanos = micros * 10 ** 3
seconds, micros = divmod(ms_value, 10**6)
nanos = micros * 10**3
return timestamp_pb2.Timestamp(seconds=seconds, nanos=nanos)


Expand Down
6 changes: 4 additions & 2 deletions google/cloud/client/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,8 @@ 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 @@ -254,7 +255,8 @@ 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
12 changes: 9 additions & 3 deletions noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import nox


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

DEFAULT_PYTHON_VERSION = "3.7"
Expand All @@ -43,7 +43,10 @@ def mypy(session):
"""Run type-checking."""
session.install(".", "mypy")
session.install(
"types-setuptools", "types-requests", "types-mock", "types-protobuf",
"types-setuptools",
"types-requests",
"types-mock",
"types-protobuf",
)
session.run("mypy", "google", "tests")

Expand Down Expand Up @@ -143,7 +146,10 @@ def docfx(session):

session.install("-e", ".")
session.install(
"sphinx==4.0.1", "alabaster", "recommonmark", "gcp-sphinx-docfx-yaml",
"sphinx==4.0.1",
"alabaster",
"recommonmark",
"gcp-sphinx-docfx-yaml",
)

shutil.rmtree(os.path.join("docs", "_build"), ignore_errors=True)
Expand Down
8 changes: 5 additions & 3 deletions tests/unit/test__helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -553,7 +553,9 @@ def test_success(self):
out_message = self._call_fut(date_pb2.Date, in_message_any)
self.assertEqual(in_message, out_message)

def test_failure(self,):
def test_failure(
self,
):
from google.protobuf import any_pb2
from google.type import date_pb2
from google.type import timeofday_pb2
Expand Down Expand Up @@ -636,7 +638,7 @@ def test_with_negative_microseconds(self):
result = self._call_fut(timedelta_val)
self.assertIsInstance(result, duration_pb2.Duration)
self.assertEqual(result.seconds, seconds - 1)
self.assertEqual(result.nanos, 10 ** 9 + 1000 * microseconds)
self.assertEqual(result.nanos, 10**9 + 1000 * microseconds)

def test_with_negative_seconds(self):
import datetime
Expand All @@ -648,7 +650,7 @@ def test_with_negative_seconds(self):
result = self._call_fut(timedelta_val)
self.assertIsInstance(result, duration_pb2.Duration)
self.assertEqual(result.seconds, seconds + 1)
self.assertEqual(result.nanos, -(10 ** 9 - 1000 * microseconds))
self.assertEqual(result.nanos, -(10**9 - 1000 * microseconds))


class Test__duration_pb_to_timedelta(unittest.TestCase):
Expand Down
15 changes: 10 additions & 5 deletions tests/unit/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,8 @@ def test_ctor_defaults_wo_envvar(self):
environ = {}
patch_env = mock.patch("os.environ", new=environ)
patch_default = mock.patch(
"google.cloud.client._determine_default_project", return_value=None,
"google.cloud.client._determine_default_project",
return_value=None,
)
with patch_env:
with patch_default as patched:
Expand Down Expand Up @@ -268,7 +269,8 @@ def test_ctor_defaults_w_legacy_envvar(self):
def test_ctor_w_explicit_project(self):
explicit_project = "explicit-project-456"
patch_default = mock.patch(
"google.cloud.client._determine_default_project", return_value=None,
"google.cloud.client._determine_default_project",
return_value=None,
)
with patch_default as patched:
client = self._make_one(project=explicit_project)
Expand All @@ -280,7 +282,8 @@ def test_ctor_w_explicit_project(self):
def test_ctor_w_explicit_project_bytes(self):
explicit_project = b"explicit-project-456"
patch_default = mock.patch(
"google.cloud.client._determine_default_project", return_value=None,
"google.cloud.client._determine_default_project",
return_value=None,
)
with patch_default as patched:
client = self._make_one(project=explicit_project)
Expand All @@ -292,7 +295,8 @@ def test_ctor_w_explicit_project_bytes(self):
def test_ctor_w_explicit_project_invalid(self):
explicit_project = object()
patch_default = mock.patch(
"google.cloud.client._determine_default_project", return_value=None,
"google.cloud.client._determine_default_project",
return_value=None,
)
with patch_default as patched:
with self.assertRaises(ValueError):
Expand Down Expand Up @@ -331,7 +335,8 @@ def test_ctor_w_explicit_credentials_w_project(self):
project = "credentials-project-456"
credentials = self._make_credentials(project_id=project)
patch_default = mock.patch(
"google.cloud.client._determine_default_project", return_value=None,
"google.cloud.client._determine_default_project",
return_value=None,
)
with patch_default as patched:
client = self._make_one(credentials=credentials)
Expand Down

0 comments on commit 8ca0faa

Please sign in to comment.