Skip to content

Commit acbd79d

Browse files
authored
chore(python): fix formatting in noxfile and docs/conf.py (#1661)
1 parent eff9421 commit acbd79d

File tree

2 files changed

+78
-14
lines changed

2 files changed

+78
-14
lines changed

synthtool/gcp/templates/python_library/docs/conf.py.j2

+1-1
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,7 @@ intersphinx_mapping = {
368368
"grpc": ("https://grpc.github.io/grpc/python/", None),
369369
"proto-plus": ("https://proto-plus-python.readthedocs.io/en/latest/", None),
370370
"protobuf": ("https://googleapis.dev/python/protobuf/latest/", None),
371-
{% if intersphinx_dependencies %}
371+
{%- if intersphinx_dependencies %}
372372
{% for name, url in intersphinx_dependencies.items() %}
373373
"{{ name }}": ("{{ url }}", None),
374374
{% endfor %}

synthtool/gcp/templates/python_library/noxfile.py.j2

+77-13
Original file line numberDiff line numberDiff line change
@@ -29,55 +29,101 @@ BLACK_VERSION = "black==22.3.0"
2929
ISORT_VERSION = "isort==5.10.1"
3030
LINT_PATHS = ["docs", "google", "tests", "noxfile.py", "setup.py"]
3131

32-
DEFAULT_PYTHON_VERSION="{{ default_python_version }}"
32+
DEFAULT_PYTHON_VERSION = "{{ default_python_version }}"
3333

34-
UNIT_TEST_PYTHON_VERSIONS=[{% for v in unit_test_python_versions %}"{{v}}"{% if not loop.last %}, {% endif %}{% endfor %}]
34+
UNIT_TEST_PYTHON_VERSIONS = [{% for v in unit_test_python_versions %}"{{v}}"{% if not loop.last %}, {% endif %}{% endfor %}]
3535
UNIT_TEST_STANDARD_DEPENDENCIES = [
3636
"mock",
3737
"asyncmock",
3838
"pytest",
3939
"pytest-cov",
4040
"pytest-asyncio",
4141
]
42+
{%- if unit_test_external_dependencies %}
4243
UNIT_TEST_EXTERNAL_DEPENDENCIES = [{% for v in unit_test_external_dependencies %}
4344
"{{v}}",{% endfor %}
4445
]
46+
{%- else %}
47+
UNIT_TEST_EXTERNAL_DEPENDENCIES = []
48+
{%- endif %}
49+
{%- if unit_test_local_dependencies %}
4550
UNIT_TEST_LOCAL_DEPENDENCIES = [{% for v in unit_test_local_dependencies %}
4651
"{{v}}",{% endfor %}
4752
]
53+
{%- else %}
54+
UNIT_TEST_LOCAL_DEPENDENCIES = []
55+
{%- endif %}
56+
{%- if unit_test_dependencies %}
4857
UNIT_TEST_DEPENDENCIES = [{% for v in unit_test_dependencies %}
4958
"{{v}}",{% endfor %}
5059
]
60+
{%- else %}
61+
UNIT_TEST_DEPENDENCIES = []
62+
{%- endif %}
63+
{%- if unit_test_extras %}
5164
UNIT_TEST_EXTRAS = [{% for v in unit_test_extras %}
5265
"{{v}}",{% endfor %}
5366
]
67+
{%- else %}
68+
UNIT_TEST_EXTRAS = []
69+
{%- endif %}
70+
71+
{%- if unit_test_extras_by_python %}
5472
UNIT_TEST_EXTRAS_BY_PYTHON = {{ '{' }}{% if unit_test_extras_by_python %}{% for python_version, extras in unit_test_extras_by_python.items() %}
5573
"{{python_version}}": [{% for v in extras %}
5674
"{{v}}",{% endfor %}
5775
],{% endfor %}{% endif %}
5876
}
59-
60-
SYSTEM_TEST_PYTHON_VERSIONS=[{% for v in system_test_python_versions %}"{{v}}"{% if not loop.last %}, {% endif %}{% endfor %}]
77+
{%- else %}
78+
UNIT_TEST_EXTRAS_BY_PYTHON = {}
79+
{%- endif %}
80+
{% if system_test_python_versions %}
81+
SYSTEM_TEST_PYTHON_VERSIONS = [{% for v in system_test_python_versions %}"{{v}}"{% if not loop.last %}, {% endif %}{% endfor %}]
82+
{%- else %}
83+
SYSTEM_TEST_PYTHON_VERSIONS = []
84+
{%- endif %}
6185
SYSTEM_TEST_STANDARD_DEPENDENCIES = [
62-
"mock", "pytest", "google-cloud-testutils",
86+
"mock",
87+
"pytest",
88+
"google-cloud-testutils",
6389
]
90+
{%- if system_test_external_dependencies %}
6491
SYSTEM_TEST_EXTERNAL_DEPENDENCIES = [{% for v in system_test_external_dependencies %}
6592
"{{v}}",{% endfor %}
6693
]
94+
{%- else %}
95+
SYSTEM_TEST_EXTERNAL_DEPENDENCIES = []
96+
{%- endif %}
97+
{%- if system_test_local_dependencies %}
6798
SYSTEM_TEST_LOCAL_DEPENDENCIES = [{% for v in system_test_local_dependencies %}
6899
"{{v}}",{% endfor %}
69100
]
101+
{%- else %}
102+
SYSTEM_TEST_LOCAL_DEPENDENCIES = []
103+
{%- endif %}
104+
{%- if system_test_dependencies %}
70105
SYSTEM_TEST_DEPENDENCIES = [{% for v in system_test_dependencies %}
71106
"{{v}}",{% endfor %}
72107
]
108+
{%- else %}
109+
SYSTEM_TEST_DEPENDENCIES = []
110+
{%- endif %}
111+
{%- if system_test_extras %}
73112
SYSTEM_TEST_EXTRAS = [{% for v in system_test_extras %}
74113
"{{v}}",{% endfor %}
75114
]
115+
{%- else %}
116+
SYSTEM_TEST_EXTRAS = []
117+
{%- endif %}
118+
{%- if system_test_extras_by_python %}
76119
SYSTEM_TEST_EXTRAS_BY_PYTHON = {{ '{' }}{% if system_test_extras_by_python %}{% for python_version, extras in system_test_extras_by_python.items() %}
77120
"{{python_version}}": [{% for v in extras %}
78121
"{{v}}",{% endfor %}
79122
],{% endfor %}{% endif %}
80123
}
124+
{%- else %}
125+
SYSTEM_TEST_EXTRAS_BY_PYTHON = {}
126+
{%- endif %}
81127

82128
CURRENT_DIRECTORY = pathlib.Path(__file__).parent.absolute()
83129

@@ -200,6 +246,7 @@ def default(session):
200246
*session.posargs,
201247
)
202248

249+
203250
@nox.session(python=UNIT_TEST_PYTHON_VERSIONS)
204251
def unit(session):
205252
"""Run the unit test suite."""
@@ -247,7 +294,7 @@ def system(session):
247294
system_test_folder_path = os.path.join("tests", "system")
248295

249296
# Check the value of `RUN_SYSTEM_TESTS` env var. It defaults to true.
250-
if os.environ.get("RUN_SYSTEM_TESTS", "true") == 'false':
297+
if os.environ.get("RUN_SYSTEM_TESTS", "true") == "false":
251298
session.skip("RUN_SYSTEM_TESTS is set to false, skipping")
252299
# Install pyopenssl for mTLS testing.
253300
if os.environ.get("GOOGLE_API_USE_CLIENT_CERTIFICATE", "false") == "true":
@@ -268,17 +315,18 @@ def system(session):
268315
"--quiet",
269316
f"--junitxml=system_{session.python}_sponge_log.xml",
270317
system_test_path,
271-
*session.posargs
318+
*session.posargs,
272319
)
273320
if system_test_folder_exists:
274321
session.run(
275322
"py.test",
276323
"--quiet",
277324
f"--junitxml=system_{session.python}_sponge_log.xml",
278325
system_test_folder_path,
279-
*session.posargs
326+
*session.posargs,
280327
)
281328

329+
282330
@nox.session(python=DEFAULT_PYTHON_VERSION)
283331
def cover(session):
284332
"""Run the final coverage report.
@@ -291,21 +339,28 @@ def cover(session):
291339

292340
session.run("coverage", "erase")
293341

342+
294343
@nox.session(python=DEFAULT_PYTHON_VERSION)
295344
def docs(session):
296345
"""Build the docs for this library."""
297346

298347
session.install("-e", ".")
299-
session.install("sphinx==4.0.1", "alabaster", "recommonmark")
348+
session.install(
349+
"sphinx==4.0.1",
350+
"alabaster",
351+
"recommonmark",
352+
)
300353

301354
shutil.rmtree(os.path.join("docs", "_build"), ignore_errors=True)
302355
session.run(
303356
"sphinx-build",
304357
"-W", # warnings as errors
305358
"-T", # show full traceback on exception
306359
"-N", # no colors
307-
"-b", "html",
308-
"-d", os.path.join("docs", "_build", "doctrees", ""),
360+
"-b",
361+
"html",
362+
"-d",
363+
os.path.join("docs", "_build", "doctrees", ""),
309364
os.path.join("docs", ""),
310365
os.path.join("docs", "_build", "html", ""),
311366
)
@@ -316,7 +371,12 @@ def docfx(session):
316371
"""Build the docfx yaml files for this library."""
317372

318373
session.install("-e", ".")
319-
session.install("sphinx==4.0.1", "alabaster", "recommonmark", "gcp-sphinx-docfx-yaml")
374+
session.install(
375+
"sphinx==4.0.1",
376+
"alabaster",
377+
"recommonmark",
378+
"gcp-sphinx-docfx-yaml",
379+
)
320380

321381
shutil.rmtree(os.path.join("docs", "_build"), ignore_errors=True)
322382
session.run(
@@ -352,7 +412,11 @@ def prerelease_deps(session):
352412
session.install("-e", ".[all, tests, tracing]")
353413
unit_deps_all = UNIT_TEST_STANDARD_DEPENDENCIES + UNIT_TEST_EXTERNAL_DEPENDENCIES
354414
session.install(*unit_deps_all)
355-
system_deps_all = SYSTEM_TEST_STANDARD_DEPENDENCIES + SYSTEM_TEST_EXTERNAL_DEPENDENCIES + SYSTEM_TEST_EXTRAS
415+
system_deps_all = (
416+
SYSTEM_TEST_STANDARD_DEPENDENCIES
417+
+ SYSTEM_TEST_EXTERNAL_DEPENDENCIES
418+
+ SYSTEM_TEST_EXTRAS
419+
)
356420
session.install(*system_deps_all)
357421

358422
# Because we test minimum dependency versions on the minimum Python

0 commit comments

Comments
 (0)