Skip to content

Commit c821cdb

Browse files
authored
Blackening Continued... (#6667)
* blacken bigtable * blacken logging * blacken translate * blacken runtimeconfig * blacken dns
1 parent 467bc0a commit c821cdb

13 files changed

Lines changed: 240 additions & 245 deletions

File tree

β€Žpackages/google-cloud-runtimeconfig/google/__init__.pyβ€Ž

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@
1414

1515
try:
1616
import pkg_resources
17+
1718
pkg_resources.declare_namespace(__name__)
1819
except ImportError:
1920
import pkgutil
21+
2022
__path__ = pkgutil.extend_path(__path__, __name__)

β€Žpackages/google-cloud-runtimeconfig/google/cloud/__init__.pyβ€Ž

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@
1414

1515
try:
1616
import pkg_resources
17+
1718
pkg_resources.declare_namespace(__name__)
1819
except ImportError:
1920
import pkgutil
21+
2022
__path__ = pkgutil.extend_path(__path__, __name__)

β€Žpackages/google-cloud-runtimeconfig/google/cloud/runtimeconfig/__init__.pyβ€Ž

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,9 @@
1616

1717

1818
from pkg_resources import get_distribution
19-
__version__ = get_distribution('google-cloud-runtimeconfig').version
19+
20+
__version__ = get_distribution("google-cloud-runtimeconfig").version
2021

2122
from google.cloud.runtimeconfig.client import Client
2223

23-
__all__ = ['__version__', 'Client']
24+
__all__ = ["__version__", "Client"]

β€Žpackages/google-cloud-runtimeconfig/google/cloud/runtimeconfig/_helpers.pyβ€Ž

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,13 @@ def config_name_from_full_name(full_name):
3232
:returns: The config's short name, given its full resource name.
3333
:raises: :class:`ValueError` if ``full_name`` is not the expected format
3434
"""
35-
projects, _, configs, result = full_name.split('/')
36-
if projects != 'projects' or configs != 'configs':
35+
projects, _, configs, result = full_name.split("/")
36+
if projects != "projects" or configs != "configs":
3737
raise ValueError(
38-
'Unexpected format of resource', full_name,
39-
'Expected "projects/{proj}/configs/{cfg}"')
38+
"Unexpected format of resource",
39+
full_name,
40+
'Expected "projects/{proj}/configs/{cfg}"',
41+
)
4042
return result
4143

4244

@@ -61,10 +63,11 @@ def variable_name_from_full_name(full_name):
6163
:returns: The variable's short name, given its full resource name.
6264
:raises: :class:`ValueError` if ``full_name`` is not the expected format
6365
"""
64-
projects, _, configs, _, variables, result = full_name.split('/', 5)
65-
if (projects != 'projects' or configs != 'configs' or
66-
variables != 'variables'):
66+
projects, _, configs, _, variables, result = full_name.split("/", 5)
67+
if projects != "projects" or configs != "configs" or variables != "variables":
6768
raise ValueError(
68-
'Unexpected format of resource', full_name,
69-
'Expected "projects/{proj}/configs/{cfg}/variables/..."')
69+
"Unexpected format of resource",
70+
full_name,
71+
'Expected "projects/{proj}/configs/{cfg}/variables/..."',
72+
)
7073
return result

β€Žpackages/google-cloud-runtimeconfig/google/cloud/runtimeconfig/_http.pyβ€Ž

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,13 @@ class Connection(_http.JSONConnection):
3131
:param client: The client that owns the current connection.
3232
"""
3333

34-
API_BASE_URL = 'https://runtimeconfig.googleapis.com'
34+
API_BASE_URL = "https://runtimeconfig.googleapis.com"
3535
"""The base of the API call URL."""
3636

37-
API_VERSION = 'v1beta1'
37+
API_VERSION = "v1beta1"
3838
"""The version of the API, used in building the API call's URL."""
3939

40-
API_URL_TEMPLATE = '{api_base_url}/{api_version}{path}'
40+
API_URL_TEMPLATE = "{api_base_url}/{api_version}{path}"
4141
"""A template for the URL of a particular API call."""
4242

43-
_EXTRA_HEADERS = {
44-
_http.CLIENT_INFO_HEADER: _CLIENT_INFO,
45-
}
43+
_EXTRA_HEADERS = {_http.CLIENT_INFO_HEADER: _CLIENT_INFO}

β€Žpackages/google-cloud-runtimeconfig/google/cloud/runtimeconfig/client.pyβ€Ž

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,13 @@ class Client(ClientWithProject):
4545
change in the future.
4646
"""
4747

48-
SCOPE = ('https://www.googleapis.com/auth/cloudruntimeconfig',)
48+
SCOPE = ("https://www.googleapis.com/auth/cloudruntimeconfig",)
4949
"""The scopes required for authenticating as a RuntimeConfig consumer."""
5050

5151
def __init__(self, project=None, credentials=None, _http=None):
5252
super(Client, self).__init__(
53-
project=project, credentials=credentials, _http=_http)
53+
project=project, credentials=credentials, _http=_http
54+
)
5455
self._connection = Connection(self)
5556

5657
def config(self, config_name):

β€Žpackages/google-cloud-runtimeconfig/google/cloud/runtimeconfig/config.pyβ€Ž

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def __init__(self, client, name):
4242
self._properties = {}
4343

4444
def __repr__(self):
45-
return '<Config: %s>' % (self.name,)
45+
return "<Config: %s>" % (self.name,)
4646

4747
@property
4848
def client(self):
@@ -59,7 +59,7 @@ def description(self):
5959
:rtype: str, or ``NoneType``
6060
:returns: the description (None until set from the server).
6161
"""
62-
return self._properties.get('description')
62+
return self._properties.get("description")
6363

6464
@property
6565
def project(self):
@@ -83,8 +83,8 @@ def full_name(self):
8383
:raises: :class:`ValueError` if the config is missing a name.
8484
"""
8585
if not self.name:
86-
raise ValueError('Missing config name.')
87-
return 'projects/%s/configs/%s' % (self._client.project, self.name)
86+
raise ValueError("Missing config name.")
87+
return "projects/%s/configs/%s" % (self._client.project, self.name)
8888

8989
@property
9090
def path(self):
@@ -93,7 +93,7 @@ def path(self):
9393
:rtype: str
9494
:returns: The URL path based on project and config names.
9595
"""
96-
return '/%s' % (self.full_name,)
96+
return "/%s" % (self.full_name,)
9797

9898
def variable(self, variable_name):
9999
"""Factory constructor for variable object.
@@ -133,8 +133,8 @@ def _set_properties(self, api_response):
133133
"""
134134
self._properties.clear()
135135
cleaned = api_response.copy()
136-
if 'name' in cleaned:
137-
self.name = config_name_from_full_name(cleaned.pop('name'))
136+
if "name" in cleaned:
137+
self.name = config_name_from_full_name(cleaned.pop("name"))
138138
self._properties.update(cleaned)
139139

140140
def exists(self, client=None):
@@ -152,9 +152,10 @@ def exists(self, client=None):
152152
try:
153153
# We only need the status code (200 or not) so we seek to
154154
# minimize the returned payload.
155-
query_params = {'fields': 'name'}
155+
query_params = {"fields": "name"}
156156
client._connection.api_request(
157-
method='GET', path=self.path, query_params=query_params)
157+
method="GET", path=self.path, query_params=query_params
158+
)
158159
return True
159160
except NotFound:
160161
return False
@@ -176,7 +177,7 @@ def reload(self, client=None):
176177

177178
# We assume the config exists. If it doesn't it will raise a NotFound
178179
# exception.
179-
resp = client._connection.api_request(method='GET', path=self.path)
180+
resp = client._connection.api_request(method="GET", path=self.path)
180181
self._set_properties(api_response=resp)
181182

182183
def get_variable(self, variable_name, client=None):
@@ -237,17 +238,18 @@ def list_variables(self, page_size=None, page_token=None, client=None):
237238
Iterator of :class:`~google.cloud.runtimeconfig.variable.Variable`
238239
belonging to this project.
239240
"""
240-
path = '%s/variables' % (self.path,)
241+
path = "%s/variables" % (self.path,)
241242
client = self._require_client(client)
242243
iterator = page_iterator.HTTPIterator(
243244
client=client,
244245
api_request=client._connection.api_request,
245246
path=path,
246247
item_to_value=_item_to_variable,
247-
items_key='variables',
248+
items_key="variables",
248249
page_token=page_token,
249-
max_results=page_size)
250-
iterator._MAX_RESULTS = 'pageSize'
250+
max_results=page_size,
251+
)
252+
iterator._MAX_RESULTS = "pageSize"
251253
iterator.config = self
252254
return iterator
253255

β€Žpackages/google-cloud-runtimeconfig/google/cloud/runtimeconfig/variable.pyβ€Ž

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,9 @@
4545
from google.cloud.runtimeconfig._helpers import variable_name_from_full_name
4646

4747

48-
STATE_UNSPECIFIED = 'VARIABLE_STATE_UNSPECIFIED'
49-
STATE_UPDATED = 'UPDATED'
50-
STATE_DELETED = 'DELETED'
48+
STATE_UNSPECIFIED = "VARIABLE_STATE_UNSPECIFIED"
49+
STATE_UPDATED = "UPDATED"
50+
STATE_DELETED = "DELETED"
5151

5252

5353
class Variable(object):
@@ -82,7 +82,7 @@ def from_api_repr(cls, resource, config):
8282
:rtype: :class:`google.cloud.runtimeconfig.variable.Variable`
8383
:returns: Variable parsed from ``resource``.
8484
"""
85-
name = variable_name_from_full_name(resource.get('name'))
85+
name = variable_name_from_full_name(resource.get("name"))
8686
variable = cls(name=name, config=config)
8787
variable._set_properties(resource=resource)
8888
return variable
@@ -100,8 +100,8 @@ def full_name(self):
100100
:raises: :class:`ValueError` if the variable is missing a name.
101101
"""
102102
if not self.name:
103-
raise ValueError('Missing variable name.')
104-
return '%s/variables/%s' % (self.config.full_name, self.name)
103+
raise ValueError("Missing variable name.")
104+
return "%s/variables/%s" % (self.config.full_name, self.name)
105105

106106
@property
107107
def path(self):
@@ -110,7 +110,7 @@ def path(self):
110110
:rtype: str
111111
:returns: The URL path based on config and variable names.
112112
"""
113-
return '/%s' % (self.full_name,)
113+
return "/%s" % (self.full_name,)
114114

115115
@property
116116
def client(self):
@@ -128,7 +128,7 @@ def value(self):
128128
:returns: The value of the variable or ``None`` if the property
129129
is not set locally.
130130
"""
131-
value = self._properties.get('value')
131+
value = self._properties.get("value")
132132
if value is not None:
133133
value = base64.b64decode(value)
134134
return value
@@ -145,7 +145,7 @@ def state(self):
145145
If set, one of "UPDATED", "DELETED", or defaults to
146146
"VARIABLE_STATE_UNSPECIFIED".
147147
"""
148-
return self._properties.get('state', STATE_UNSPECIFIED)
148+
return self._properties.get("state", STATE_UNSPECIFIED)
149149

150150
@property
151151
def update_time(self):
@@ -163,17 +163,16 @@ def update_time(self):
163163
Raises:
164164
ValueError: if value is not a valid RFC3339 timestamp
165165
"""
166-
value = self._properties.get('updateTime')
166+
value = self._properties.get("updateTime")
167167
if value is not None:
168168
try:
169169
value = datetime.datetime.strptime(
170-
value, datetime_helpers._RFC3339_MICROS)
170+
value, datetime_helpers._RFC3339_MICROS
171+
)
171172
except ValueError:
172173
DatetimeNS = datetime_helpers.DatetimeWithNanoseconds
173174
value = DatetimeNS.from_rfc3339(value)
174-
naive = (
175-
value.tzinfo is None
176-
or value.tzinfo.utcoffset(value) is None)
175+
naive = value.tzinfo is None or value.tzinfo.utcoffset(value) is None
177176
if naive:
178177
value = pytz.utc.localize(value)
179178
return value
@@ -201,8 +200,8 @@ def _set_properties(self, resource):
201200
"""
202201
self._properties.clear()
203202
cleaned = resource.copy()
204-
if 'name' in cleaned:
205-
self.name = variable_name_from_full_name(cleaned.pop('name'))
203+
if "name" in cleaned:
204+
self.name = variable_name_from_full_name(cleaned.pop("name"))
206205
self._properties.update(cleaned)
207206

208207
def exists(self, client=None):
@@ -223,9 +222,10 @@ def exists(self, client=None):
223222
try:
224223
# We only need the status code (200 or not) so we seek to
225224
# minimize the returned payload.
226-
query_params = {'fields': 'name'}
227-
client._connection.api_request(method='GET', path=self.path,
228-
query_params=query_params)
225+
query_params = {"fields": "name"}
226+
client._connection.api_request(
227+
method="GET", path=self.path, query_params=query_params
228+
)
229229
return True
230230
except NotFound:
231231
return False
@@ -247,5 +247,5 @@ def reload(self, client=None):
247247

248248
# We assume the variable exists. If it doesn't it will raise a NotFound
249249
# exception.
250-
resp = client._connection.api_request(method='GET', path=self.path)
250+
resp = client._connection.api_request(method="GET", path=self.path)
251251
self._set_properties(resource=resp)

β€Žpackages/google-cloud-runtimeconfig/tests/unit/test__helpers.pyβ€Ž

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -16,60 +16,62 @@
1616

1717

1818
class Test_config_name_from_full_name(unittest.TestCase):
19-
2019
def _call_fut(self, full_name):
21-
from google.cloud.runtimeconfig._helpers import (
22-
config_name_from_full_name)
20+
from google.cloud.runtimeconfig._helpers import config_name_from_full_name
2321

2422
return config_name_from_full_name(full_name)
2523

2624
def test_w_simple_name(self):
27-
CONFIG_NAME = 'CONFIG_NAME'
28-
PROJECT = 'my-project-1234'
29-
PATH = 'projects/%s/configs/%s' % (PROJECT, CONFIG_NAME)
25+
CONFIG_NAME = "CONFIG_NAME"
26+
PROJECT = "my-project-1234"
27+
PATH = "projects/%s/configs/%s" % (PROJECT, CONFIG_NAME)
3028
config_name = self._call_fut(PATH)
3129
self.assertEqual(config_name, CONFIG_NAME)
3230

3331
def test_w_name_w_all_extras(self):
34-
CONFIG_NAME = 'CONFIG_NAME-part.one~part.two%part-three'
35-
PROJECT = 'my-project-1234'
36-
PATH = 'projects/%s/configs/%s' % (PROJECT, CONFIG_NAME)
32+
CONFIG_NAME = "CONFIG_NAME-part.one~part.two%part-three"
33+
PROJECT = "my-project-1234"
34+
PATH = "projects/%s/configs/%s" % (PROJECT, CONFIG_NAME)
3735
config_name = self._call_fut(PATH)
3836
self.assertEqual(config_name, CONFIG_NAME)
3937

4038
def test_w_bad_format(self):
41-
PATH = 'definitley/not/a/resource-name'
39+
PATH = "definitley/not/a/resource-name"
4240
with self.assertRaises(ValueError):
4341
self._call_fut(PATH)
4442

4543

4644
class Test_variable_name_from_full_name(unittest.TestCase):
47-
4845
def _call_fut(self, full_name):
49-
from google.cloud.runtimeconfig._helpers import (
50-
variable_name_from_full_name)
46+
from google.cloud.runtimeconfig._helpers import variable_name_from_full_name
5147

5248
return variable_name_from_full_name(full_name)
5349

5450
def test_w_simple_name(self):
55-
VARIABLE_NAME = 'VARIABLE_NAME'
56-
CONFIG_NAME = 'CONFIG_NAME'
57-
PROJECT = 'my-project-1234'
58-
PATH = 'projects/%s/configs/%s/variables/%s' % (
59-
PROJECT, CONFIG_NAME, VARIABLE_NAME)
51+
VARIABLE_NAME = "VARIABLE_NAME"
52+
CONFIG_NAME = "CONFIG_NAME"
53+
PROJECT = "my-project-1234"
54+
PATH = "projects/%s/configs/%s/variables/%s" % (
55+
PROJECT,
56+
CONFIG_NAME,
57+
VARIABLE_NAME,
58+
)
6059
variable_name = self._call_fut(PATH)
6160
self.assertEqual(variable_name, VARIABLE_NAME)
6261

6362
def test_w_name_w_all_extras(self):
64-
VARIABLE_NAME = 'VARIABLE_NAME-part.one/part.two/part-three'
65-
CONFIG_NAME = 'CONFIG_NAME'
66-
PROJECT = 'my-project-1234'
67-
PATH = 'projects/%s/configs/%s/variables/%s' % (
68-
PROJECT, CONFIG_NAME, VARIABLE_NAME)
63+
VARIABLE_NAME = "VARIABLE_NAME-part.one/part.two/part-three"
64+
CONFIG_NAME = "CONFIG_NAME"
65+
PROJECT = "my-project-1234"
66+
PATH = "projects/%s/configs/%s/variables/%s" % (
67+
PROJECT,
68+
CONFIG_NAME,
69+
VARIABLE_NAME,
70+
)
6971
variable_name = self._call_fut(PATH)
7072
self.assertEqual(variable_name, VARIABLE_NAME)
7173

7274
def test_w_bad_format(self):
73-
PATH = 'definitley/not/a/resource/name/for/a/variable'
75+
PATH = "definitley/not/a/resource/name/for/a/variable"
7476
with self.assertRaises(ValueError):
7577
self._call_fut(PATH)

0 commit comments

Comments
 (0)