Skip to content

Commit 4d0ea18

Browse files
authored
fix: fix lint sessions on generated samples (googleapis#1192)
1 parent d4ad77e commit 4d0ea18

File tree

49 files changed

+505
-87
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+505
-87
lines changed

.github/sync-repo-settings.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ branchProtectionRules:
2323
- 'showcase-unit (3.9, _alternative_templates)'
2424
- 'showcase-unit-add-iam-methods'
2525
- 'integration'
26+
- 'goldens-lint'
2627
- 'style-check'
2728
- 'snippetgen'
2829
- 'unit (3.6)'

.github/workflows/tests.yaml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,24 @@ jobs:
316316
echo "The old one will disappear after 7 days."
317317
- name: Integration Tests
318318
run: bazel test tests/integration:asset tests/integration:credentials tests/integration:logging tests/integration:redis
319+
goldens-lint:
320+
runs-on: ubuntu-latest
321+
steps:
322+
- uses: actions/checkout@v2
323+
- name: Set up Python 3.9
324+
uses: actions/setup-python@v2
325+
with:
326+
python-version: 3.9
327+
cache: 'pip'
328+
- name: Install nox.
329+
run: |
330+
python -m pip install nox
331+
- name: Run blacken and lint on the generated output.
332+
run: |
333+
nox -f tests/integration/goldens/asset/noxfile.py -s blacken lint_setup_py lint
334+
nox -f tests/integration/goldens/credentials/noxfile.py -s blacken lint_setup_py lint
335+
nox -f tests/integration/goldens/logging/noxfile.py -s blacken lint_setup_py lint
336+
nox -f tests/integration/goldens/redis/noxfile.py -s blacken lint_setup_py lint
319337
style-check:
320338
runs-on: ubuntu-latest
321339
steps:

gapic/templates/.flake8.j2

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# -*- coding: utf-8 -*-
2+
#
3+
# Copyright 2020 Google LLC
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# https://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
# Generated by synthtool. DO NOT EDIT!
18+
[flake8]
19+
ignore = E203, E266, E501, W503
20+
exclude =
21+
# Exclude generated code.
22+
**/proto/**
23+
**/gapic/**
24+
**/services/**
25+
**/types/**
26+
*_pb2.py
27+
28+
# Standard linting exemptions.
29+
**/.nox/**
30+
__pycache__,
31+
.git,
32+
*.pyc,
33+
conf.py

gapic/templates/examples/feature_fragments.j2

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,7 @@ configs the client streaming logic should be modified to allow 2+ request object
190190
# Here we create a generator that yields a single `request` for
191191
# demonstrative purposes.
192192
requests = [request]
193+
193194
def request_generator():
194195
for request in requests:
195196
yield request
@@ -245,8 +246,8 @@ client.{{ sample.rpc|snake_case }}({{ render_request_params_unary(sample.request
245246
{# it's just easier to set up client side streaming and other things from outside this macro. #}
246247
{% macro render_calling_form(method_invocation_text, calling_form, calling_form_enum, transport, response_statements ) %}
247248
# Make the request
248-
{% if calling_form == calling_form_enum.Request %}
249-
response = {{ method_invocation_text|trim }}
249+
{% if calling_form in [calling_form_enum.Request, calling_form_enum.RequestStreamingClient] %}
250+
{% if response_statements %}response = {% endif %}{{ method_invocation_text|trim }}
250251

251252
{% if response_statements %}
252253
# Handle the response

gapic/templates/noxfile.py.j2

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ CURRENT_DIRECTORY = pathlib.Path(__file__).parent.absolute()
1616
LOWER_BOUND_CONSTRAINTS_FILE = CURRENT_DIRECTORY / "constraints.txt"
1717
PACKAGE_NAME = subprocess.check_output([sys.executable, "setup.py", "--name"], encoding="utf-8")
1818

19+
BLACK_VERSION = "black==19.10b0"
20+
BLACK_PATHS = ["docs", "google", "tests", "samples", "noxfile.py", "setup.py"]
21+
DEFAULT_PYTHON_VERSION = "3.9"
1922

2023
nox.sessions = [
2124
"unit",
@@ -24,6 +27,9 @@ nox.sessions = [
2427
"check_lower_bounds"
2528
# exclude update_lower_bounds from default
2629
"docs",
30+
"blacken",
31+
"lint",
32+
"lint_setup_py",
2733
]
2834

2935
@nox.session(python=['3.6', '3.7', '3.8', '3.9', '3.10'])
@@ -44,7 +50,7 @@ def unit(session):
4450
)
4551

4652

47-
@nox.session(python='3.9')
53+
@nox.session(python=DEFAULT_PYTHON_VERSION)
4854
def cover(session):
4955
"""Run the final coverage report.
5056
This outputs the coverage report aggregating coverage from the unit
@@ -103,7 +109,7 @@ def check_lower_bounds(session):
103109
str(LOWER_BOUND_CONSTRAINTS_FILE),
104110
)
105111

106-
@nox.session(python='3.9')
112+
@nox.session(python=DEFAULT_PYTHON_VERSION)
107113
def docs(session):
108114
"""Build the docs for this library."""
109115

@@ -123,4 +129,38 @@ def docs(session):
123129
os.path.join("docs", ""),
124130
os.path.join("docs", "_build", "html", ""),
125131
)
132+
133+
134+
@nox.session(python=DEFAULT_PYTHON_VERSION)
135+
def lint(session):
136+
"""Run linters.
137+
138+
Returns a failure if the linters find linting errors or sufficiently
139+
serious code quality issues.
140+
"""
141+
session.install("flake8", BLACK_VERSION)
142+
session.run(
143+
"black",
144+
"--check",
145+
*BLACK_PATHS,
146+
)
147+
session.run("flake8", "google", "tests", "samples")
148+
149+
150+
@nox.session(python=DEFAULT_PYTHON_VERSION)
151+
def blacken(session):
152+
"""Run black. Format code to uniform standard."""
153+
session.install(BLACK_VERSION)
154+
session.run(
155+
"black",
156+
*BLACK_PATHS,
157+
)
158+
159+
160+
@nox.session(python=DEFAULT_PYTHON_VERSION)
161+
def lint_setup_py(session):
162+
"""Verify that setup.py is valid (including RST check)."""
163+
session.install("docutils", "pygments")
164+
session.run("python", "setup.py", "check", "--restructuredtext", "--strict")
165+
126166
{% endblock %}

gapic/templates/setup.py.j2

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ with io.open(readme_filename, encoding='utf-8') as readme_file:
1616

1717
setuptools.setup(
1818
name='{{ api.naming.warehouse_package_name }}',
19+
author="Google LLC",
20+
author_email="[email protected]",
21+
url="https://github.com/googleapis/python-{{ api.naming.warehouse_package_name }}",
1922
version=version,
2023
long_description=readme,
2124
{% if api.naming.namespace %}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# -*- coding: utf-8 -*-
2+
#
3+
# Copyright 2020 Google LLC
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# https://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
# Generated by synthtool. DO NOT EDIT!
18+
[flake8]
19+
ignore = E203, E266, E501, W503
20+
exclude =
21+
# Exclude generated code.
22+
**/proto/**
23+
**/gapic/**
24+
**/services/**
25+
**/types/**
26+
*_pb2.py
27+
28+
# Standard linting exemptions.
29+
**/.nox/**
30+
__pycache__,
31+
.git,
32+
*.pyc,
33+
conf.py

tests/integration/goldens/asset/google/cloud/asset_v1/services/asset_service/async_client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -943,7 +943,7 @@ def sample_delete_feed():
943943
)
944944
945945
# Make the request
946-
response = client.delete_feed(request=request)
946+
client.delete_feed(request=request)
947947
948948
Args:
949949
request (Union[google.cloud.asset_v1.types.DeleteFeedRequest, dict]):

tests/integration/goldens/asset/google/cloud/asset_v1/services/asset_service/client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1128,7 +1128,7 @@ def sample_delete_feed():
11281128
)
11291129
11301130
# Make the request
1131-
response = client.delete_feed(request=request)
1131+
client.delete_feed(request=request)
11321132
11331133
Args:
11341134
request (Union[google.cloud.asset_v1.types.DeleteFeedRequest, dict]):

tests/integration/goldens/asset/noxfile.py

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@
2727
LOWER_BOUND_CONSTRAINTS_FILE = CURRENT_DIRECTORY / "constraints.txt"
2828
PACKAGE_NAME = subprocess.check_output([sys.executable, "setup.py", "--name"], encoding="utf-8")
2929

30+
BLACK_VERSION = "black==19.10b0"
31+
BLACK_PATHS = ["docs", "google", "tests", "samples", "noxfile.py", "setup.py"]
32+
DEFAULT_PYTHON_VERSION = "3.9"
3033

3134
nox.sessions = [
3235
"unit",
@@ -35,6 +38,9 @@
3538
"check_lower_bounds"
3639
# exclude update_lower_bounds from default
3740
"docs",
41+
"blacken",
42+
"lint",
43+
"lint_setup_py",
3844
]
3945

4046
@nox.session(python=['3.6', '3.7', '3.8', '3.9', '3.10'])
@@ -55,7 +61,7 @@ def unit(session):
5561
)
5662

5763

58-
@nox.session(python='3.9')
64+
@nox.session(python=DEFAULT_PYTHON_VERSION)
5965
def cover(session):
6066
"""Run the final coverage report.
6167
This outputs the coverage report aggregating coverage from the unit
@@ -110,7 +116,7 @@ def check_lower_bounds(session):
110116
str(LOWER_BOUND_CONSTRAINTS_FILE),
111117
)
112118

113-
@nox.session(python='3.9')
119+
@nox.session(python=DEFAULT_PYTHON_VERSION)
114120
def docs(session):
115121
"""Build the docs for this library."""
116122

@@ -130,3 +136,36 @@ def docs(session):
130136
os.path.join("docs", ""),
131137
os.path.join("docs", "_build", "html", ""),
132138
)
139+
140+
141+
@nox.session(python=DEFAULT_PYTHON_VERSION)
142+
def lint(session):
143+
"""Run linters.
144+
145+
Returns a failure if the linters find linting errors or sufficiently
146+
serious code quality issues.
147+
"""
148+
session.install("flake8", BLACK_VERSION)
149+
session.run(
150+
"black",
151+
"--check",
152+
*BLACK_PATHS,
153+
)
154+
session.run("flake8", "google", "tests", "samples")
155+
156+
157+
@nox.session(python=DEFAULT_PYTHON_VERSION)
158+
def blacken(session):
159+
"""Run black. Format code to uniform standard."""
160+
session.install(BLACK_VERSION)
161+
session.run(
162+
"black",
163+
*BLACK_PATHS,
164+
)
165+
166+
167+
@nox.session(python=DEFAULT_PYTHON_VERSION)
168+
def lint_setup_py(session):
169+
"""Verify that setup.py is valid (including RST check)."""
170+
session.install("docutils", "pygments")
171+
session.run("python", "setup.py", "check", "--restructuredtext", "--strict")

tests/integration/goldens/asset/samples/generated_samples/cloudasset_generated_asset_v1_asset_service_delete_feed_async.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ async def sample_delete_feed():
3737
)
3838

3939
# Make the request
40-
response = await client.delete_feed(request=request)
40+
await client.delete_feed(request=request)
4141

4242

4343
# [END cloudasset_generated_asset_v1_AssetService_DeleteFeed_async]

tests/integration/goldens/asset/samples/generated_samples/cloudasset_generated_asset_v1_asset_service_delete_feed_sync.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def sample_delete_feed():
3737
)
3838

3939
# Make the request
40-
response = client.delete_feed(request=request)
40+
client.delete_feed(request=request)
4141

4242

4343
# [END cloudasset_generated_asset_v1_AssetService_DeleteFeed_sync]

tests/integration/goldens/asset/setup.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@
2727

2828
setuptools.setup(
2929
name='google-cloud-asset',
30+
author="Google LLC",
31+
author_email="[email protected]",
32+
url="https://github.com/googleapis/python-google-cloud-asset",
3033
version=version,
3134
long_description=readme,
3235
packages=setuptools.PEP420PackageFinder.find(),
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# -*- coding: utf-8 -*-
2+
#
3+
# Copyright 2020 Google LLC
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# https://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
# Generated by synthtool. DO NOT EDIT!
18+
[flake8]
19+
ignore = E203, E266, E501, W503
20+
exclude =
21+
# Exclude generated code.
22+
**/proto/**
23+
**/gapic/**
24+
**/services/**
25+
**/types/**
26+
*_pb2.py
27+
28+
# Standard linting exemptions.
29+
**/.nox/**
30+
__pycache__,
31+
.git,
32+
*.pyc,
33+
conf.py

0 commit comments

Comments
 (0)