39
39
# You can opt out from the test for specific Python versions.
40
40
'ignored_versions' : ["2.7" ],
41
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
+
42
46
# An envvar key for determining the project id to use. Change it
43
47
# to 'BUILD_SPECIFIC_GCLOUD_PROJECT' if you want to opt in using a
44
48
# build specific Cloud project. You can also use your own string
@@ -132,7 +136,10 @@ def _determine_local_import_names(start_dir):
132
136
133
137
@nox .session
134
138
def lint (session ):
135
- 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" )
136
143
137
144
local_names = _determine_local_import_names ("." )
138
145
args = FLAKE8_COMMON_ARGS + [
@@ -141,8 +148,18 @@ def lint(session):
141
148
"."
142
149
]
143
150
session .run ("flake8" , * args )
151
+ #
152
+ # Black
153
+ #
144
154
145
155
156
+ @nox .session
157
+ def blacken (session ):
158
+ session .install ("black" )
159
+ python_files = [path for path in os .listdir ("." ) if path .endswith (".py" )]
160
+
161
+ session .run ("black" , * python_files )
162
+
146
163
#
147
164
# Sample Tests
148
165
#
@@ -201,6 +218,11 @@ def _get_repo_root():
201
218
break
202
219
if Path (p / ".git" ).exists ():
203
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 )
204
226
p = p .parent
205
227
raise Exception ("Unable to detect repository root." )
206
228
0 commit comments