Skip to content

Commit

Permalink
chore: skip reporting coverage for namespace package, update secrets …
Browse files Browse the repository at this point in the history
…manager (via synth) (#280)

* chore(py-library): update decrypt secrets file

* chore(py-library): update decrypt secrets file

From https://github.com/GoogleCloudPlatform/python-docs-samples/blob/master/scripts/decrypt-secrets.sh

* docs: explain conditional

Co-authored-by: Jeffrey Rennie <rennie@google.com>

Source-Author: Bu Sun Kim <8822365+busunkim96@users.noreply.github.com>
Source-Date: Tue Sep 8 11:35:59 2020 -0600
Source-Repo: googleapis/synthtool
Source-Sha: d302f93d7f47e2852e585ac35ab2d15585717ec0
Source-Link: googleapis/synthtool@d302f93

* chore(python-library): use sphinx 1.5.5 for the docfx job

Originally tested at:
googleapis/python-texttospeech#89

This change will fix the missing docstring in the yaml files.

Source-Author: Takashi Matsuo <tmatsuo@google.com>
Source-Date: Thu Sep 10 04:12:14 2020 +0000
Source-Repo: googleapis/synthtool
Source-Sha: ffcee7952b74f647cbb3ef021d95422f10816fca
Source-Link: googleapis/synthtool@ffcee79

* build(python): use release-publish app for notifying GitHub of releas…

* build(python): use release-publish app for notifying GitHub of release status

* fix: re-add pypi password

Source-Author: Bu Sun Kim <8822365+busunkim96@users.noreply.github.com>
Source-Date: Wed Sep 16 08:46:42 2020 -0600
Source-Repo: googleapis/synthtool
Source-Sha: 257fda18168bedb76985024bd198ed1725485488
Source-Link: googleapis/synthtool@257fda1

* build(python): add secret manager in kokoro

Source-Author: Bu Sun Kim <8822365+busunkim96@users.noreply.github.com>
Source-Date: Wed Sep 16 10:24:40 2020 -0600
Source-Repo: googleapis/synthtool
Source-Sha: dba48bb9bc6959c232bec9150ac6313b608fe7bd
Source-Link: googleapis/synthtool@dba48bb

* chore(python): add sphinx doctest extension

Source-Author: Bu Sun Kim <8822365+busunkim96@users.noreply.github.com>
Source-Date: Mon Sep 21 13:09:57 2020 -0600
Source-Repo: googleapis/synthtool
Source-Sha: 27f4406999b1eee29e04b09b2423a8e4646c7e24
Source-Link: googleapis/synthtool@27f4406

* chore(python): remove note about editable installs

`pip install -e .` is supported and is how we install the library for tests.

Source-Author: Bu Sun Kim <8822365+busunkim96@users.noreply.github.com>
Source-Date: Tue Sep 22 12:06:12 2020 -0600
Source-Repo: googleapis/synthtool
Source-Sha: a651c5fb763c69a921aecdd3e1d8dc51dbf20f8d
Source-Link: googleapis/synthtool@a651c5f

* chore(python): skip reporting coverage for namespace package

Source-Author: Tres Seaver <tseaver@palladion.com>
Source-Date: Wed Sep 23 10:58:13 2020 -0400
Source-Repo: googleapis/synthtool
Source-Sha: f3c04883d6c43261ff13db1f52d03a283be06871
Source-Link: googleapis/synthtool@f3c0488
  • Loading branch information
yoshi-automation committed Sep 25, 2020
1 parent 50b43d9 commit 2f4164d
Show file tree
Hide file tree
Showing 9 changed files with 92 additions and 67 deletions.
5 changes: 4 additions & 1 deletion .coveragerc
Expand Up @@ -17,6 +17,8 @@
# Generated by synthtool. DO NOT EDIT!
[run]
branch = True
omit =
google/cloud/__init__.py

[report]
fail_under = 100
Expand All @@ -32,4 +34,5 @@ omit =
*/gapic/*.py
*/proto/*.py
*/core/*.py
*/site-packages/*.py
*/site-packages/*.py
google/cloud/__init__.py
43 changes: 43 additions & 0 deletions .kokoro/populate-secrets.sh
@@ -0,0 +1,43 @@
#!/bin/bash
# Copyright 2020 Google LLC.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

set -eo pipefail

function now { date +"%Y-%m-%d %H:%M:%S" | tr -d '\n' ;}
function msg { println "$*" >&2 ;}
function println { printf '%s\n' "$(now) $*" ;}


# Populates requested secrets set in SECRET_MANAGER_KEYS from service account:
# kokoro-trampoline@cloud-devrel-kokoro-resources.iam.gserviceaccount.com
SECRET_LOCATION="${KOKORO_GFILE_DIR}/secret_manager"
msg "Creating folder on disk for secrets: ${SECRET_LOCATION}"
mkdir -p ${SECRET_LOCATION}
for key in $(echo ${SECRET_MANAGER_KEYS} | sed "s/,/ /g")
do
msg "Retrieving secret ${key}"
docker run --entrypoint=gcloud \
--volume=${KOKORO_GFILE_DIR}:${KOKORO_GFILE_DIR} \
gcr.io/google.com/cloudsdktool/cloud-sdk \
secrets versions access latest \
--project cloud-devrel-kokoro-resources \
--secret ${key} > \
"${SECRET_LOCATION}/${key}"
if [[ $? == 0 ]]; then
msg "Secret written to ${SECRET_LOCATION}/${key}"
else
msg "Error retrieving secret ${key}"
fi
done
50 changes: 13 additions & 37 deletions .kokoro/release/common.cfg
Expand Up @@ -23,42 +23,18 @@ env_vars: {
value: "github/python-storage/.kokoro/release.sh"
}

# Fetch the token needed for reporting release status to GitHub
before_action {
fetch_keystore {
keystore_resource {
keystore_config_id: 73713
keyname: "yoshi-automation-github-key"
}
}
}

# Fetch PyPI password
before_action {
fetch_keystore {
keystore_resource {
keystore_config_id: 73713
keyname: "google_cloud_pypi_password"
}
}
}

# Fetch magictoken to use with Magic Github Proxy
before_action {
fetch_keystore {
keystore_resource {
keystore_config_id: 73713
keyname: "releasetool-magictoken"
}
}
# Fetch PyPI password
before_action {
fetch_keystore {
keystore_resource {
keystore_config_id: 73713
keyname: "google_cloud_pypi_password"
}
}
}

# Fetch api key to use with Magic Github Proxy
before_action {
fetch_keystore {
keystore_resource {
keystore_config_id: 73713
keyname: "magic-github-proxy-api-key"
}
}
}
# Tokens needed to report release status back to GitHub
env_vars: {
key: "SECRET_MANAGER_KEYS"
value: "releasetool-publish-reporter-app,releasetool-publish-reporter-googleapis-installation,releasetool-publish-reporter-pem"
}
15 changes: 10 additions & 5 deletions .kokoro/trampoline.sh
Expand Up @@ -15,9 +15,14 @@

set -eo pipefail

python3 "${KOKORO_GFILE_DIR}/trampoline_v1.py" || ret_code=$?
# Always run the cleanup script, regardless of the success of bouncing into
# the container.
function cleanup() {
chmod +x ${KOKORO_GFILE_DIR}/trampoline_cleanup.sh
${KOKORO_GFILE_DIR}/trampoline_cleanup.sh
echo "cleanup";
}
trap cleanup EXIT

chmod +x ${KOKORO_GFILE_DIR}/trampoline_cleanup.sh
${KOKORO_GFILE_DIR}/trampoline_cleanup.sh || true

exit ${ret_code}
$(dirname $0)/populate-secrets.sh # Secret Manager secrets.
python3 "${KOKORO_GFILE_DIR}/trampoline_v1.py"
19 changes: 0 additions & 19 deletions CONTRIBUTING.rst
Expand Up @@ -80,25 +80,6 @@ We use `nox <https://nox.readthedocs.io/en/latest/>`__ to instrument our tests.

.. nox: https://pypi.org/project/nox/
Note on Editable Installs / Develop Mode
========================================

- As mentioned previously, using ``setuptools`` in `develop mode`_
or a ``pip`` `editable install`_ is not possible with this
library. This is because this library uses `namespace packages`_.
For context see `Issue #2316`_ and the relevant `PyPA issue`_.

Since ``editable`` / ``develop`` mode can't be used, packages
need to be installed directly. Hence your changes to the source
tree don't get incorporated into the **already installed**
package.

.. _namespace packages: https://www.python.org/dev/peps/pep-0420/
.. _Issue #2316: https://github.com/GoogleCloudPlatform/google-cloud-python/issues/2316
.. _PyPA issue: https://github.com/pypa/packaging-problems/issues/12
.. _develop mode: https://setuptools.readthedocs.io/en/latest/setuptools.html#development-mode
.. _editable install: https://pip.pypa.io/en/stable/reference/pip_install/#editable-installs

*****************************************
I'm getting weird errors... Can you help?
*****************************************
Expand Down
3 changes: 2 additions & 1 deletion docs/conf.py
Expand Up @@ -29,7 +29,7 @@
# -- General configuration ------------------------------------------------

# If your documentation needs a minimal Sphinx version, state it here.
needs_sphinx = "1.6.3"
needs_sphinx = "1.5.5"

# Add any Sphinx extension module names here, as strings. They can be
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
Expand All @@ -39,6 +39,7 @@
"sphinx.ext.autosummary",
"sphinx.ext.intersphinx",
"sphinx.ext.coverage",
"sphinx.ext.doctest",
"sphinx.ext.napoleon",
"sphinx.ext.todo",
"sphinx.ext.viewcode",
Expand Down
4 changes: 3 additions & 1 deletion noxfile.py
Expand Up @@ -176,7 +176,9 @@ def docfx(session):
"""Build the docfx yaml files for this library."""

session.install("-e", ".")
session.install("sphinx", "alabaster", "recommonmark", "sphinx-docfx-yaml")
# sphinx-docfx-yaml supports up to sphinx version 1.5.5.
# https://github.com/docascode/sphinx-docfx-yaml/issues/97
session.install("sphinx==1.5.5", "alabaster", "recommonmark", "sphinx-docfx-yaml")

shutil.rmtree(os.path.join("docs", "_build"), ignore_errors=True)
session.run(
Expand Down
15 changes: 14 additions & 1 deletion scripts/decrypt-secrets.sh
Expand Up @@ -20,14 +20,27 @@ ROOT=$( dirname "$DIR" )
# Work from the project root.
cd $ROOT

# Prevent it from overriding files.
# We recommend that sample authors use their own service account files and cloud project.
# In that case, they are supposed to prepare these files by themselves.
if [[ -f "testing/test-env.sh" ]] || \
[[ -f "testing/service-account.json" ]] || \
[[ -f "testing/client-secrets.json" ]]; then
echo "One or more target files exist, aborting."
exit 1
fi

# Use SECRET_MANAGER_PROJECT if set, fallback to cloud-devrel-kokoro-resources.
PROJECT_ID="${SECRET_MANAGER_PROJECT:-cloud-devrel-kokoro-resources}"

gcloud secrets versions access latest --secret="python-docs-samples-test-env" \
--project="${PROJECT_ID}" \
> testing/test-env.sh
gcloud secrets versions access latest \
--secret="python-docs-samples-service-account" \
--project="${PROJECT_ID}" \
> testing/service-account.json
gcloud secrets versions access latest \
--secret="python-docs-samples-client-secrets" \
> testing/client-secrets.json
--project="${PROJECT_ID}" \
> testing/client-secrets.json
5 changes: 3 additions & 2 deletions synth.metadata
Expand Up @@ -4,14 +4,14 @@
"git": {
"name": ".",
"remote": "https://github.com/googleapis/python-storage.git",
"sha": "e190f1cd8f2c454da34a79e22ddb58ff54bc1a10"
"sha": "50b43d95863a0c3ede1feeff3e09346b495a539c"
}
},
{
"git": {
"name": "synthtool",
"remote": "https://github.com/googleapis/synthtool.git",
"sha": "d91dd8aac77f7a9c5506c238038a26fa4f9e361e"
"sha": "f3c04883d6c43261ff13db1f52d03a283be06871"
}
}
],
Expand All @@ -34,6 +34,7 @@
".kokoro/docs/common.cfg",
".kokoro/docs/docs-presubmit.cfg",
".kokoro/docs/docs.cfg",
".kokoro/populate-secrets.sh",
".kokoro/presubmit/common.cfg",
".kokoro/presubmit/presubmit.cfg",
".kokoro/publish-docs.sh",
Expand Down

0 comments on commit 2f4164d

Please sign in to comment.