From 777218db12802d71bfb695e1324bdf7e089e61c9 Mon Sep 17 00:00:00 2001 From: Takashi Matsuo Date: Tue, 12 May 2020 17:57:14 -0700 Subject: [PATCH] chore: some lint fixes (#3749) --- run/image-processing/main.py | 5 ++++- run/image-processing/main_test.py | 10 +++++----- run/logging-manual/main.py | 4 +++- run/logging-manual/main_test.py | 2 +- run/markdown-preview/editor/main.py | 4 +++- run/markdown-preview/editor/main_test.py | 6 ++++-- run/markdown-preview/noxfile.py | 16 +++++++++++----- run/markdown-preview/renderer/main.py | 3 ++- run/markdown-preview/renderer/main_test.py | 3 ++- run/pubsub/main.py | 4 +++- run/system-package/main.py | 3 ++- run/system-package/main_test.py | 3 +-- secretmanager/api-client/snippets_test.py | 10 +++++----- spanner/cloud-client/backup_sample_test.py | 4 ++-- 14 files changed, 48 insertions(+), 29 deletions(-) diff --git a/run/image-processing/main.py b/run/image-processing/main.py index 53e939bec7a1..c590e15a739a 100644 --- a/run/image-processing/main.py +++ b/run/image-processing/main.py @@ -14,12 +14,15 @@ # [START run_imageproc_controller] import base64 -from flask import Flask, request import json import os import sys + +from flask import Flask, request + import image + app = Flask(__name__) diff --git a/run/image-processing/main_test.py b/run/image-processing/main_test.py index 1e9c30216a5b..60d05a6aecd9 100644 --- a/run/image-processing/main_test.py +++ b/run/image-processing/main_test.py @@ -14,14 +14,14 @@ # NOTE: # These tests are unit tests that mock Pub/Sub. - import base64 import json -import main +import uuid + import mock import pytest -from uuid import uuid4 +import main @pytest.fixture @@ -55,8 +55,8 @@ def test_minimally_valid_message(client): def test_call_to_blur_image(client, capsys): - filename = str(uuid4()) - blur_bucket = 'blurred-bucket-' + str(uuid4()) + filename = str(uuid.uuid4()) + blur_bucket = 'blurred-bucket-' + str(uuid.uuid4()) data_json = json.dumps({'name': filename, 'bucket': blur_bucket}) data = base64.b64encode(data_json.encode()).decode() diff --git a/run/logging-manual/main.py b/run/logging-manual/main.py index 29e92ab7c8a9..29fc5a764945 100644 --- a/run/logging-manual/main.py +++ b/run/logging-manual/main.py @@ -12,11 +12,13 @@ # See the License for the specific language governing permissions and # limitations under the License. -from flask import Flask, request import json import os import sys +from flask import Flask, request + + app = Flask(__name__) diff --git a/run/logging-manual/main_test.py b/run/logging-manual/main_test.py index 6266451f5de4..5acc65cd9782 100644 --- a/run/logging-manual/main_test.py +++ b/run/logging-manual/main_test.py @@ -15,8 +15,8 @@ # NOTE: # These unit tests mock logging. - import pytest + import main diff --git a/run/markdown-preview/editor/main.py b/run/markdown-preview/editor/main.py index 83dd1d83a440..f06e442b16ee 100644 --- a/run/markdown-preview/editor/main.py +++ b/run/markdown-preview/editor/main.py @@ -12,11 +12,13 @@ # See the License for the specific language governing permissions and # limitations under the License. -from flask import Flask, render_template, request import os +from flask import Flask, render_template, request + import render + app = Flask(__name__) diff --git a/run/markdown-preview/editor/main_test.py b/run/markdown-preview/editor/main_test.py index 596c66165f9e..cc87343cee4f 100644 --- a/run/markdown-preview/editor/main_test.py +++ b/run/markdown-preview/editor/main_test.py @@ -12,11 +12,13 @@ # See the License for the specific language governing permissions and # limitations under the License. -import main -import os import json +import os + import pytest +import main # noqa I100 for parent lint + @pytest.fixture def client(): diff --git a/run/markdown-preview/noxfile.py b/run/markdown-preview/noxfile.py index 97670a289978..7476509a39cd 100644 --- a/run/markdown-preview/noxfile.py +++ b/run/markdown-preview/noxfile.py @@ -34,10 +34,6 @@ # -# Ignore I202 "Additional newline in a section of imports." to accommodate -# region tags in import blocks. Since we specify an explicit ignore, we also -# have to explicitly ignore the list of default ignores: -# `E121,E123,E126,E226,E24,E704,W503,W504` as shown by `flake8 --help`. def _determine_local_import_names(start_dir): """Determines all import names that should be considered "local". @@ -54,13 +50,23 @@ def _determine_local_import_names(start_dir): ] +# Linting with flake8. +# +# We ignore the following rules: +# E203: whitespace before ‘:’ +# E266: too many leading ‘#’ for block comment +# E501: line too long +# I202: Additional newline in a section of imports +# +# We also need to specify the rules which are ignored by default: +# ['E226', 'W504', 'E126', 'E123', 'W503', 'E24', 'E704', 'E121'] FLAKE8_COMMON_ARGS = [ "--show-source", "--builtin=gettext", "--max-complexity=20", "--import-order-style=google", "--exclude=.nox,.cache,env,lib,generated_pb2,*_pb2.py,*_pb2_grpc.py", - "--ignore=E121,E123,E126,E203,E226,E24,E266,E501,E704,W503,W504,I100,I201,I202", + "--ignore=E121,E123,E126,E203,E226,E24,E266,E501,E704,W503,W504,I202", "--max-line-length=88", ] diff --git a/run/markdown-preview/renderer/main.py b/run/markdown-preview/renderer/main.py index 70d526194a67..8fff3e293672 100644 --- a/run/markdown-preview/renderer/main.py +++ b/run/markdown-preview/renderer/main.py @@ -12,10 +12,11 @@ # See the License for the specific language governing permissions and # limitations under the License. +import os + import bleach from flask import Flask, request import markdown -import os app = Flask(__name__) diff --git a/run/markdown-preview/renderer/main_test.py b/run/markdown-preview/renderer/main_test.py index 43097ca5f2a9..8c702f420d7b 100644 --- a/run/markdown-preview/renderer/main_test.py +++ b/run/markdown-preview/renderer/main_test.py @@ -12,9 +12,10 @@ # See the License for the specific language governing permissions and # limitations under the License. -import main import pytest +import main # noqa I100 for parent lint + @pytest.fixture def client(): diff --git a/run/pubsub/main.py b/run/pubsub/main.py index 5f5b97355a99..0f37200d9bfa 100644 --- a/run/pubsub/main.py +++ b/run/pubsub/main.py @@ -14,10 +14,12 @@ # [START run_pubsub_server_setup] import base64 -from flask import Flask, request import os import sys +from flask import Flask, request + + app = Flask(__name__) # [END run_pubsub_server_setup] diff --git a/run/system-package/main.py b/run/system-package/main.py index 5bc6cc2e4317..e7e26f6925a9 100644 --- a/run/system-package/main.py +++ b/run/system-package/main.py @@ -12,11 +12,12 @@ # See the License for the specific language governing permissions and # limitations under the License. -from flask import Flask, make_response, request import os import subprocess import sys +from flask import Flask, make_response, request + app = Flask(__name__) diff --git a/run/system-package/main_test.py b/run/system-package/main_test.py index f19e54332ce7..90233b831879 100644 --- a/run/system-package/main_test.py +++ b/run/system-package/main_test.py @@ -14,10 +14,9 @@ # NOTE: # To pass these tests locally, run `brew install graphviz` - +import pytest import main -import pytest @pytest.fixture diff --git a/secretmanager/api-client/snippets_test.py b/secretmanager/api-client/snippets_test.py index 08f9244a1000..2c16c139d64f 100644 --- a/secretmanager/api-client/snippets_test.py +++ b/secretmanager/api-client/snippets_test.py @@ -12,10 +12,12 @@ # See the License for the specific language governing permissions and import os -import pytest import uuid -from quickstart import quickstart +from google.api_core import exceptions +from google.cloud import secretmanager +import pytest + from access_secret_version import access_secret_version from add_secret_version import add_secret_version from create_secret import create_secret @@ -29,11 +31,9 @@ from iam_revoke_access import iam_revoke_access from list_secret_versions import list_secret_versions from list_secrets import list_secrets +from quickstart import quickstart from update_secret import update_secret -from google.api_core import exceptions -from google.cloud import secretmanager - @pytest.fixture() def client(): diff --git a/spanner/cloud-client/backup_sample_test.py b/spanner/cloud-client/backup_sample_test.py index 2f0e5128e607..61c69a0be61b 100644 --- a/spanner/cloud-client/backup_sample_test.py +++ b/spanner/cloud-client/backup_sample_test.py @@ -11,11 +11,11 @@ # 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. +import random +import string from google.cloud import spanner import pytest -import random -import string import backup_sample