diff --git a/synthtool/gcp/templates/python_library/.kokoro/build.sh b/synthtool/gcp/templates/python_library/.kokoro/build.sh index 758f299e6..400197473 100755 --- a/synthtool/gcp/templates/python_library/.kokoro/build.sh +++ b/synthtool/gcp/templates/python_library/.kokoro/build.sh @@ -15,7 +15,11 @@ set -eo pipefail -cd github/{{ metadata['repo']['repo'].split('/')[1] }} +if [[ -z "${PROJECT_ROOT:-}" ]]; then + PROJECT_ROOT="github/{{ metadata['repo']['repo'].split('/')[1] }}" +fi + +cd "${PROJECT_ROOT}" # Disable buffering, so that the logs stream through. export PYTHONUNBUFFERED=1 @@ -30,16 +34,16 @@ export GOOGLE_APPLICATION_CREDENTIALS=${KOKORO_GFILE_DIR}/service-account.json export PROJECT_ID=$(cat "${KOKORO_GFILE_DIR}/project-id.json") # Remove old nox -python3.6 -m pip uninstall --yes --quiet nox-automation +python3 -m pip uninstall --yes --quiet nox-automation # Install nox -python3.6 -m pip install --upgrade --quiet nox -python3.6 -m nox --version +python3 -m pip install --upgrade --quiet nox +python3 -m nox --version # If NOX_SESSION is set, it only runs the specified session, # otherwise run all the sessions. if [[ -n "${NOX_SESSION:-}" ]]; then - python3.6 -m nox -s "${NOX_SESSION:-}" + python3 -m nox -s ${NOX_SESSION:-} else - python3.6 -m nox + python3 -m nox fi diff --git a/synthtool/gcp/templates/python_library/.kokoro/docs/docs-presubmit.cfg b/synthtool/gcp/templates/python_library/.kokoro/docs/docs-presubmit.cfg index 111810782..91f8a3be0 100644 --- a/synthtool/gcp/templates/python_library/.kokoro/docs/docs-presubmit.cfg +++ b/synthtool/gcp/templates/python_library/.kokoro/docs/docs-presubmit.cfg @@ -15,3 +15,14 @@ env_vars: { key: "TRAMPOLINE_IMAGE_UPLOAD" value: "false" } + +env_vars: { + key: "TRAMPOLINE_BUILD_FILE" + value: github/{{ metadata['repo']['repo'].split('/')[1] }}/.kokoro/build.sh" +} + +# Only run this nox session. +env_vars: { + key: "NOX_SESSION" + value: "docs docfx" +} diff --git a/synthtool/gcp/templates/python_library/.trampolinerc b/synthtool/gcp/templates/python_library/.trampolinerc index 995ee2911..c7d663ae9 100644 --- a/synthtool/gcp/templates/python_library/.trampolinerc +++ b/synthtool/gcp/templates/python_library/.trampolinerc @@ -18,12 +18,14 @@ required_envvars+=( "STAGING_BUCKET" "V2_STAGING_BUCKET" + "NOX_SESSION" ) # Add env vars which are passed down into the container here. pass_down_envvars+=( "STAGING_BUCKET" "V2_STAGING_BUCKET" + "NOX_SESSION" ) # Prevent unintentional override on the default image. diff --git a/synthtool/gcp/templates/python_library/noxfile.py.j2 b/synthtool/gcp/templates/python_library/noxfile.py.j2 index afec6442c..ee187e795 100644 --- a/synthtool/gcp/templates/python_library/noxfile.py.j2 +++ b/synthtool/gcp/templates/python_library/noxfile.py.j2 @@ -30,6 +30,17 @@ DEFAULT_PYTHON_VERSION="{{ default_python_version }}" SYSTEM_TEST_PYTHON_VERSIONS=[{% for v in system_test_python_versions %}"{{v}}"{% if not loop.last %},{% endif %}{% endfor %}] UNIT_TEST_PYTHON_VERSIONS=[{% for v in unit_test_python_versions %}"{{v}}"{% if not loop.last %},{% endif %}{% endfor %}] +# 'docfx' is excluded since it only needs to run in 'docs-presubmit' +nox.options.sessions = [ + "unit", + "system", + "cover", + "lint", + "lint_setup_py", + "blacken", + "docs", +] + @nox.session(python=DEFAULT_PYTHON_VERSION) def lint(session): """Run linters.