Skip to content

Commit d0a3a7e

Browse files
authored
add blacken to noxfile (googleapis#6795)
1 parent 91fcc6a commit d0a3a7e

File tree

13 files changed

+386
-378
lines changed

13 files changed

+386
-378
lines changed

dns/noxfile.py

Lines changed: 39 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,45 @@
2525
)
2626

2727

28+
@nox.session(python="3.7")
29+
def lint(session):
30+
"""Run linters.
31+
Returns a failure if the linters find linting errors or sufficiently
32+
serious code quality issues.
33+
"""
34+
session.install("flake8", "black", *LOCAL_DEPS)
35+
session.run(
36+
"black",
37+
"--check",
38+
"google",
39+
"tests",
40+
"docs",
41+
)
42+
session.run("flake8", "google", "tests")
43+
44+
45+
@nox.session(python="3.6")
46+
def blacken(session):
47+
"""Run black.
48+
Format code to uniform standard.
49+
"""
50+
session.install("black")
51+
session.run(
52+
"black",
53+
"google",
54+
"tests",
55+
"docs",
56+
)
57+
58+
59+
@nox.session(python='3.6')
60+
def lint_setup_py(session):
61+
"""Verify that setup.py is valid (including RST check)."""
62+
session.install('docutils', 'Pygments')
63+
session.run(
64+
'python', 'setup.py', 'check', '--restructuredtext', '--strict')
65+
66+
2867
def default(session):
2968
"""Default unit test session.
3069
@@ -60,27 +99,6 @@ def unit(session):
6099
default(session)
61100

62101

63-
@nox.session(python='3.6')
64-
def lint(session):
65-
"""Run linters.
66-
67-
Returns a failure if the linters find linting errors or sufficiently
68-
serious code quality issues.
69-
"""
70-
session.install('flake8', *LOCAL_DEPS)
71-
session.install('.')
72-
session.run('flake8', 'google', 'tests')
73-
74-
75-
@nox.session(python='3.6')
76-
def lint_setup_py(session):
77-
"""Verify that setup.py is valid (including RST check)."""
78-
79-
session.install('docutils', 'Pygments')
80-
session.run(
81-
'python', 'setup.py', 'check', '--restructuredtext', '--strict')
82-
83-
84102
@nox.session(python='3.6')
85103
def cover(session):
86104
"""Run the final coverage report.

resource_manager/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__)

resource_manager/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__)

resource_manager/google/cloud/resource_manager/__init__.py

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

1717

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

2122
from google.cloud.resource_manager.client import Client
2223
from google.cloud.resource_manager.project import Project
2324

2425

2526
SCOPE = Client.SCOPE
2627

27-
__all__ = ['__version__', 'Client', 'Project', 'SCOPE']
28+
__all__ = ["__version__", "Client", "Project", "SCOPE"]

resource_manager/google/cloud/resource_manager/_http.py

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

33-
API_BASE_URL = 'https://cloudresourcemanager.googleapis.com'
33+
API_BASE_URL = "https://cloudresourcemanager.googleapis.com"
3434
"""The base of the API call URL."""
3535

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

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

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

resource_manager/google/cloud/resource_manager/client.py

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,11 @@ class Client(BaseClient):
5151
change in the future.
5252
"""
5353

54-
SCOPE = ('https://www.googleapis.com/auth/cloud-platform',)
54+
SCOPE = ("https://www.googleapis.com/auth/cloud-platform",)
5555
"""The scopes required for authenticating as a Resouce Manager consumer."""
5656

5757
def __init__(self, credentials=None, _http=None):
58-
super(Client, self).__init__(
59-
credentials=credentials, _http=_http)
58+
super(Client, self).__init__(credentials=credentials, _http=_http)
6059
self._connection = Connection(self)
6160

6261
def new_project(self, project_id, name=None, labels=None):
@@ -85,8 +84,7 @@ def new_project(self, project_id, name=None, labels=None):
8584
:class:`~google.cloud.resource_manager.project.Project`
8685
**without** any metadata loaded.
8786
"""
88-
return Project(project_id=project_id,
89-
client=self, name=name, labels=labels)
87+
return Project(project_id=project_id, client=self, name=name, labels=labels)
9088

9189
def fetch_project(self, project_id):
9290
"""Fetch an existing project and it's relevant metadata by ID.
@@ -160,21 +158,22 @@ def list_projects(self, filter_params=None, page_size=None):
160158
extra_params = {}
161159

162160
if page_size is not None:
163-
extra_params['pageSize'] = page_size
161+
extra_params["pageSize"] = page_size
164162

165163
if filter_params is not None:
166-
extra_params['filter'] = [
167-
'{}:{}'.format(key, value)
164+
extra_params["filter"] = [
165+
"{}:{}".format(key, value)
168166
for key, value in six.iteritems(filter_params)
169167
]
170168

171169
return page_iterator.HTTPIterator(
172170
client=self,
173171
api_request=self._connection.api_request,
174-
path='/projects',
172+
path="/projects",
175173
item_to_value=_item_to_project,
176-
items_key='projects',
177-
extra_params=extra_params)
174+
items_key="projects",
175+
extra_params=extra_params,
176+
)
178177

179178

180179
def _item_to_project(iterator, resource):

resource_manager/google/cloud/resource_manager/project.py

Lines changed: 22 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ class Project(object):
5151
:type labels: dict
5252
:param labels: A list of labels associated with the project.
5353
"""
54+
5455
def __init__(self, project_id, client, name=None, labels=None):
5556
self._client = client
5657
self.project_id = project_id
@@ -61,7 +62,7 @@ def __init__(self, project_id, client, name=None, labels=None):
6162
self.parent = None
6263

6364
def __repr__(self):
64-
return '<Project: %r (%r)>' % (self.name, self.project_id)
65+
return "<Project: %r (%r)>" % (self.name, self.project_id)
6566

6667
@classmethod
6768
def from_api_repr(cls, resource, client):
@@ -76,30 +77,30 @@ def from_api_repr(cls, resource, client):
7677
:rtype: :class:`google.cloud.resource_manager.project.Project`
7778
:returns: The project created.
7879
"""
79-
project = cls(project_id=resource['projectId'], client=client)
80+
project = cls(project_id=resource["projectId"], client=client)
8081
project.set_properties_from_api_repr(resource)
8182
return project
8283

8384
def set_properties_from_api_repr(self, resource):
8485
"""Update specific properties from its API representation."""
85-
self.name = resource.get('name')
86-
self.number = resource['projectNumber']
87-
self.labels = resource.get('labels', {})
88-
self.status = resource['lifecycleState']
89-
if 'parent' in resource:
90-
self.parent = resource['parent']
86+
self.name = resource.get("name")
87+
self.number = resource["projectNumber"]
88+
self.labels = resource.get("labels", {})
89+
self.status = resource["lifecycleState"]
90+
if "parent" in resource:
91+
self.parent = resource["parent"]
9192

9293
@property
9394
def full_name(self):
9495
"""Fully-qualified name (ie, ``'projects/purple-spaceship-123'``)."""
9596
if not self.project_id:
96-
raise ValueError('Missing project ID.')
97-
return 'projects/%s' % (self.project_id)
97+
raise ValueError("Missing project ID.")
98+
return "projects/%s" % (self.project_id)
9899

99100
@property
100101
def path(self):
101102
"""URL for the project (ie, ``'/projects/purple-spaceship-123'``)."""
102-
return '/%s' % (self.full_name)
103+
return "/%s" % (self.full_name)
103104

104105
def _require_client(self, client):
105106
"""Check client or verify over-ride.
@@ -129,13 +130,10 @@ def create(self, client=None):
129130
"""
130131
client = self._require_client(client)
131132

132-
data = {
133-
'projectId': self.project_id,
134-
'name': self.name,
135-
'labels': self.labels,
136-
}
137-
resp = client._connection.api_request(method='POST', path='/projects',
138-
data=data)
133+
data = {"projectId": self.project_id, "name": self.name, "labels": self.labels}
134+
resp = client._connection.api_request(
135+
method="POST", path="/projects", data=data
136+
)
139137
self.set_properties_from_api_repr(resource=resp)
140138

141139
def reload(self, client=None):
@@ -164,7 +162,7 @@ def reload(self, client=None):
164162

165163
# We assume the project exists. If it doesn't it will raise a NotFound
166164
# exception.
167-
resp = client._connection.api_request(method='GET', path=self.path)
165+
resp = client._connection.api_request(method="GET", path=self.path)
168166
self.set_properties_from_api_repr(resource=resp)
169167

170168
def exists(self, client=None):
@@ -186,7 +184,7 @@ def exists(self, client=None):
186184
try:
187185
# Note that we have to request the entire resource as the API
188186
# doesn't provide a way tocheck for existence only.
189-
client._connection.api_request(method='GET', path=self.path)
187+
client._connection.api_request(method="GET", path=self.path)
190188
except NotFound:
191189
return False
192190
else:
@@ -205,14 +203,9 @@ def update(self, client=None):
205203
"""
206204
client = self._require_client(client)
207205

208-
data = {
209-
'name': self.name,
210-
'labels': self.labels,
211-
'parent': self.parent,
212-
}
206+
data = {"name": self.name, "labels": self.labels, "parent": self.parent}
213207

214-
resp = client._connection.api_request(
215-
method='PUT', path=self.path, data=data)
208+
resp = client._connection.api_request(method="PUT", path=self.path, data=data)
216209
self.set_properties_from_api_repr(resp)
217210

218211
def delete(self, client=None, reload_data=False):
@@ -240,7 +233,7 @@ def delete(self, client=None, reload_data=False):
240233
Default: :data:`False`.
241234
"""
242235
client = self._require_client(client)
243-
client._connection.api_request(method='DELETE', path=self.path)
236+
client._connection.api_request(method="DELETE", path=self.path)
244237

245238
# If the reload flag is set, reload the project.
246239
if reload_data:
@@ -270,8 +263,7 @@ def undelete(self, client=None, reload_data=False):
270263
Default: :data:`False`.
271264
"""
272265
client = self._require_client(client)
273-
client._connection.api_request(
274-
method='POST', path=self.path + ':undelete')
266+
client._connection.api_request(method="POST", path=self.path + ":undelete")
275267

276268
# If the reload flag is set, reload the project.
277269
if reload_data:

resource_manager/noxfile.py

Lines changed: 39 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,45 @@
2525
)
2626

2727

28+
@nox.session(python="3.7")
29+
def lint(session):
30+
"""Run linters.
31+
Returns a failure if the linters find linting errors or sufficiently
32+
serious code quality issues.
33+
"""
34+
session.install("flake8", "black", *LOCAL_DEPS)
35+
session.run(
36+
"black",
37+
"--check",
38+
"google",
39+
"tests",
40+
"docs",
41+
)
42+
session.run("flake8", "google", "tests")
43+
44+
45+
@nox.session(python="3.6")
46+
def blacken(session):
47+
"""Run black.
48+
Format code to uniform standard.
49+
"""
50+
session.install("black")
51+
session.run(
52+
"black",
53+
"google",
54+
"tests",
55+
"docs",
56+
)
57+
58+
59+
@nox.session(python='3.6')
60+
def lint_setup_py(session):
61+
"""Verify that setup.py is valid (including RST check)."""
62+
session.install('docutils', 'Pygments')
63+
session.run(
64+
'python', 'setup.py', 'check', '--restructuredtext', '--strict')
65+
66+
2867
def default(session):
2968
"""Default unit test session.
3069
@@ -58,27 +97,6 @@ def unit(session):
5897
default(session)
5998

6099

61-
@nox.session(python='3.6')
62-
def lint(session):
63-
"""Run linters.
64-
65-
Returns a failure if the linters find linting errors or sufficiently
66-
serious code quality issues.
67-
"""
68-
session.install('flake8', *LOCAL_DEPS)
69-
session.install('.')
70-
session.run('flake8', 'google', 'tests')
71-
72-
73-
@nox.session(python='3.6')
74-
def lint_setup_py(session):
75-
"""Verify that setup.py is valid (including RST check)."""
76-
77-
session.install('docutils', 'Pygments')
78-
session.run(
79-
'python', 'setup.py', 'check', '--restructuredtext', '--strict')
80-
81-
82100
@nox.session(python='3.6')
83101
def cover(session):
84102
"""Run the final coverage report.

0 commit comments

Comments
 (0)