8000 chore(python): conditionally load credentials in .kokoro/build.sh (#594) · googleapis/python-datastore@9f83d17 · GitHub
[go: up one dir, main page]

Skip to content

Commit 9f83d17

Browse files
chore(python): conditionally load credentials in .kokoro/build.sh (#594)
Source-Link: googleapis/synthtool@aa69fb7 Post-Processor: gcr.io/cloud-devrel-public-resources/owlbot-python:latest@sha256:f016446d6e520e5fb552c45b110cba3f217bffdd3d06bdddd076e9e6d13266cf Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
1 parent 14a0f96 commit 9f83d17

File tree

7 files changed

+343
-24
lines changed

7 files changed

+343
-24
lines changed

.github/.OwlBot.lock.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,5 @@
1313
# limitations under the License.
1414
docker:
1515
image: gcr.io/cloud-devrel-public-resources/owlbot-python:latest
16-
digest: sha256:a1c5112b81d645f5bbc4d4bbc99d7dcb5089a52216c0e3fb1203a0eeabadd7d5
17-
# created: 2025-01-02T23:09:36.975468657Z
16+
digest: sha256:f016446d6e520e5fb552c45b110cba3f217bffdd3d06bdddd076e9e6d13266cf
17+
# created: 2025-02-21T19:32:52.01306189Z

.kokoro/build.sh

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,13 @@
1515

1616
set -eo pipefail
1717

18+
CURRENT_DIR=$(dirname "${BASH_SOURCE[0]}")
19+
1820
if [[ -z "${PROJECT_ROOT:-}" ]]; then
19-
PROJECT_ROOT="github/python-datastore"
21+
PROJECT_ROOT=$(realpath "${CURRENT_DIR}/..")
2022
fi
2123

22-
cd "${PROJECT_ROOT}"
24+
pushd "${PROJECT_ROOT}"
2325

2426
# Disable buffering, so that the logs stream through.
2527
export PYTHONUNBUFFERED=1
@@ -28,10 +30,16 @@ export PYTHONUNBUFFERED=1
2830
env | grep KOKORO
2931

3032
# Setup service account credentials.
31-
export GOOGLE_APPLICATION_CREDENTIALS=${KOKORO_GFILE_DIR}/service-account.json
33+
if [[ -f "${KOKORO_GFILE_DIR}/service-account.json" ]]
34+
then
35+
export GOOGLE_APPLICATION_CREDENTIALS=${KOKORO_GFILE_DIR}/service-account.json
36+
fi
3237

3338
# Setup project id.
34-
export PROJECT_ID=$(cat "${KOKORO_GFILE_DIR}/project-id.json")
39+
if [[ -f "${KOKORO_GFILE_DIR}/project-id.json" ]]
40+
then
41+
export PROJECT_ID=$(cat "${KOKORO_GFILE_DIR}/project-id.json")
42+
fi
3543

3644
# If this is a continuous build, send the test log to the FlakyBot.
3745
# See https://github.com/googleapis/repo-automation-bots/tree/main/packages/flakybot.
@@ -46,7 +54,7 @@ fi
4654
# If NOX_SESSION is set, it only runs the specified session,
4755
# otherwise run all the sessions.
4856
if [[ -n "${NOX_SESSION:-}" ]]; then
49-
python3 -m nox -s ${NOX_SESSION:-}
57+
python3 -m nox -s ${NOX_SESSION:-}
5058
else
51-
python3 -m nox
59+
python3 -m nox
5260
fi

.kokoro/docker/docs/requirements.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
nox
2+
gcp-docuploader

.kokoro/docker/docs/requirements.txt

Lines changed: 234 additions & 9 deletions
Large diffs are not rendered by default.

.kokoro/publish-docs.sh

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,6 @@ export PYTHONUNBUFFERED=1
2020

2121
export PATH="${HOME}/.local/bin:${PATH}"
2222

23-
# Install nox
24-
python3.10 -m pip install --require-hashes -r .kokoro/requirements.txt
25-
python3.10 -m nox --version
26-
2723
# build docs
2824
nox -s docs
2925

README.rst

Lines changed: 91 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,12 @@ In order to use this library, you first need to go through the following steps:
3030
1. `Select or create a Cloud Platform project.`_
3131
2. `Enable billing for your project.`_
3232
3. `Enable the Google Cloud Datastore API.`_
33-
4. `Setup Authentication.`_
33+
4. `Set up Authentication.`_
3434

3535
.. _Select or create a Cloud Platform project.: https://console.cloud.google.com/project
3636
.. _Enable billing for your project.: https://cloud.google.com/billing/docs/how-to/modify-project#enable_billing_for_a_project
3737
.. _Enable the Google Cloud Datastore API.: https://cloud.google.com/datastore
38-
.. _Setup Authentication.: https://googleapis.dev/python/google-api-core/latest/auth.html
38+
.. _Set up Authentication.: https://googleapis.dev/python/google-api-core/latest/auth.html
3939

4040
Installation
4141
~~~~~~~~~~~~
@@ -110,3 +110,92 @@ Next Steps
110110

111111
.. _Google Cloud Datastore API Product documentation: https://cloud.google.com/datastore
112112
.. _README: https://github.com/googleapis/google-cloud-python/blob/main/README.rst
113+
114+
Logging
115+
-------
116+
117+
This library uses the standard Python :code:`logging` functionality to log some RPC events that could be of interest for debugging and monitoring purposes.
118+
Note the following:
119+
120+
#. Logs may contain sensitive information. Take care to **restrict access to the logs** if they are saved, whether it be on local storage or on Google Cloud Logging.
121+
#. Google may refine the occurrence, level, and content of various log messages in this library without flagging such changes as breaking. **Do not depend on immutability of the logging events**.
122+
#. By default, the logging events from this library are not handled. You must **explicitly configure log handling** using one of the mechanisms below.
123+
124+
Simple, environment-based configuration
125+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
126+
127+
To enable logging for this library without any changes in your code, set the :code:`GOOGLE_SDK_PYTHON_LOGGING_SCOPE` environment variable to a valid Google
128+
logging scope. This configures handling of logging events (at level :code:`logging.DEBUG` or higher) from this library in a default manner, emitting the logged
129+
messages in a structured format. It does not currently allow customizing the logging levels captured nor the handlers, formatters, etc. used for any logging
130+
event.
131+
132+
A logging scope is a period-separated namespace that begins with :code:`google`, identifying the Python module or package to log.
133+
134+
- Valid logging scopes: :code:`google`, :code:`google.cloud.asset.v1`, :code:`google.api`, :code:`google.auth`, etc.
135+
- Invalid logging scopes: :code:`foo`, :code:`123`, etc.
136+
137+
**NOTE**: If the logging scope is invalid, the library does not set up any logging handlers.
138+
139+
Environment-Based Examples
140+
^^^^^^^^^^^^^^^^^^^^^^^^^^
141+
142+
- Enabling the default handler for all Google-based loggers
143+
144+
.. code-block:: console
145+
146+
export GOOGLE_SDK_PYTHON_LOGGING_SCOPE=google
147+
148+
- Enabling the default handler for a specific Google module (for a client library called :code:`library_v1`):
149+
150+
.. code-block:: console
151+
152+
export GOOGLE_SDK_PYTHON_LOGGING_SCOPE=google.cloud.library_v1
153+
154+
155+
Advanced, code-based configuration
156+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
157+
158+
You can also configure a valid logging scope using Python's standard `logging` mechanism.
159+
160+
Code-Based Examples
161+
^^^^^^^^^^^^^^^^^^^
162+
163+
- Configuring a handler for all Google-based loggers
164+
165+
.. code-block:: python
166+
167+
import logging
168+
169+
from google.cloud.translate_v3 import translate
170+
171+
base_logger = logging.getLogger("google")
172+
base_logger.addHandler(logging.StreamHandler())
173+
base_logger.setLevel(logging.DEBUG)
174+
175+
- Configuring a handler for a specific Google module (for a client library called :code:`library_v1`):
176+
177+
.. code-block:: python
178+
179+
import logging
180+
181+
from google.cloud.translate_v3 import translate
182+
183+
base_logger = logging.getLogger("google.cloud.library_v1")
184+
base_logger.addHandler(logging.StreamHandler())
185+
base_logger.setLevel(logging.DEBUG)
186+
187+
Logging details
188+
~~~~~~~~~~~~~~~
189+
190+
#. Regardless of which of the mechanisms above you use to configure logging for this library, by default logging events are not propagated up to the root
191+
logger from the `google`-level logger. If you need the events to be propagated to the root logger, you must explicitly set
192+
:code:`logging.getLogger("google").propagate = True` in your code.
193+
#. You can mix the different logging configurations above for different Google modules. For example, you may want use a code-based logging configuration for
194+
one library, but decide you need to also set up environment-based logging configuration for another library.
195+
196+
#. If you attempt to use both code-based and environment-based configuration for the same module, the environment-based configuration will be ineffectual
197+
if the code -based configuration gets applied first.
198+
199+
#. The Google-specific logging configurations (default handlers for environment-based configuration; not propagating logging events to the root logger) get
200+
executed the first time *any* client library is instantiated in your application, and only if the affected loggers have not been previously configured.
201+
(This is the reason for 2.i. above.)

renovate.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
":preserveSemverRanges",
66
":disableDependencyDashboard"
77
],
8-
"ignorePaths": [".pre-commit-config.yaml", ".kokoro/requirements.txt", "setup.py"],
8+
"ignorePaths": [".pre-commit-config.yaml", ".kokoro/requirements.txt", "setup.py", ".github/workflows/unittest.yml"],
99
"pip_requirements": {
1010
"fileMatch": ["requirements-test.txt", "samples/[\\S/]*constraints.txt", "samples/[\\S/]*constraints-test.txt"]
1111
}

0 commit comments

Comments
 (0)
0