|
| 1 | +# Copyright 2023 Google LLC |
| 2 | +# |
| 3 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +# you may not use this file except in compliance with the License. |
| 5 | +# You may obtain a copy of the License at |
| 6 | +# |
| 7 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +# |
| 9 | +# Unless required by applicable law or agreed to in writing, software |
| 10 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +# See the License for the specific language governing permissions and |
| 13 | +# limitations under the License. |
| 14 | + |
| 15 | +# Default TEST_CONFIG_OVERRIDE for python repos. |
| 16 | + |
| 17 | +# You can copy this file into your directory, then it will be imported from |
| 18 | +# the noxfile.py. |
| 19 | + |
| 20 | +# The source of truth: |
| 21 | +# https://github.com/GoogleCloudPlatform/python-docs-samples/blob/main/noxfile_config.py |
| 22 | + |
| 23 | +import time |
| 24 | + |
| 25 | + |
| 26 | +TEST_CONFIG_OVERRIDE = { |
| 27 | + # You can opt out from the test for specific Python versions. |
| 28 | + "ignored_versions": ["3.6", "3.7", "3.8", "3.9", "3.10", "3.11"], |
| 29 | + # Old samples are opted out of enforcing Python type hints |
| 30 | + # All new samples should feature them |
| 31 | + "enforce_type_hints": False, |
| 32 | + # An envvar key for determining the project id to use. Change it |
| 33 | + # to 'BUILD_SPECIFIC_GCLOUD_PROJECT' if you want to opt in using a |
| 34 | + # build specific Cloud project. You can also use your own string |
| 35 | + # to use your own Cloud project. |
| 36 | + "gcloud_project_env": "GOOGLE_CLOUD_PROJECT", |
| 37 | + # 'gcloud_project_env': 'BUILD_SPECIFIC_GCLOUD_PROJECT', |
| 38 | + # If you need to use a specific version of pip, |
| 39 | + # change pip_version_override to the string representation |
| 40 | + # of the version number, for example, "20.2.4" |
| 41 | + "pip_version_override": None, |
| 42 | + # A dictionary you want to inject into your test. Don't put any |
| 43 | + # secrets here. These values will override predefined values. |
| 44 | + "envs": {}, |
| 45 | +} |
| 46 | + |
| 47 | + |
| 48 | +def retry_installs(func): |
| 49 | + def wrap_in_retries(*args, **kwargs): |
| 50 | + for attempt in range(3): |
| 51 | + try: |
| 52 | + result = func(*args, **kwargs) |
| 53 | + return result |
| 54 | + except Exception as e: |
| 55 | + print(f"Attempt #{attempt} failed to install {*args}, {**kwargs}") |
| 56 | + time.sleep(5) |
| 57 | + raise e |
| 58 | + |
| 59 | + return wrap_in_retries |
| 60 | + |
| 61 | + |
| 62 | +SESSION_INSTALL = main.nox.Session.install |
| 63 | +main.nox.Session.install = retry_installs(SESSION_INSTALL) |
0 commit comments