37
37
38
38
TEST_CONFIG = {
39
39
# You can opt out from the test for specific Python versions.
40
- "ignored_versions" : ["2.7" ],
40
+ 'ignored_versions' : ["2.7" ],
41
+
42
+ # Old samples are opted out of enforcing Python type hints
43
+ # All new samples should feature them
44
+ 'enforce_type_hints' : False ,
45
+
41
46
# An envvar key for determining the project id to use. Change it
42
47
# to 'BUILD_SPECIFIC_GCLOUD_PROJECT' if you want to opt in using a
43
48
# build specific Cloud project. You can also use your own string
44
49
# to use your own Cloud project.
45
- " gcloud_project_env" : " GOOGLE_CLOUD_PROJECT" ,
50
+ ' gcloud_project_env' : ' GOOGLE_CLOUD_PROJECT' ,
46
51
# 'gcloud_project_env': 'BUILD_SPECIFIC_GCLOUD_PROJECT',
52
+
47
53
# A dictionary you want to inject into your test. Don't put any
48
54
# secrets here. These values will override predefined values.
49
- " envs" : {},
55
+ ' envs' : {},
50
56
}
51
57
52
58
53
59
try :
54
60
# Ensure we can import noxfile_config in the project's directory.
55
- sys .path .append ("." )
61
+ sys .path .append ('.' )
56
62
from noxfile_config import TEST_CONFIG_OVERRIDE
57
63
except ImportError as e :
58
64
print ("No user noxfile_config found: detail: {}" .format (e ))
@@ -67,13 +73,12 @@ def get_pytest_env_vars():
67
73
ret = {}
68
74
69
75
# Override the GCLOUD_PROJECT and the alias.
70
- env_key = TEST_CONFIG [" gcloud_project_env" ]
76
+ env_key = TEST_CONFIG [' gcloud_project_env' ]
71
77
# This should error out if not set.
72
- ret ["GOOGLE_CLOUD_PROJECT" ] = os .environ [env_key ]
73
- ret ["GCLOUD_PROJECT" ] = os .environ [env_key ] # deprecated
78
+ ret ['GOOGLE_CLOUD_PROJECT' ] = os .environ [env_key ]
74
79
75
80
# Apply user supplied envs.
76
- ret .update (TEST_CONFIG [" envs" ])
81
+ ret .update (TEST_CONFIG [' envs' ])
77
82
return ret
78
83
79
84
@@ -82,7 +87,7 @@ def get_pytest_env_vars():
82
87
ALL_VERSIONS = ["2.7" , "3.6" , "3.7" , "3.8" ]
83
88
84
89
# Any default versions that should be ignored.
85
- IGNORED_VERSIONS = TEST_CONFIG [" ignored_versions" ]
90
+ IGNORED_VERSIONS = TEST_CONFIG [' ignored_versions' ]
86
91
87
92
TESTED_VERSIONS = sorted ([v for v in ALL_VERSIONS if v not in IGNORED_VERSIONS ])
88
93
@@ -94,6 +99,7 @@ def get_pytest_env_vars():
94
99
95
100
def _determine_local_import_names (start_dir ):
96
101
"""Determines all import names that should be considered "local".
102
+
97
103
This is used when running the linter to insure that import order is
98
104
properly checked.
99
105
"""
@@ -130,17 +136,18 @@ def _determine_local_import_names(start_dir):
130
136
131
137
@nox .session
132
138
def lint (session ):
133
- session .install ("flake8" , "flake8-import-order" )
139
+ if not TEST_CONFIG ['enforce_type_hints' ]:
140
+ session .install ("flake8" , "flake8-import-order" )
141
+ else :
142
+ session .install ("flake8" , "flake8-import-order" , "flake8-annotations" )
134
143
135
144
local_names = _determine_local_import_names ("." )
136
145
args = FLAKE8_COMMON_ARGS + [
137
146
"--application-import-names" ,
138
147
"," .join (local_names ),
139
- "." ,
148
+ "."
140
149
]
141
150
session .run ("flake8" , * args )
142
-
143
-
144
151
#
145
152
# Black
146
153
#
@@ -153,7 +160,6 @@ def blacken(session):
153
160
154
161
session .run ("black" , * python_files )
155
162
156
-
157
163
#
158
164
# Sample Tests
159
165
#
@@ -193,9 +199,9 @@ def py(session):
193
199
if session .python in TESTED_VERSIONS :
194
200
_session_tests (session )
195
201
else :
196
- session .skip (
197
- "SKIPPED: {} tests are disabled for this sample." . format ( session .python )
198
- )
202
+ session .skip ("SKIPPED: {} tests are disabled for this sample." . format (
203
+ session .python
204
+ ))
199
205
200
206
201
207
#
@@ -212,6 +218,11 @@ def _get_repo_root():
212
218
break
213
219
if Path (p / ".git" ).exists ():
214
220
return str (p )
221
+ # .git is not available in repos cloned via Cloud Build
222
+ # setup.py is always in the library's root, so use that instead
223
+ # https://github.com/googleapis/synthtool/issues/792
224
+ if Path (p / "setup.py" ).exists ():
225
+ return str (p )
215
226
p = p .parent
216
227
raise Exception ("Unable to detect repository root." )
217
228
0 commit comments