Skip to content

Commit 7d20fbb

Browse files
authored
chore: remove code formatting for noxfile.py (#2491)
1 parent f93a0eb commit 7d20fbb

File tree

8 files changed

+297
-312
lines changed

8 files changed

+297
-312
lines changed

gapic/templates/noxfile.py.j2

Lines changed: 38 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,21 @@ BLACK_VERSION = "black[jupyter]==23.7.0"
1616
ISORT_VERSION = "isort==5.11.0"
1717

1818
{% if api.naming.module_namespace %}
19+
FORMAT_PATHS = ["docs", "{{ api.naming.module_namespace[0] }}", "tests", "setup.py"]
1920
LINT_PATHS = ["docs", "{{ api.naming.module_namespace[0] }}", "tests", "noxfile.py", "setup.py"]
2021
{% else %}
22+
FORMAT_PATHS = ["docs", "{{ api.naming.versioned_module_name }}", "tests", "setup.py"]
2123
LINT_PATHS = ["docs", "{{ api.naming.versioned_module_name }}", "tests", "noxfile.py", "setup.py"]
2224
{% endif %}
2325

26+
# We're most interested in ensuring that code is formatted properly
27+
# and less concerned about the line length.
28+
LINT_LINE_LENGTH = 150
29+
2430
# Add samples to the list of directories to format if the directory exists.
2531
if os.path.isdir("samples"):
2632
LINT_PATHS.append("samples")
33+
FORMAT_PATHS.append("samples")
2734

2835
ALL_PYTHON = [
2936
"3.7",
@@ -152,6 +159,7 @@ def lint(session):
152159
"black",
153160
"--check",
154161
*LINT_PATHS,
162+
f"--line-length={LINT_LINE_LENGTH}",
155163
)
156164
157165
{% if api.naming.module_namespace %}
@@ -167,7 +175,8 @@ def blacken(session):
167175
session.install(BLACK_VERSION)
168176
session.run(
169177
"black",
170-
*LINT_PATHS,
178+
*FORMAT_PATHS,
179+
f"--line-length={LINT_LINE_LENGTH}",
171180
)
172181

173182

@@ -183,11 +192,12 @@ def format(session):
183192
session.run(
184193
"isort",
185194
"--fss",
186-
*LINT_PATHS,
195+
*FORMAT_PATHS,
187196
)
188197
session.run(
189198
"black",
190-
*LINT_PATHS,
199+
*FORMAT_PATHS,
200+
f"--line-length={LINT_LINE_LENGTH}",
191201
)
192202

193203

@@ -204,8 +214,7 @@ def install_unittest_dependencies(session, *constraints):
204214

205215
if UNIT_TEST_EXTERNAL_DEPENDENCIES:
206216
warnings.warn(
207-
"'unit_test_external_dependencies' is deprecated. Instead, please "
208-
"use 'unit_test_dependencies' or 'unit_test_local_dependencies'.",
217+
"'unit_test_external_dependencies' is deprecated. Instead, please use 'unit_test_dependencies' or 'unit_test_local_dependencies'.",
209218
DeprecationWarning,
210219
)
211220
session.install(*UNIT_TEST_EXTERNAL_DEPENDENCIES, *constraints)
@@ -236,12 +245,15 @@ def unit(session, protobuf_implementation):
236245

237246
# TODO(https://github.com/googleapis/gapic-generator-python/issues/2388):
238247
# Remove this check once support for Protobuf 3.x is dropped.
239-
if protobuf_implementation == "cpp" and session.python in ("3.11", "3.12", "3.13", "3.14"):
248+
if protobuf_implementation == "cpp" and session.python in (
249+
"3.11",
250+
"3.12",
251+
"3.13",
252+
"3.14",
253+
):
240254
session.skip("cpp implementation is not supported in python 3.11+")
241255

242-
constraints_path = str(
243-
CURRENT_DIRECTORY / "testing" / f"constraints-{session.python}.txt"
244-
)
256+
constraints_path = str(CURRENT_DIRECTORY / "testing" / f"constraints-{session.python}.txt")
245257
install_unittest_dependencies(session, "-c", constraints_path)
246258

247259
# TODO(https://github.com/googleapis/gapic-generator-python/issues/2388):
@@ -304,9 +316,7 @@ def install_systemtest_dependencies(session, *constraints):
304316
@nox.session(python=SYSTEM_TEST_PYTHON_VERSIONS)
305317
def system(session):
306318
"""Run the system test suite."""
307-
constraints_path = str(
308-
CURRENT_DIRECTORY / "testing" / f"constraints-{session.python}.txt"
309-
)
319+
constraints_path = str(CURRENT_DIRECTORY / "testing" / f"constraints-{session.python}.txt")
310320
system_test_path = os.path.join("tests", "system.py")
311321
system_test_folder_path = os.path.join("tests", "system")
312322

@@ -383,8 +393,10 @@ def docs(session):
383393
"-W", # warnings as errors
384394
"-T", # show full traceback on exception
385395
"-N", # no colors
386-
"-b", "html", # builder
387-
"-d", os.path.join("docs", "_build", "doctrees", ""), # cache directory
396+
"-b", # builder
397+
"html",
398+
"-d", # cache directory
399+
os.path.join("docs", "_build", "doctrees", ""),
388400
# paths to build:
389401
os.path.join("docs", ""),
390402
os.path.join("docs", "_build", "html", ""),
@@ -452,7 +464,12 @@ def prerelease_deps(session, protobuf_implementation):
452464

453465
# TODO(https://github.com/googleapis/gapic-generator-python/issues/2388):
454466
# Remove this check once support for Protobuf 3.x is dropped.
455-
if protobuf_implementation == "cpp" and session.python in ("3.11", "3.12", "3.13", "3.14"):
467+
if protobuf_implementation == "cpp" and session.python in (
468+
"3.11",
469+
"3.12",
470+
"3.13",
471+
"3.14",
472+
):
456473
session.skip("cpp implementation is not supported in python 3.11+")
457474

458475
# Install all dependencies
@@ -463,11 +480,7 @@ def prerelease_deps(session, protobuf_implementation):
463480
session.install(*unit_deps_all)
464481

465482
# Install dependencies for the system test environment
466-
system_deps_all = (
467-
SYSTEM_TEST_STANDARD_DEPENDENCIES
468-
+ SYSTEM_TEST_EXTERNAL_DEPENDENCIES
469-
+ SYSTEM_TEST_EXTRAS
470-
)
483+
system_deps_all = SYSTEM_TEST_STANDARD_DEPENDENCIES + SYSTEM_TEST_EXTERNAL_DEPENDENCIES + SYSTEM_TEST_EXTRAS
471484
session.install(*system_deps_all)
472485

473486
# Because we test minimum dependency versions on the minimum Python
@@ -479,13 +492,8 @@ def prerelease_deps(session, protobuf_implementation):
479492
) as constraints_file:
480493
constraints_text = constraints_file.read()
481494

482-
# Ignore leading whitespace and comment lines.
483-
constraints_deps = [
484-
match.group(1)
485-
for match in re.finditer(
486-
r"^\s*(\S+)(?===\S+)", constraints_text, flags=re.MULTILINE
487-
)
488-
]
495+
# Ignore leading spaces and comment lines.
496+
constraints_deps = [match.group(1) for match in re.finditer(r"^\s*(\S+)(?===\S+)", constraints_text, flags=re.MULTILINE)]
489497

490498
# Install dependencies specified in `testing/constraints-X.txt`.
491499
session.install(*constraints_deps)
@@ -556,11 +564,7 @@ def core_deps_from_source(session, protobuf_implementation):
556564
session.install(*unit_deps_all)
557565

558566
# Install dependencies for the system test environment
559-
system_deps_all = (
560-
SYSTEM_TEST_STANDARD_DEPENDENCIES
561-
+ SYSTEM_TEST_EXTERNAL_DEPENDENCIES
562-
+ SYSTEM_TEST_EXTRAS
563-
)
567+
system_deps_all = SYSTEM_TEST_STANDARD_DEPENDENCIES + SYSTEM_TEST_EXTERNAL_DEPENDENCIES + SYSTEM_TEST_EXTRAS
564568
session.install(*system_deps_all)
565569

566570
# Because we test minimum dependency versions on the minimum Python
@@ -572,13 +576,8 @@ def core_deps_from_source(session, protobuf_implementation):
572576
) as constraints_file:
573577
constraints_text = constraints_file.read()
574578

575-
# Ignore leading whitespace and comment lines.
576-
constraints_deps = [
577-
match.group(1)
578-
for match in re.finditer(
579-
r"^\s*(\S+)(?===\S+)", constraints_text, flags=re.MULTILINE
580-
)
581-
]
579+
# Ignore leading spaces and comment lines.
580+
constraints_deps = [match.group(1) for match in re.finditer(r"^\s*(\S+)(?===\S+)", constraints_text, flags=re.MULTILINE)]
582581

583582
# Install dependencies specified in `testing/constraints-X.txt`.
584583
session.install(*constraints_deps)

tests/integration/goldens/asset/noxfile.py

Lines changed: 37 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,17 @@
2626
BLACK_VERSION = "black[jupyter]==23.7.0"
2727
ISORT_VERSION = "isort==5.11.0"
2828

29+
FORMAT_PATHS = ["docs", "google", "tests", "setup.py"]
2930
LINT_PATHS = ["docs", "google", "tests", "noxfile.py", "setup.py"]
3031

32+
# We're most interested in ensuring that code is formatted properly
33+
# and less concerned about the line length.
34+
LINT_LINE_LENGTH = 150
35+
3136
# Add samples to the list of directories to format if the directory exists.
3237
if os.path.isdir("samples"):
3338
LINT_PATHS.append("samples")
39+
FORMAT_PATHS.append("samples")
3440

3541
ALL_PYTHON = [
3642
"3.7",
@@ -155,6 +161,7 @@ def lint(session):
155161
"black",
156162
"--check",
157163
*LINT_PATHS,
164+
f"--line-length={LINT_LINE_LENGTH}",
158165
)
159166

160167
session.run("flake8", "google", "tests")
@@ -166,7 +173,8 @@ def blacken(session):
166173
session.install(BLACK_VERSION)
167174
session.run(
168175
"black",
169-
*LINT_PATHS,
176+
*FORMAT_PATHS,
177+
f"--line-length={LINT_LINE_LENGTH}",
170178
)
171179

172180

@@ -182,11 +190,12 @@ def format(session):
182190
session.run(
183191
"isort",
184192
"--fss",
185-
*LINT_PATHS,
193+
*FORMAT_PATHS,
186194
)
187195
session.run(
188196
"black",
189-
*LINT_PATHS,
197+
*FORMAT_PATHS,
198+
f"--line-length={LINT_LINE_LENGTH}",
190199
)
191200

192201

@@ -203,8 +212,7 @@ def install_unittest_dependencies(session, *constraints):
203212

204213
if UNIT_TEST_EXTERNAL_DEPENDENCIES:
205214
warnings.warn(
206-
"'unit_test_external_dependencies' is deprecated. Instead, please "
207-
"use 'unit_test_dependencies' or 'unit_test_local_dependencies'.",
215+
"'unit_test_external_dependencies' is deprecated. Instead, please use 'unit_test_dependencies' or 'unit_test_local_dependencies'.",
208216
DeprecationWarning,
209217
)
210218
session.install(*UNIT_TEST_EXTERNAL_DEPENDENCIES, *constraints)
@@ -235,12 +243,15 @@ def unit(session, protobuf_implementation):
235243

236244
# TODO(https://github.com/googleapis/gapic-generator-python/issues/2388):
237245
# Remove this check once support for Protobuf 3.x is dropped.
238-
if protobuf_implementation == "cpp" and session.python in ("3.11", "3.12", "3.13", "3.14"):
246+
if protobuf_implementation == "cpp" and session.python in (
247+
"3.11",
248+
"3.12",
249+
"3.13",
250+
"3.14",
251+
):
239252
session.skip("cpp implementation is not supported in python 3.11+")
240253

241-
constraints_path = str(
242-
CURRENT_DIRECTORY / "testing" / f"constraints-{session.python}.txt"
243-
)
254+
constraints_path = str(CURRENT_DIRECTORY / "testing" / f"constraints-{session.python}.txt")
244255
install_unittest_dependencies(session, "-c", constraints_path)
245256

246257
# TODO(https://github.com/googleapis/gapic-generator-python/issues/2388):
@@ -298,9 +309,7 @@ def install_systemtest_dependencies(session, *constraints):
298309
@nox.session(python=SYSTEM_TEST_PYTHON_VERSIONS)
299310
def system(session):
300311
"""Run the system test suite."""
301-
constraints_path = str(
302-
CURRENT_DIRECTORY / "testing" / f"constraints-{session.python}.txt"
303-
)
312+
constraints_path = str(CURRENT_DIRECTORY / "testing" / f"constraints-{session.python}.txt")
304313
system_test_path = os.path.join("tests", "system.py")
305314
system_test_folder_path = os.path.join("tests", "system")
306315

@@ -377,8 +386,10 @@ def docs(session):
377386
"-W", # warnings as errors
378387
"-T", # show full traceback on exception
379388
"-N", # no colors
380-
"-b", "html", # builder
381-
"-d", os.path.join("docs", "_build", "doctrees", ""), # cache directory
389+
"-b", # builder
390+
"html",
391+
"-d", # cache directory
392+
os.path.join("docs", "_build", "doctrees", ""),
382393
# paths to build:
383394
os.path.join("docs", ""),
384395
os.path.join("docs", "_build", "html", ""),
@@ -446,7 +457,12 @@ def prerelease_deps(session, protobuf_implementation):
446457

447458
# TODO(https://github.com/googleapis/gapic-generator-python/issues/2388):
448459
# Remove this check once support for Protobuf 3.x is dropped.
449-
if protobuf_implementation == "cpp" and session.python in ("3.11", "3.12", "3.13", "3.14"):
460+
if protobuf_implementation == "cpp" and session.python in (
461+
"3.11",
462+
"3.12",
463+
"3.13",
464+
"3.14",
465+
):
450466
session.skip("cpp implementation is not supported in python 3.11+")
451467

452468
# Install all dependencies
@@ -457,11 +473,7 @@ def prerelease_deps(session, protobuf_implementation):
457473
session.install(*unit_deps_all)
458474

459475
# Install dependencies for the system test environment
460-
system_deps_all = (
461-
SYSTEM_TEST_STANDARD_DEPENDENCIES
462-
+ SYSTEM_TEST_EXTERNAL_DEPENDENCIES
463-
+ SYSTEM_TEST_EXTRAS
464-
)
476+
system_deps_all = SYSTEM_TEST_STANDARD_DEPENDENCIES + SYSTEM_TEST_EXTERNAL_DEPENDENCIES + SYSTEM_TEST_EXTRAS
465477
session.install(*system_deps_all)
466478

467479
# Because we test minimum dependency versions on the minimum Python
@@ -473,13 +485,8 @@ def prerelease_deps(session, protobuf_implementation):
473485
) as constraints_file:
474486
constraints_text = constraints_file.read()
475487

476-
# Ignore leading whitespace and comment lines.
477-
constraints_deps = [
478-
match.group(1)
479-
for match in re.finditer(
480-
r"^\s*(\S+)(?===\S+)", constraints_text, flags=re.MULTILINE
481-
)
482-
]
488+
# Ignore leading spaces and comment lines.
489+
constraints_deps = [match.group(1) for match in re.finditer(r"^\s*(\S+)(?===\S+)", constraints_text, flags=re.MULTILINE)]
483490

484491
# Install dependencies specified in `testing/constraints-X.txt`.
485492
session.install(*constraints_deps)
@@ -550,11 +557,7 @@ def core_deps_from_source(session, protobuf_implementation):
550557
session.install(*unit_deps_all)
551558

552559
# Install dependencies for the system test environment
553-
system_deps_all = (
554-
SYSTEM_TEST_STANDARD_DEPENDENCIES
555-
+ SYSTEM_TEST_EXTERNAL_DEPENDENCIES
556-
+ SYSTEM_TEST_EXTRAS
557-
)
560+
system_deps_all = SYSTEM_TEST_STANDARD_DEPENDENCIES + SYSTEM_TEST_EXTERNAL_DEPENDENCIES + SYSTEM_TEST_EXTRAS
558561
session.install(*system_deps_all)
559562

560563
# Because we test minimum dependency versions on the minimum Python
@@ -566,13 +569,8 @@ def core_deps_from_source(session, protobuf_implementation):
566569
) as constraints_file:
567570
constraints_text = constraints_file.read()
568571

569-
# Ignore leading whitespace and comment lines.
570-
constraints_deps = [
571-
match.group(1)
572-
for match in re.finditer(
573-
r"^\s*(\S+)(?===\S+)", constraints_text, flags=re.MULTILINE
574-
)
575-
]
572+
# Ignore leading spaces and comment lines.
573+
constraints_deps = [match.group(1) for match in re.finditer(r"^\s*(\S+)(?===\S+)", constraints_text, flags=re.MULTILINE)]
576574

577575
# Install dependencies specified in `testing/constraints-X.txt`.
578576
session.install(*constraints_deps)

0 commit comments

Comments
 (0)