3737
3838TEST_CONFIG = {
3939 # 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+
4146 # An envvar key for determining the project id to use. Change it
4247 # to 'BUILD_SPECIFIC_GCLOUD_PROJECT' if you want to opt in using a
4348 # build specific Cloud project. You can also use your own string
4449 # to use your own Cloud project.
45- " gcloud_project_env" : " GOOGLE_CLOUD_PROJECT" ,
50+ ' gcloud_project_env' : ' GOOGLE_CLOUD_PROJECT' ,
4651 # 'gcloud_project_env': 'BUILD_SPECIFIC_GCLOUD_PROJECT',
52+
4753 # A dictionary you want to inject into your test. Don't put any
4854 # secrets here. These values will override predefined values.
49- " envs" : {},
55+ ' envs' : {},
5056}
5157
5258
5359try :
5460 # Ensure we can import noxfile_config in the project's directory.
55- sys .path .append ("." )
61+ sys .path .append ('.' )
5662 from noxfile_config import TEST_CONFIG_OVERRIDE
5763except ImportError as e :
5864 print ("No user noxfile_config found: detail: {}" .format (e ))
@@ -67,13 +73,12 @@ def get_pytest_env_vars():
6773 ret = {}
6874
6975 # Override the GCLOUD_PROJECT and the alias.
70- env_key = TEST_CONFIG [" gcloud_project_env" ]
76+ env_key = TEST_CONFIG [' gcloud_project_env' ]
7177 # 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 ]
7479
7580 # Apply user supplied envs.
76- ret .update (TEST_CONFIG [" envs" ])
81+ ret .update (TEST_CONFIG [' envs' ])
7782 return ret
7883
7984
@@ -82,7 +87,7 @@ def get_pytest_env_vars():
8287ALL_VERSIONS = ["2.7" , "3.6" , "3.7" , "3.8" ]
8388
8489# Any default versions that should be ignored.
85- IGNORED_VERSIONS = TEST_CONFIG [" ignored_versions" ]
90+ IGNORED_VERSIONS = TEST_CONFIG [' ignored_versions' ]
8691
8792TESTED_VERSIONS = sorted ([v for v in ALL_VERSIONS if v not in IGNORED_VERSIONS ])
8893
@@ -94,6 +99,7 @@ def get_pytest_env_vars():
9499
95100def _determine_local_import_names (start_dir ):
96101 """Determines all import names that should be considered "local".
102+
97103 This is used when running the linter to insure that import order is
98104 properly checked.
99105 """
@@ -130,17 +136,18 @@ def _determine_local_import_names(start_dir):
130136
131137@nox .session
132138def 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" )
134143
135144 local_names = _determine_local_import_names ("." )
136145 args = FLAKE8_COMMON_ARGS + [
137146 "--application-import-names" ,
138147 "," .join (local_names ),
139- "." ,
148+ "."
140149 ]
141150 session .run ("flake8" , * args )
142-
143-
144151#
145152# Black
146153#
@@ -153,7 +160,6 @@ def blacken(session):
153160
154161 session .run ("black" , * python_files )
155162
156-
157163#
158164# Sample Tests
159165#
@@ -193,9 +199,9 @@ def py(session):
193199 if session .python in TESTED_VERSIONS :
194200 _session_tests (session )
195201 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+ ))
199205
200206
201207#
@@ -212,6 +218,11 @@ def _get_repo_root():
212218 break
213219 if Path (p / ".git" ).exists ():
214220 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 )
215226 p = p .parent
216227 raise Exception ("Unable to detect repository root." )
217228
0 commit comments