Skip to content

Commit

Permalink
fix: fix lint sessions on generated samples (#1192)
Browse files Browse the repository at this point in the history
  • Loading branch information
parthea authored Feb 9, 2022
1 parent d4ad77e commit 4d0ea18
Show file tree
Hide file tree
Showing 49 changed files with 505 additions and 87 deletions.
1 change: 1 addition & 0 deletions .github/sync-repo-settings.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ branchProtectionRules:
- 'showcase-unit (3.9, _alternative_templates)'
- 'showcase-unit-add-iam-methods'
- 'integration'
- 'goldens-lint'
- 'style-check'
- 'snippetgen'
- 'unit (3.6)'
Expand Down
18 changes: 18 additions & 0 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,24 @@ jobs:
echo "The old one will disappear after 7 days."
- name: Integration Tests
run: bazel test tests/integration:asset tests/integration:credentials tests/integration:logging tests/integration:redis
goldens-lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up Python 3.9
uses: actions/setup-python@v2
with:
python-version: 3.9
cache: 'pip'
- name: Install nox.
run: |
python -m pip install nox
- name: Run blacken and lint on the generated output.
run: |
nox -f tests/integration/goldens/asset/noxfile.py -s blacken lint_setup_py lint
nox -f tests/integration/goldens/credentials/noxfile.py -s blacken lint_setup_py lint
nox -f tests/integration/goldens/logging/noxfile.py -s blacken lint_setup_py lint
nox -f tests/integration/goldens/redis/noxfile.py -s blacken lint_setup_py lint
style-check:
runs-on: ubuntu-latest
steps:
Expand Down
33 changes: 33 additions & 0 deletions gapic/templates/.flake8.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# -*- coding: utf-8 -*-
#
# Copyright 2020 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# Generated by synthtool. DO NOT EDIT!
[flake8]
ignore = E203, E266, E501, W503
exclude =
# Exclude generated code.
**/proto/**
**/gapic/**
**/services/**
**/types/**
*_pb2.py

# Standard linting exemptions.
**/.nox/**
__pycache__,
.git,
*.pyc,
conf.py
5 changes: 3 additions & 2 deletions gapic/templates/examples/feature_fragments.j2
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ configs the client streaming logic should be modified to allow 2+ request object
# Here we create a generator that yields a single `request` for
# demonstrative purposes.
requests = [request]

def request_generator():
for request in requests:
yield request
Expand Down Expand Up @@ -245,8 +246,8 @@ client.{{ sample.rpc|snake_case }}({{ render_request_params_unary(sample.request
{# it's just easier to set up client side streaming and other things from outside this macro. #}
{% macro render_calling_form(method_invocation_text, calling_form, calling_form_enum, transport, response_statements ) %}
# Make the request
{% if calling_form == calling_form_enum.Request %}
response = {{ method_invocation_text|trim }}
{% if calling_form in [calling_form_enum.Request, calling_form_enum.RequestStreamingClient] %}
{% if response_statements %}response = {% endif %}{{ method_invocation_text|trim }}

{% if response_statements %}
# Handle the response
Expand Down
44 changes: 42 additions & 2 deletions gapic/templates/noxfile.py.j2
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ CURRENT_DIRECTORY = pathlib.Path(__file__).parent.absolute()
LOWER_BOUND_CONSTRAINTS_FILE = CURRENT_DIRECTORY / "constraints.txt"
PACKAGE_NAME = subprocess.check_output([sys.executable, "setup.py", "--name"], encoding="utf-8")

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

nox.sessions = [
"unit",
Expand All @@ -24,6 +27,9 @@ nox.sessions = [
"check_lower_bounds"
# exclude update_lower_bounds from default
"docs",
"blacken",
"lint",
"lint_setup_py",
]

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


@nox.session(python='3.9')
@nox.session(python=DEFAULT_PYTHON_VERSION)
def cover(session):
"""Run the final coverage report.
This outputs the coverage report aggregating coverage from the unit
Expand Down Expand Up @@ -103,7 +109,7 @@ def check_lower_bounds(session):
str(LOWER_BOUND_CONSTRAINTS_FILE),
)

@nox.session(python='3.9')
@nox.session(python=DEFAULT_PYTHON_VERSION)
def docs(session):
"""Build the docs for this library."""

Expand All @@ -123,4 +129,38 @@ def docs(session):
os.path.join("docs", ""),
os.path.join("docs", "_build", "html", ""),
)


@nox.session(python=DEFAULT_PYTHON_VERSION)
def lint(session):
"""Run linters.

Returns a failure if the linters find linting errors or sufficiently
serious code quality issues.
"""
session.install("flake8", BLACK_VERSION)
session.run(
"black",
"--check",
*BLACK_PATHS,
)
session.run("flake8", "google", "tests", "samples")


@nox.session(python=DEFAULT_PYTHON_VERSION)
def blacken(session):
"""Run black. Format code to uniform standard."""
session.install(BLACK_VERSION)
session.run(
"black",
*BLACK_PATHS,
)


@nox.session(python=DEFAULT_PYTHON_VERSION)
def lint_setup_py(session):
"""Verify that setup.py is valid (including RST check)."""
session.install("docutils", "pygments")
session.run("python", "setup.py", "check", "--restructuredtext", "--strict")

{% endblock %}
3 changes: 3 additions & 0 deletions gapic/templates/setup.py.j2
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ with io.open(readme_filename, encoding='utf-8') as readme_file:

setuptools.setup(
name='{{ api.naming.warehouse_package_name }}',
author="Google LLC",
author_email="googleapis-packages@google.com",
url="https://github.com/googleapis/python-{{ api.naming.warehouse_package_name }}",
version=version,
long_description=readme,
{% if api.naming.namespace %}
Expand Down
33 changes: 33 additions & 0 deletions tests/integration/goldens/asset/.flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# -*- coding: utf-8 -*-
#
# Copyright 2020 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# Generated by synthtool. DO NOT EDIT!
[flake8]
ignore = E203, E266, E501, W503
exclude =
# Exclude generated code.
**/proto/**
**/gapic/**
**/services/**
**/types/**
*_pb2.py

# Standard linting exemptions.
**/.nox/**
__pycache__,
.git,
*.pyc,
conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -943,7 +943,7 @@ def sample_delete_feed():
)
# Make the request
response = client.delete_feed(request=request)
client.delete_feed(request=request)
Args:
request (Union[google.cloud.asset_v1.types.DeleteFeedRequest, dict]):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1128,7 +1128,7 @@ def sample_delete_feed():
)
# Make the request
response = client.delete_feed(request=request)
client.delete_feed(request=request)
Args:
request (Union[google.cloud.asset_v1.types.DeleteFeedRequest, dict]):
Expand Down
43 changes: 41 additions & 2 deletions tests/integration/goldens/asset/noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@
LOWER_BOUND_CONSTRAINTS_FILE = CURRENT_DIRECTORY / "constraints.txt"
PACKAGE_NAME = subprocess.check_output([sys.executable, "setup.py", "--name"], encoding="utf-8")

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

nox.sessions = [
"unit",
Expand All @@ -35,6 +38,9 @@
"check_lower_bounds"
# exclude update_lower_bounds from default
"docs",
"blacken",
"lint",
"lint_setup_py",
]

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


@nox.session(python='3.9')
@nox.session(python=DEFAULT_PYTHON_VERSION)
def cover(session):
"""Run the final coverage report.
This outputs the coverage report aggregating coverage from the unit
Expand Down Expand Up @@ -110,7 +116,7 @@ def check_lower_bounds(session):
str(LOWER_BOUND_CONSTRAINTS_FILE),
)

@nox.session(python='3.9')
@nox.session(python=DEFAULT_PYTHON_VERSION)
def docs(session):
"""Build the docs for this library."""

Expand All @@ -130,3 +136,36 @@ def docs(session):
os.path.join("docs", ""),
os.path.join("docs", "_build", "html", ""),
)


@nox.session(python=DEFAULT_PYTHON_VERSION)
def lint(session):
"""Run linters.
Returns a failure if the linters find linting errors or sufficiently
serious code quality issues.
"""
session.install("flake8", BLACK_VERSION)
session.run(
"black",
"--check",
*BLACK_PATHS,
)
session.run("flake8", "google", "tests", "samples")


@nox.session(python=DEFAULT_PYTHON_VERSION)
def blacken(session):
"""Run black. Format code to uniform standard."""
session.install(BLACK_VERSION)
session.run(
"black",
*BLACK_PATHS,
)


@nox.session(python=DEFAULT_PYTHON_VERSION)
def lint_setup_py(session):
"""Verify that setup.py is valid (including RST check)."""
session.install("docutils", "pygments")
session.run("python", "setup.py", "check", "--restructuredtext", "--strict")
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ async def sample_delete_feed():
)

# Make the request
response = await client.delete_feed(request=request)
await client.delete_feed(request=request)


# [END cloudasset_generated_asset_v1_AssetService_DeleteFeed_async]
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def sample_delete_feed():
)

# Make the request
response = client.delete_feed(request=request)
client.delete_feed(request=request)


# [END cloudasset_generated_asset_v1_AssetService_DeleteFeed_sync]
3 changes: 3 additions & 0 deletions tests/integration/goldens/asset/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@

setuptools.setup(
name='google-cloud-asset',
author="Google LLC",
author_email="googleapis-packages@google.com",
url="https://github.com/googleapis/python-google-cloud-asset",
version=version,
long_description=readme,
packages=setuptools.PEP420PackageFinder.find(),
Expand Down
33 changes: 33 additions & 0 deletions tests/integration/goldens/credentials/.flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# -*- coding: utf-8 -*-
#
# Copyright 2020 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# Generated by synthtool. DO NOT EDIT!
[flake8]
ignore = E203, E266, E501, W503
exclude =
# Exclude generated code.
**/proto/**
**/gapic/**
**/services/**
**/types/**
*_pb2.py

# Standard linting exemptions.
**/.nox/**
__pycache__,
.git,
*.pyc,
conf.py
Loading

0 comments on commit 4d0ea18

Please sign in to comment.