forked from googleapis/python-api-common-protos
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnoxfile.py
182 lines (147 loc) · 5.91 KB
/
noxfile.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
# Copyright 2020 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# 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 os
from pathlib import Path
import nox
BLACK_VERSION = "black==19.3b0"
@nox.session(python="3.6")
def blacken(session):
"""Run black.
Format code to uniform standard.
This currently uses Python 3.6 due to the automated Kokoro run of synthtool.
That run uses an image that doesn't have 3.6 installed. Before updating this
check the state of the `gcp_ubuntu_config` we use for that Kokoro run.
"""
session.install(BLACK_VERSION)
session.run("black", "google", "setup.py")
@nox.session(python="3.8")
def lint_setup_py(session):
"""Verify that setup.py is valid"""
session.install("docutils", "pygments")
session.run("python", "setup.py", "check", "--strict")
def default(session):
# Install all test dependencies, then install this package in-place.
session.install("mock", "pytest", "pytest-cov")
session.install("-e", ".")
# Install googleapis-api-common-protos
# This *must* be the last install command to get the package from source.
session.install("e", "..")
# Run py.test against the unit tests.
session.run(
"py.test",
"--quiet",
"--cov=google.cloud",
"--cov=tests.unit",
"--cov-append",
"--cov-config=.coveragerc",
"--cov-report=",
"--cov-fail-under=0",
os.path.join("tests", "unit"),
*session.posargs,
)
def unit(session):
"""Run the unit test suite."""
default(session)
def system(session):
"""Run the system test suite."""
system_test_path = os.path.join("tests", "system.py")
system_test_folder_path = os.path.join("tests", "system")
# Sanity check: Only run tests if the environment variable is set.
if not os.environ.get("GOOGLE_APPLICATION_CREDENTIALS", ""):
session.skip("Credentials must be set via environment variable")
system_test_exists = os.path.exists(system_test_path)
system_test_folder_exists = os.path.exists(system_test_folder_path)
# Sanity check: only run tests if found.
if not system_test_exists and not system_test_folder_exists:
session.skip("System tests were not found")
# Use pre-release gRPC for system tests.
session.install("--pre", "grpcio")
# Install all test dependencies, then install this package into the
# virtualenv's dist-packages.
session.install("mock", "pytest", "google-cloud-testutils")
session.install("-e", ".")
# Install googleapis-api-common-protos
# This *must* be the last install command to get the package from source.
session.install("e", "..")
# Run py.test against the system tests.
if system_test_exists:
session.run("py.test", "--verbose", system_test_path, *session.posargs)
if system_test_folder_exists:
session.run("py.test", "--verbose", system_test_folder_path, *session.posargs)
@nox.session(python=["3.6", "3.7", "3.8"])
@nox.parametrize(
"library",
["python-pubsub", "python-texttospeech", "python-speech"],
ids=["pubsub", "texttospeech", "speech"],
)
def test(session, library):
"""Run tests from a downstream libraries.
To verify that any changes we make here will not break downstream libraries, clone
a few and run their unit and system tests.
NOTE: The unit and system test functions above are copied from the templates.
They will need to be updated when the templates change.
* Pub/Sub: GAPIC with handwritten layer.
* Text-to-Speech: Full GAPIC.
* Speech: Full GAPIC, has long running operations.
"""
try:
session.run("git", "-C", library, "pull", external=True)
except nox.command.CommandFailed:
session.run(
"git",
"clone",
"--single-branch",
f"https://github.com/googleapis/{library}",
external=True,
)
session.cd(library)
unit(session)
# system tests are run on 3.7 only
if session.python == "3.7":
if library == "python-pubsub":
session.install("psutil")
system(session)
@nox.session(python="3.8")
def generate_protos(session):
"""Generates the protos using protoc.
This session but be last to avoid overwriting the protos used in CI runs.
Some notes on the `google` directory:
1. The `_pb2.py` files are produced by protoc.
2. The .proto files are non-functional but are left in the repository
to make it easier to understand diffs.
3. The `google` directory also has `__init__.py` files to create proper modules.
If a new subdirectory is added, you will need to create more `__init__.py`
files.
"""
# longrunning operations directory is non-standard for backwards compatibility
# see comments in directory for details
# Temporarily rename the operations_pb2.py to keep it from getting overwritten
os.replace(
"google/longrunning/operations_pb2.py",
"google/longrunning/operations_pb2-COPY.py",
)
session.install("grpcio-tools")
protos = [str(p) for p in (Path(".").glob("google/**/*.proto"))]
session.run(
"python", "-m", "grpc_tools.protoc", "--proto_path=.", "--python_out=.", *protos
)
# Clean up LRO directory
os.replace(
"google/longrunning/operations_pb2.py",
"google/longrunning/operations_proto_pb2.py",
)
os.replace(
"google/longrunning/operations_pb2-COPY.py",
"google/longrunning/operations_pb2.py",
)