2828# WARNING - WARNING - WARNING - WARNING - WARNING
2929# WARNING - WARNING - WARNING - WARNING - WARNING
3030
31- # Copy `noxfile_config.py` to your directory and modify it instead.
31+ BLACK_VERSION = "black==19.10b0"
3232
33+ # Copy `noxfile_config.py` to your directory and modify it instead.
3334
3435# `TEST_CONFIG` dict is a configuration hook that allows users to
3536# modify the test configurations. The values here should be in sync
3839
3940TEST_CONFIG = {
4041 # You can opt out from the test for specific Python versions.
41- 'ignored_versions' : ["2.7" ],
42+ 'ignored_versions' : [],
4243
4344 # Old samples are opted out of enforcing Python type hints
4445 # All new samples should feature them
5051 # to use your own Cloud project.
5152 'gcloud_project_env' : 'GOOGLE_CLOUD_PROJECT' ,
5253 # 'gcloud_project_env': 'BUILD_SPECIFIC_GCLOUD_PROJECT',
53-
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 ,
5458 # A dictionary you want to inject into your test. Don't put any
5559 # secrets here. These values will override predefined values.
5660 'envs' : {},
@@ -77,23 +81,22 @@ def get_pytest_env_vars() -> Dict[str, str]:
7781 env_key = TEST_CONFIG ['gcloud_project_env' ]
7882 # This should error out if not set.
7983 ret ['GOOGLE_CLOUD_PROJECT' ] = os .environ [env_key ]
80- ret ['GCLOUD_PROJECT' ] = os .environ [env_key ] # deprecated
8184
8285 # Apply user supplied envs.
8386 ret .update (TEST_CONFIG ['envs' ])
8487 return ret
8588
8689
8790# DO NOT EDIT - automatically generated.
88- # All versions used to tested samples.
89- 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" ]
9093
9194# Any default versions that should be ignored.
9295IGNORED_VERSIONS = TEST_CONFIG ['ignored_versions' ]
9396
9497TESTED_VERSIONS = sorted ([v for v in ALL_VERSIONS if v not in IGNORED_VERSIONS ])
9598
96- 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" )
97100#
98101# Style Checks
99102#
@@ -110,8 +113,8 @@ def _determine_local_import_names(start_dir: str) -> List[str]:
110113 basename
111114 for basename , extension in file_ext_pairs
112115 if extension == ".py"
113- or os .path .isdir (os .path .join (start_dir , basename ))
114- and basename not in ("__pycache__" )
116+ or os .path .isdir (os .path .join (start_dir , basename ))
117+ and basename not in ("__pycache__" )
115118 ]
116119
117120
@@ -150,20 +153,18 @@ def lint(session: nox.sessions.Session) -> None:
150153 "."
151154 ]
152155 session .run ("flake8" , * args )
153-
154-
155156#
156157# Black
157158#
158159
160+
159161@nox .session
160162def blacken (session : nox .sessions .Session ) -> None :
161- session .install ("black" )
163+ session .install (BLACK_VERSION )
162164 python_files = [path for path in os .listdir ("." ) if path .endswith (".py" )]
163165
164166 session .run ("black" , * python_files )
165167
166-
167168#
168169# Sample Tests
169170#
@@ -173,6 +174,9 @@ def blacken(session: nox.sessions.Session) -> None:
173174
174175
175176def _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 } " )
176180 """Runs py.test for a particular project."""
177181 if os .path .exists ("requirements.txt" ):
178182 if os .path .exists ("constraints.txt" ):
@@ -221,14 +225,18 @@ def py(session: nox.sessions.Session) -> None:
221225
222226def _get_repo_root () -> Optional [str ]:
223227 """ Returns the root folder of the project. """
224- # Get root of this repository.
225- # Assume we don't have directories nested deeper than 10 items.
228+ # Get root of this repository. Assume we don't have directories nested deeper than 10 items.
226229 p = Path (os .getcwd ())
227230 for i in range (10 ):
228231 if p is None :
229232 break
230233 if Path (p / ".git" ).exists ():
231234 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 )
232240 p = p .parent
233241 raise Exception ("Unable to detect repository root." )
234242
0 commit comments