Skip to content

Commit 9384a75

Browse files
chore: migrate to main branch (#372)
* docs: migrate to main branch * chore: update changelog * fix: revert some owlbot changes * chore: revert owlbot * chore: update owlbot * chore: update owlbot * 🦉 Updates from OwlBot See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * chore: update owlbot * 🦉 Updates from OwlBot See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
1 parent e6238f1 commit 9384a75

File tree

1 file changed

+46
-32
lines changed

1 file changed

+46
-32
lines changed

dialogflow/noxfile.py

Lines changed: 46 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import os
1818
from pathlib import Path
1919
import sys
20+
from typing import Callable, Dict, List, Optional
2021

2122
import nox
2223

@@ -27,8 +28,9 @@
2728
# WARNING - WARNING - WARNING - WARNING - WARNING
2829
# WARNING - WARNING - WARNING - WARNING - WARNING
2930

30-
# Copy `noxfile_config.py` to your directory and modify it instead.
31+
BLACK_VERSION = "black==19.10b0"
3132

33+
# Copy `noxfile_config.py` to your directory and modify it instead.
3234

3335
# `TEST_CONFIG` dict is a configuration hook that allows users to
3436
# modify the test configurations. The values here should be in sync
@@ -37,25 +39,31 @@
3739

3840
TEST_CONFIG = {
3941
# You can opt out from the test for specific Python versions.
40-
"ignored_versions": ["2.7"],
42+
'ignored_versions': [],
43+
4144
# Old samples are opted out of enforcing Python type hints
4245
# All new samples should feature them
43-
"enforce_type_hints": False,
46+
'enforce_type_hints': False,
47+
4448
# An envvar key for determining the project id to use. Change it
4549
# to 'BUILD_SPECIFIC_GCLOUD_PROJECT' if you want to opt in using a
4650
# build specific Cloud project. You can also use your own string
4751
# to use your own Cloud project.
48-
"gcloud_project_env": "GOOGLE_CLOUD_PROJECT",
52+
'gcloud_project_env': 'GOOGLE_CLOUD_PROJECT',
4953
# 'gcloud_project_env': 'BUILD_SPECIFIC_GCLOUD_PROJECT',
54+
# If you need to use a specific version of pip,
55+
# change pip_version_override to the string representation
56+
# of the version number, for example, "20.2.4"
57+
"pip_version_override": None,
5058
# A dictionary you want to inject into your test. Don't put any
5159
# secrets here. These values will override predefined values.
52-
"envs": {},
60+
'envs': {},
5361
}
5462

5563

5664
try:
5765
# Ensure we can import noxfile_config in the project's directory.
58-
sys.path.append(".")
66+
sys.path.append('.')
5967
from noxfile_config import TEST_CONFIG_OVERRIDE
6068
except ImportError as e:
6169
print("No user noxfile_config found: detail: {}".format(e))
@@ -65,36 +73,36 @@
6573
TEST_CONFIG.update(TEST_CONFIG_OVERRIDE)
6674

6775

68-
def get_pytest_env_vars():
76+
def get_pytest_env_vars() -> Dict[str, str]:
6977
"""Returns a dict for pytest invocation."""
7078
ret = {}
7179

7280
# Override the GCLOUD_PROJECT and the alias.
73-
env_key = TEST_CONFIG["gcloud_project_env"]
81+
env_key = TEST_CONFIG['gcloud_project_env']
7482
# This should error out if not set.
75-
ret["GOOGLE_CLOUD_PROJECT"] = os.environ[env_key]
83+
ret['GOOGLE_CLOUD_PROJECT'] = os.environ[env_key]
7684

7785
# Apply user supplied envs.
78-
ret.update(TEST_CONFIG["envs"])
86+
ret.update(TEST_CONFIG['envs'])
7987
return ret
8088

8189

8290
# DO NOT EDIT - automatically generated.
83-
# All versions used to tested samples.
84-
ALL_VERSIONS = ["2.7", "3.6", "3.7", "3.8"]
91+
# All versions used to test samples.
92+
ALL_VERSIONS = ["3.6", "3.7", "3.8", "3.9"]
8593

8694
# Any default versions that should be ignored.
87-
IGNORED_VERSIONS = TEST_CONFIG["ignored_versions"]
95+
IGNORED_VERSIONS = TEST_CONFIG['ignored_versions']
8896

8997
TESTED_VERSIONS = sorted([v for v in ALL_VERSIONS if v not in IGNORED_VERSIONS])
9098

91-
INSTALL_LIBRARY_FROM_SOURCE = bool(os.environ.get("INSTALL_LIBRARY_FROM_SOURCE", False))
99+
INSTALL_LIBRARY_FROM_SOURCE = os.environ.get("INSTALL_LIBRARY_FROM_SOURCE", False) in ("True", "true")
92100
#
93101
# Style Checks
94102
#
95103

96104

97-
def _determine_local_import_names(start_dir):
105+
def _determine_local_import_names(start_dir: str) -> List[str]:
98106
"""Determines all import names that should be considered "local".
99107
100108
This is used when running the linter to insure that import order is
@@ -132,8 +140,8 @@ def _determine_local_import_names(start_dir):
132140

133141

134142
@nox.session
135-
def lint(session):
136-
if not TEST_CONFIG["enforce_type_hints"]:
143+
def lint(session: nox.sessions.Session) -> None:
144+
if not TEST_CONFIG['enforce_type_hints']:
137145
session.install("flake8", "flake8-import-order")
138146
else:
139147
session.install("flake8", "flake8-import-order", "flake8-annotations")
@@ -142,24 +150,21 @@ def lint(session):
142150
args = FLAKE8_COMMON_ARGS + [
143151
"--application-import-names",
144152
",".join(local_names),
145-
".",
153+
"."
146154
]
147155
session.run("flake8", *args)
148-
149-
150156
#
151157
# Black
152158
#
153159

154160

155161
@nox.session
156-
def blacken(session):
157-
session.install("black")
162+
def blacken(session: nox.sessions.Session) -> None:
163+
session.install(BLACK_VERSION)
158164
python_files = [path for path in os.listdir(".") if path.endswith(".py")]
159165

160166
session.run("black", *python_files)
161167

162-
163168
#
164169
# Sample Tests
165170
#
@@ -168,13 +173,22 @@ def blacken(session):
168173
PYTEST_COMMON_ARGS = ["--junitxml=sponge_log.xml"]
169174

170175

171-
def _session_tests(session, post_install=None):
176+
def _session_tests(session: nox.sessions.Session, post_install: Callable = None) -> None:
177+
if TEST_CONFIG["pip_version_override"]:
178+
pip_version = TEST_CONFIG["pip_version_override"]
179+
session.install(f"pip=={pip_version}")
172180
"""Runs py.test for a particular project."""
173181
if os.path.exists("requirements.txt"):
174-
session.install("-r", "requirements.txt")
182+
if os.path.exists("constraints.txt"):
183+
session.install("-r", "requirements.txt", "-c", "constraints.txt")
184+
else:
185+
session.install("-r", "requirements.txt")
175186

176187
if os.path.exists("requirements-test.txt"):
177-
session.install("-r", "requirements-test.txt")
188+
if os.path.exists("constraints-test.txt"):
189+
session.install("-r", "requirements-test.txt", "-c", "constraints-test.txt")
190+
else:
191+
session.install("-r", "requirements-test.txt")
178192

179193
if INSTALL_LIBRARY_FROM_SOURCE:
180194
session.install("-e", _get_repo_root())
@@ -194,22 +208,22 @@ def _session_tests(session, post_install=None):
194208

195209

196210
@nox.session(python=ALL_VERSIONS)
197-
def py(session):
211+
def py(session: nox.sessions.Session) -> None:
198212
"""Runs py.test for a sample using the specified version of Python."""
199213
if session.python in TESTED_VERSIONS:
200214
_session_tests(session)
201215
else:
202-
session.skip(
203-
"SKIPPED: {} tests are disabled for this sample.".format(session.python)
204-
)
216+
session.skip("SKIPPED: {} tests are disabled for this sample.".format(
217+
session.python
218+
))
205219

206220

207221
#
208222
# Readmegen
209223
#
210224

211225

212-
def _get_repo_root():
226+
def _get_repo_root() -> Optional[str]:
213227
""" Returns the root folder of the project. """
214228
# Get root of this repository. Assume we don't have directories nested deeper than 10 items.
215229
p = Path(os.getcwd())
@@ -232,7 +246,7 @@ def _get_repo_root():
232246

233247
@nox.session
234248
@nox.parametrize("path", GENERATED_READMES)
235-
def readmegen(session, path):
249+
def readmegen(session: nox.sessions.Session, path: str) -> None:
236250
"""(Re-)generates the readme for a sample."""
237251
session.install("jinja2", "pyyaml")
238252
dir_ = os.path.dirname(path)

0 commit comments

Comments
 (0)