Skip to content

Commit d6f191b

Browse files
author
Takashi Matsuo
authored
chore: apply noxfile changes for flake8 import order (#3752)
1 parent 3a2654b commit d6f191b

File tree

8 files changed

+79
-43
lines changed

8 files changed

+79
-43
lines changed

appengine/flexible/memcache/noxfile.py

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,6 @@
3434
#
3535

3636

37-
# Ignore I202 "Additional newline in a section of imports." to accommodate
38-
# region tags in import blocks. Since we specify an explicit ignore, we also
39-
# have to explicitly ignore the list of default ignores:
40-
# `E121,E123,E126,E226,E24,E704,W503,W504` as shown by `flake8 --help`.
4137
def _determine_local_import_names(start_dir):
4238
"""Determines all import names that should be considered "local".
4339
@@ -54,13 +50,23 @@ def _determine_local_import_names(start_dir):
5450
]
5551

5652

53+
# Linting with flake8.
54+
#
55+
# We ignore the following rules:
56+
# E203: whitespace before ‘:’
57+
# E266: too many leading ‘#’ for block comment
58+
# E501: line too long
59+
# I202: Additional newline in a section of imports
60+
#
61+
# We also need to specify the rules which are ignored by default:
62+
# ['E226', 'W504', 'E126', 'E123', 'W503', 'E24', 'E704', 'E121']
5763
FLAKE8_COMMON_ARGS = [
5864
"--show-source",
5965
"--builtin=gettext",
6066
"--max-complexity=20",
6167
"--import-order-style=google",
6268
"--exclude=.nox,.cache,env,lib,generated_pb2,*_pb2.py,*_pb2_grpc.py",
63-
"--ignore=E121,E123,E126,E203,E226,E24,E266,E501,E704,W503,W504,I100,I201,I202",
69+
"--ignore=E121,E123,E126,E203,E226,E24,E266,E501,E704,W503,W504,I202",
6470
"--max-line-length=88",
6571
]
6672

@@ -142,11 +148,12 @@ def _get_repo_root():
142148
def readmegen(session, path):
143149
"""(Re-)generates the readme for a sample."""
144150
session.install("jinja2", "pyyaml")
151+
dir_ = os.path.dirname(path)
145152

146-
if os.path.exists(os.path.join(path, "requirements.txt")):
147-
session.install("-r", os.path.join(path, "requirements.txt"))
153+
if os.path.exists(os.path.join(dir_, "requirements.txt")):
154+
session.install("-r", os.path.join(dir_, "requirements.txt"))
148155

149-
in_file = os.path.join(path, "README.rst.in")
156+
in_file = os.path.join(dir_, "README.rst.in")
150157
session.run(
151158
"python", _get_repo_root() + "/scripts/readme-gen/readme_gen.py", in_file
152159
)

dataflow/encryption-keys/noxfile.py

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,6 @@
3434
#
3535

3636

37-
# Ignore I202 "Additional newline in a section of imports." to accommodate
38-
# region tags in import blocks. Since we specify an explicit ignore, we also
39-
# have to explicitly ignore the list of default ignores:
40-
# `E121,E123,E126,E226,E24,E704,W503,W504` as shown by `flake8 --help`.
4137
def _determine_local_import_names(start_dir):
4238
"""Determines all import names that should be considered "local".
4339
@@ -54,13 +50,23 @@ def _determine_local_import_names(start_dir):
5450
]
5551

5652

53+
# Linting with flake8.
54+
#
55+
# We ignore the following rules:
56+
# E203: whitespace before ‘:’
57+
# E266: too many leading ‘#’ for block comment
58+
# E501: line too long
59+
# I202: Additional newline in a section of imports
60+
#
61+
# We also need to specify the rules which are ignored by default:
62+
# ['E226', 'W504', 'E126', 'E123', 'W503', 'E24', 'E704', 'E121']
5763
FLAKE8_COMMON_ARGS = [
5864
"--show-source",
5965
"--builtin=gettext",
6066
"--max-complexity=20",
6167
"--import-order-style=google",
6268
"--exclude=.nox,.cache,env,lib,generated_pb2,*_pb2.py,*_pb2_grpc.py",
63-
"--ignore=E121,E123,E126,E203,E226,E24,E266,E501,E704,W503,W504,I100,I201,I202",
69+
"--ignore=E121,E123,E126,E203,E226,E24,E266,E501,E704,W503,W504,I202",
6470
"--max-line-length=88",
6571
]
6672

@@ -142,11 +148,12 @@ def _get_repo_root():
142148
def readmegen(session, path):
143149
"""(Re-)generates the readme for a sample."""
144150
session.install("jinja2", "pyyaml")
151+
dir_ = os.path.dirname(path)
145152

146-
if os.path.exists(os.path.join(path, "requirements.txt")):
147-
session.install("-r", os.path.join(path, "requirements.txt"))
153+
if os.path.exists(os.path.join(dir_, "requirements.txt")):
154+
session.install("-r", os.path.join(dir_, "requirements.txt"))
148155

149-
in_file = os.path.join(path, "README.rst.in")
156+
in_file = os.path.join(dir_, "README.rst.in")
150157
session.run(
151158
"python", _get_repo_root() + "/scripts/readme-gen/readme_gen.py", in_file
152159
)

dataflow/flex-templates/streaming_beam/noxfile.py

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,6 @@
3434
#
3535

3636

37-
# Ignore I202 "Additional newline in a section of imports." to accommodate
38-
# region tags in import blocks. Since we specify an explicit ignore, we also
39-
# have to explicitly ignore the list of default ignores:
40-
# `E121,E123,E126,E226,E24,E704,W503,W504` as shown by `flake8 --help`.
4137
def _determine_local_import_names(start_dir):
4238
"""Determines all import names that should be considered "local".
4339
@@ -54,13 +50,23 @@ def _determine_local_import_names(start_dir):
5450
]
5551

5652

53+
# Linting with flake8.
54+
#
55+
# We ignore the following rules:
56+
# E203: whitespace before ‘:’
57+
# E266: too many leading ‘#’ for block comment
58+
# E501: line too long
59+
# I202: Additional newline in a section of imports
60+
#
61+
# We also need to specify the rules which are ignored by default:
62+
# ['E226', 'W504', 'E126', 'E123', 'W503', 'E24', 'E704', 'E121']
5763
FLAKE8_COMMON_ARGS = [
5864
"--show-source",
5965
"--builtin=gettext",
6066
"--max-complexity=20",
6167
"--import-order-style=google",
6268
"--exclude=.nox,.cache,env,lib,generated_pb2,*_pb2.py,*_pb2_grpc.py",
63-
"--ignore=E121,E123,E126,E203,E226,E24,E266,E501,E704,W503,W504,I100,I201,I202",
69+
"--ignore=E121,E123,E126,E203,E226,E24,E266,E501,E704,W503,W504,I202",
6470
"--max-line-length=88",
6571
]
6672

@@ -142,11 +148,12 @@ def _get_repo_root():
142148
def readmegen(session, path):
143149
"""(Re-)generates the readme for a sample."""
144150
session.install("jinja2", "pyyaml")
151+
dir_ = os.path.dirname(path)
145152

146-
if os.path.exists(os.path.join(path, "requirements.txt")):
147-
session.install("-r", os.path.join(path, "requirements.txt"))
153+
if os.path.exists(os.path.join(dir_, "requirements.txt")):
154+
session.install("-r", os.path.join(dir_, "requirements.txt"))
148155

149-
in_file = os.path.join(path, "README.rst.in")
156+
in_file = os.path.join(dir_, "README.rst.in")
150157
session.run(
151158
"python", _get_repo_root() + "/scripts/readme-gen/readme_gen.py", in_file
152159
)

dataflow/flex-templates/streaming_beam/streaming_beam_test.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,15 @@
1212

1313
import multiprocessing as mp
1414
import os
15-
import pytest
1615
import subprocess as sp
1716
import tempfile
1817
import time
1918
import uuid
2019

2120
from google.cloud import bigquery
2221
from google.cloud import pubsub
22+
import pytest
23+
2324

2425
PROJECT = os.environ["GCLOUD_PROJECT"]
2526
UUID = str(uuid.uuid4()).split('-')[0]

ml_engine/online_prediction/noxfile.py

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,6 @@
3434
#
3535

3636

37-
# Ignore I202 "Additional newline in a section of imports." to accommodate
38-
# region tags in import blocks. Since we specify an explicit ignore, we also
39-
# have to explicitly ignore the list of default ignores:
40-
# `E121,E123,E126,E226,E24,E704,W503,W504` as shown by `flake8 --help`.
4137
def _determine_local_import_names(start_dir):
4238
"""Determines all import names that should be considered "local".
4339
@@ -54,13 +50,23 @@ def _determine_local_import_names(start_dir):
5450
]
5551

5652

53+
# Linting with flake8.
54+
#
55+
# We ignore the following rules:
56+
# E203: whitespace before ‘:’
57+
# E266: too many leading ‘#’ for block comment
58+
# E501: line too long
59+
# I202: Additional newline in a section of imports
60+
#
61+
# We also need to specify the rules which are ignored by default:
62+
# ['E226', 'W504', 'E126', 'E123', 'W503', 'E24', 'E704', 'E121']
5763
FLAKE8_COMMON_ARGS = [
5864
"--show-source",
5965
"--builtin=gettext",
6066
"--max-complexity=20",
6167
"--import-order-style=google",
6268
"--exclude=.nox,.cache,env,lib,generated_pb2,*_pb2.py,*_pb2_grpc.py",
63-
"--ignore=E121,E123,E126,E203,E226,E24,E266,E501,E704,W503,W504,I100,I201,I202",
69+
"--ignore=E121,E123,E126,E203,E226,E24,E266,E501,E704,W503,W504,I202",
6470
"--max-line-length=88",
6571
]
6672

@@ -142,11 +148,12 @@ def _get_repo_root():
142148
def readmegen(session, path):
143149
"""(Re-)generates the readme for a sample."""
144150
session.install("jinja2", "pyyaml")
151+
dir_ = os.path.dirname(path)
145152

146-
if os.path.exists(os.path.join(path, "requirements.txt")):
147-
session.install("-r", os.path.join(path, "requirements.txt"))
153+
if os.path.exists(os.path.join(dir_, "requirements.txt")):
154+
session.install("-r", os.path.join(dir_, "requirements.txt"))
148155

149-
in_file = os.path.join(path, "README.rst.in")
156+
in_file = os.path.join(dir_, "README.rst.in")
150157
session.run(
151158
"python", _get_repo_root() + "/scripts/readme-gen/readme_gen.py", in_file
152159
)

pubsub/streaming-analytics/PubSubToGCS.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919
import logging
2020

2121
import apache_beam as beam
22-
import apache_beam.transforms.window as window
2322
from apache_beam.options.pipeline_options import PipelineOptions
23+
import apache_beam.transforms.window as window
2424

2525

2626
class GroupWindowsIntoBatches(beam.PTransform):

pubsub/streaming-analytics/PubSubToGCS_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
import mock
1615
import os
1716
import uuid
1817

@@ -21,6 +20,7 @@
2120
from apache_beam.testing.test_stream import TestStream
2221
from apache_beam.testing.test_utils import TempDir
2322
from apache_beam.transforms.window import TimestampedValue
23+
import mock
2424

2525
import PubSubToGCS
2626

pubsub/streaming-analytics/noxfile.py

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,6 @@
3434
#
3535

3636

37-
# Ignore I202 "Additional newline in a section of imports." to accommodate
38-
# region tags in import blocks. Since we specify an explicit ignore, we also
39-
# have to explicitly ignore the list of default ignores:
40-
# `E121,E123,E126,E226,E24,E704,W503,W504` as shown by `flake8 --help`.
4137
def _determine_local_import_names(start_dir):
4238
"""Determines all import names that should be considered "local".
4339
@@ -54,13 +50,23 @@ def _determine_local_import_names(start_dir):
5450
]
5551

5652

53+
# Linting with flake8.
54+
#
55+
# We ignore the following rules:
56+
# E203: whitespace before ‘:’
57+
# E266: too many leading ‘#’ for block comment
58+
# E501: line too long
59+
# I202: Additional newline in a section of imports
60+
#
61+
# We also need to specify the rules which are ignored by default:
62+
# ['E226', 'W504', 'E126', 'E123', 'W503', 'E24', 'E704', 'E121']
5763
FLAKE8_COMMON_ARGS = [
5864
"--show-source",
5965
"--builtin=gettext",
6066
"--max-complexity=20",
6167
"--import-order-style=google",
6268
"--exclude=.nox,.cache,env,lib,generated_pb2,*_pb2.py,*_pb2_grpc.py",
63-
"--ignore=E121,E123,E126,E203,E226,E24,E266,E501,E704,W503,W504,I100,I201,I202",
69+
"--ignore=E121,E123,E126,E203,E226,E24,E266,E501,E704,W503,W504,I202",
6470
"--max-line-length=88",
6571
]
6672

@@ -142,11 +148,12 @@ def _get_repo_root():
142148
def readmegen(session, path):
143149
"""(Re-)generates the readme for a sample."""
144150
session.install("jinja2", "pyyaml")
151+
dir_ = os.path.dirname(path)
145152

146-
if os.path.exists(os.path.join(path, "requirements.txt")):
147-
session.install("-r", os.path.join(path, "requirements.txt"))
153+
if os.path.exists(os.path.join(dir_, "requirements.txt")):
154+
session.install("-r", os.path.join(dir_, "requirements.txt"))
148155

149-
in_file = os.path.join(path, "README.rst.in")
156+
in_file = os.path.join(dir_, "README.rst.in")
150157
session.run(
151158
"python", _get_repo_root() + "/scripts/readme-gen/readme_gen.py", in_file
152159
)

0 commit comments

Comments
 (0)