Skip to content

Commit d842233

Browse files
parthealarkeegcf-owl-bot[bot]
authored
chore: use templated noxfile.py (#366)
* chore: use templated noxfile.py * Update noxfile.py * 🦉 Updates from OwlBot See https://github.com/googleapis/repo-automation-bots/blob/master/packages/owl-bot/README.md * coverage * coverage * 🦉 Updates from OwlBot See https://github.com/googleapis/repo-automation-bots/blob/master/packages/owl-bot/README.md * Replace fixup with customize Co-authored-by: larkee <[email protected]> Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
1 parent 7f1b120 commit d842233

File tree

2 files changed

+106
-14
lines changed

2 files changed

+106
-14
lines changed

noxfile.py

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -64,14 +64,7 @@ def lint(session):
6464

6565
@nox.session(python=DEFAULT_PYTHON_VERSION)
6666
def blacken(session):
67-
"""Run black.
68-
69-
Format code to uniform standard.
70-
71-
This currently uses Python 3.6 due to the automated Kokoro run of synthtool.
72-
That run uses an image that doesn't have 3.6 installed. Before updating this
73-
check the state of the `gcp_ubuntu_config` we use for that Kokoro run.
74-
"""
67+
"""Run black. Format code to uniform standard."""
7568
session.install(BLACK_VERSION)
7669
session.run(
7770
"black", *BLACK_PATHS,
@@ -156,6 +149,10 @@ def system(session):
156149
"Credentials or emulator host must be set via environment variable"
157150
)
158151

152+
# Install pyopenssl for mTLS testing.
153+
if os.environ.get("GOOGLE_API_USE_CLIENT_CERTIFICATE", "false") == "true":
154+
session.install("pyopenssl")
155+
159156
system_test_exists = os.path.exists(system_test_path)
160157
system_test_folder_exists = os.path.exists(system_test_folder_path)
161158
# Sanity check: only run tests if found.
@@ -172,9 +169,21 @@ def system(session):
172169

173170
# Run py.test against the system tests.
174171
if system_test_exists:
175-
session.run("py.test", "--quiet", system_test_path, *session.posargs)
172+
session.run(
173+
"py.test",
174+
"--quiet",
175+
f"--junitxml=system_{session.python}_sponge_log.xml",
176+
system_test_path,
177+
*session.posargs,
178+
)
176179
if system_test_folder_exists:
177-
session.run("py.test", "--quiet", system_test_folder_path, *session.posargs)
180+
session.run(
181+
"py.test",
182+
"--quiet",
183+
f"--junitxml=system_{session.python}_sponge_log.xml",
184+
system_test_folder_path,
185+
*session.posargs,
186+
)
178187

179188

180189
@nox.session(python=DEFAULT_PYTHON_VERSION)
@@ -195,7 +204,7 @@ def docs(session):
195204
"""Build the docs for this library."""
196205

197206
session.install("-e", ".[tracing]")
198-
session.install("sphinx", "alabaster", "recommonmark")
207+
session.install("sphinx==4.0.1", "alabaster", "recommonmark")
199208

200209
shutil.rmtree(os.path.join("docs", "_build"), ignore_errors=True)
201210
session.run(
@@ -217,7 +226,9 @@ def docfx(session):
217226
"""Build the docfx yaml files for this library."""
218227

219228
session.install("-e", ".[tracing]")
220-
session.install("sphinx", "alabaster", "recommonmark", "gcp-sphinx-docfx-yaml")
229+
session.install(
230+
"sphinx==4.0.1", "alabaster", "recommonmark", "gcp-sphinx-docfx-yaml"
231+
)
221232

222233
shutil.rmtree(os.path.join("docs", "_build"), ignore_errors=True)
223234
session.run(

owlbot.py

Lines changed: 83 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,8 @@ def get_staging_dirs(
109109
# ----------------------------------------------------------------------------
110110
# Add templated files
111111
# ----------------------------------------------------------------------------
112-
templated_files = common.py_library(microgenerator=True, samples=True)
113-
s.move(templated_files, excludes=[".coveragerc", "noxfile.py"])
112+
templated_files = common.py_library(microgenerator=True, samples=True, cov_level=99)
113+
s.move(templated_files, excludes=[".coveragerc"])
114114

115115
# Ensure CI runs on a new instance each time
116116
s.replace(
@@ -127,4 +127,85 @@ def get_staging_dirs(
127127

128128
python.py_samples()
129129

130+
# ----------------------------------------------------------------------------
131+
# Customize noxfile.py
132+
# ----------------------------------------------------------------------------
133+
134+
def place_before(path, text, *before_text, escape=None):
135+
replacement = "\n".join(before_text) + "\n" + text
136+
if escape:
137+
for c in escape:
138+
text = text.replace(c, '\\' + c)
139+
s.replace([path], text, replacement)
140+
141+
open_telemetry_test = """
142+
session.install("-e", ".[tracing]", "-c", constraints_path)
143+
144+
# Run py.test against the unit tests with OpenTelemetry.
145+
session.run(
146+
"py.test",
147+
"--quiet",
148+
"--cov=google.cloud.spanner",
149+
"--cov=google.cloud",
150+
"--cov=tests.unit",
151+
"--cov-append",
152+
"--cov-config=.coveragerc",
153+
"--cov-report=",
154+
"--cov-fail-under=0",
155+
os.path.join("tests", "unit"),
156+
*session.posargs,
157+
)
158+
"""
159+
160+
place_before(
161+
"noxfile.py",
162+
"@nox.session(python=UNIT_TEST_PYTHON_VERSIONS)",
163+
open_telemetry_test,
164+
escape="()"
165+
)
166+
167+
skip_tests_if_env_var_not_set ="""# Sanity check: Only run tests if the environment variable is set.
168+
if not os.environ.get("GOOGLE_APPLICATION_CREDENTIALS", "") and not os.environ.get(
169+
"SPANNER_EMULATOR_HOST", ""
170+
):
171+
session.skip(
172+
"Credentials or emulator host must be set via environment variable"
173+
)
174+
"""
175+
176+
place_before(
177+
"noxfile.py",
178+
"# Install pyopenssl for mTLS testing.",
179+
skip_tests_if_env_var_not_set,
180+
escape="()"
181+
)
182+
183+
s.replace(
184+
"noxfile.py",
185+
"""f"--junitxml=unit_{session.python}_sponge_log.xml",
186+
"--cov=google/cloud",
187+
"--cov=tests/unit",""",
188+
"""\"--cov=google.cloud.spanner",
189+
"--cov=google.cloud",
190+
"--cov=tests.unit","""
191+
)
192+
193+
s.replace(
194+
"noxfile.py",
195+
"""session.install\("-e", "."\)""",
196+
"""session.install("-e", ".[tracing]")"""
197+
)
198+
199+
s.replace(
200+
"noxfile.py",
201+
"""# Install all test dependencies, then install this package into the
202+
# virtualenv's dist-packages.
203+
session.install\("mock", "pytest", "google-cloud-testutils", "-c", constraints_path\)
204+
session.install\("-e", ".", "-c", constraints_path\)""",
205+
"""# Install all test dependencies, then install this package into the
206+
# virtualenv's dist-packages.
207+
session.install("mock", "pytest", "google-cloud-testutils", "-c", constraints_path)
208+
session.install("-e", ".[tracing]", "-c", constraints_path)"""
209+
)
210+
130211
s.shell.run(["nox", "-s", "blacken"], hide_output=False)

0 commit comments

Comments
 (0)