1
- # Copyright 2021 Google LLC
1
+ # Copyright 2019 Google LLC
2
2
#
3
3
# Licensed under the Apache License, Version 2.0 (the "License");
4
4
# you may not use this file except in compliance with the License.
28
28
# WARNING - WARNING - WARNING - WARNING - WARNING
29
29
# WARNING - WARNING - WARNING - WARNING - WARNING
30
30
31
- # Copy `noxfile_config.py` to your directory and modify it instead.
31
+ BLACK_VERSION = "black==19.10b0"
32
32
33
+ # Copy `noxfile_config.py` to your directory and modify it instead.
33
34
34
35
# `TEST_CONFIG` dict is a configuration hook that allows users to
35
36
# modify the test configurations. The values here should be in sync
38
39
39
40
TEST_CONFIG = {
40
41
# You can opt out from the test for specific Python versions.
41
- "ignored_versions" : ["2.7" ],
42
+ 'ignored_versions' : [],
43
+
42
44
# Old samples are opted out of enforcing Python type hints
43
45
# All new samples should feature them
44
- "enforce_type_hints" : False ,
46
+ 'enforce_type_hints' : False ,
47
+
45
48
# An envvar key for determining the project id to use. Change it
46
49
# to 'BUILD_SPECIFIC_GCLOUD_PROJECT' if you want to opt in using a
47
50
# build specific Cloud project. You can also use your own string
48
51
# to use your own Cloud project.
49
- " gcloud_project_env" : " GOOGLE_CLOUD_PROJECT" ,
52
+ ' gcloud_project_env' : ' GOOGLE_CLOUD_PROJECT' ,
50
53
# 'gcloud_project_env': 'BUILD_SPECIFIC_GCLOUD_PROJECT',
51
54
# If you need to use a specific version of pip,
52
55
# change pip_version_override to the string representation
53
56
# of the version number, for example, "20.2.4"
54
57
"pip_version_override" : None ,
55
58
# A dictionary you want to inject into your test. Don't put any
56
59
# secrets here. These values will override predefined values.
57
- " envs" : {},
60
+ ' envs' : {},
58
61
}
59
62
60
63
61
64
try :
62
65
# Ensure we can import noxfile_config in the project's directory.
63
- sys .path .append ("." )
66
+ sys .path .append ('.' )
64
67
from noxfile_config import TEST_CONFIG_OVERRIDE
65
68
except ImportError as e :
66
69
print ("No user noxfile_config found: detail: {}" .format (e ))
@@ -75,33 +78,33 @@ def get_pytest_env_vars() -> Dict[str, str]:
75
78
ret = {}
76
79
77
80
# Override the GCLOUD_PROJECT and the alias.
78
- env_key = TEST_CONFIG [" gcloud_project_env" ]
81
+ env_key = TEST_CONFIG [' gcloud_project_env' ]
79
82
# This should error out if not set.
80
- ret ["GOOGLE_CLOUD_PROJECT" ] = os .environ [env_key ]
81
- ret ["GCLOUD_PROJECT" ] = os .environ [env_key ] # deprecated
83
+ ret ['GOOGLE_CLOUD_PROJECT' ] = os .environ [env_key ]
82
84
83
85
# Apply user supplied envs.
84
- ret .update (TEST_CONFIG [" envs" ])
86
+ ret .update (TEST_CONFIG [' envs' ])
85
87
return ret
86
88
87
89
88
90
# DO NOT EDIT - automatically generated.
89
- # All versions used to tested samples.
90
- ALL_VERSIONS = ["2.7" , " 3.6" , "3.7" , "3.8" , "3.9" ]
91
+ # All versions used to test samples.
92
+ ALL_VERSIONS = ["3.6" , "3.7" , "3.8" , "3.9" ]
91
93
92
94
# Any default versions that should be ignored.
93
- IGNORED_VERSIONS = TEST_CONFIG [" ignored_versions" ]
95
+ IGNORED_VERSIONS = TEST_CONFIG [' ignored_versions' ]
94
96
95
97
TESTED_VERSIONS = sorted ([v for v in ALL_VERSIONS if v not in IGNORED_VERSIONS ])
96
98
97
- 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" )
98
100
#
99
101
# Style Checks
100
102
#
101
103
102
104
103
105
def _determine_local_import_names (start_dir : str ) -> List [str ]:
104
106
"""Determines all import names that should be considered "local".
107
+
105
108
This is used when running the linter to insure that import order is
106
109
properly checked.
107
110
"""
@@ -138,7 +141,7 @@ def _determine_local_import_names(start_dir: str) -> List[str]:
138
141
139
142
@nox .session
140
143
def lint (session : nox .sessions .Session ) -> None :
141
- if not TEST_CONFIG [" enforce_type_hints" ]:
144
+ if not TEST_CONFIG [' enforce_type_hints' ]:
142
145
session .install ("flake8" , "flake8-import-order" )
143
146
else :
144
147
session .install ("flake8" , "flake8-import-order" , "flake8-annotations" )
@@ -147,24 +150,21 @@ def lint(session: nox.sessions.Session) -> None:
147
150
args = FLAKE8_COMMON_ARGS + [
148
151
"--application-import-names" ,
149
152
"," .join (local_names ),
150
- "." ,
153
+ "."
151
154
]
152
155
session .run ("flake8" , * args )
153
-
154
-
155
156
#
156
157
# Black
157
158
#
158
159
159
160
160
161
@nox .session
161
162
def blacken (session : nox .sessions .Session ) -> None :
162
- session .install ("black" )
163
+ session .install (BLACK_VERSION )
163
164
python_files = [path for path in os .listdir ("." ) if path .endswith (".py" )]
164
165
165
166
session .run ("black" , * python_files )
166
167
167
-
168
168
#
169
169
# Sample Tests
170
170
#
@@ -173,9 +173,7 @@ def blacken(session: nox.sessions.Session) -> None:
173
173
PYTEST_COMMON_ARGS = ["--junitxml=sponge_log.xml" ]
174
174
175
175
176
- def _session_tests (
177
- session : nox .sessions .Session , post_install : Callable = None
178
- ) -> None :
176
+ def _session_tests (session : nox .sessions .Session , post_install : Callable = None ) -> None :
179
177
if TEST_CONFIG ["pip_version_override" ]:
180
178
pip_version = TEST_CONFIG ["pip_version_override" ]
181
179
session .install (f"pip=={ pip_version } " )
@@ -205,7 +203,7 @@ def _session_tests(
205
203
# on travis where slow and flaky tests are excluded.
206
204
# See http://doc.pytest.org/en/latest/_modules/_pytest/main.html
207
205
success_codes = [0 , 5 ],
208
- env = get_pytest_env_vars (),
206
+ env = get_pytest_env_vars ()
209
207
)
210
208
211
209
@@ -215,9 +213,9 @@ def py(session: nox.sessions.Session) -> None:
215
213
if session .python in TESTED_VERSIONS :
216
214
_session_tests (session )
217
215
else :
218
- session .skip (
219
- "SKIPPED: {} tests are disabled for this sample." . format ( session .python )
220
- )
216
+ session .skip ("SKIPPED: {} tests are disabled for this sample." . format (
217
+ session .python
218
+ ))
221
219
222
220
223
221
#
@@ -226,15 +224,19 @@ def py(session: nox.sessions.Session) -> None:
226
224
227
225
228
226
def _get_repo_root () -> Optional [str ]:
229
- """Returns the root folder of the project."""
230
- # Get root of this repository.
231
- # Assume we don't have directories nested deeper than 10 items.
227
+ """ Returns the root folder of the project. """
228
+ # Get root of this repository. Assume we don't have directories nested deeper than 10 items.
232
229
p = Path (os .getcwd ())
233
230
for i in range (10 ):
234
231
if p is None :
235
232
break
236
233
if Path (p / ".git" ).exists ():
237
234
return str (p )
235
+ # .git is not available in repos cloned via Cloud Build
236
+ # setup.py is always in the library's root, so use that instead
237
+ # https://github.com/googleapis/synthtool/issues/792
238
+ if Path (p / "setup.py" ).exists ():
239
+ return str (p )
238
240
p = p .parent
239
241
raise Exception ("Unable to detect repository root." )
240
242
0 commit comments