From 5d21b4db9cdc23aa65511178a0fc40771725cd4d Mon Sep 17 00:00:00 2001 From: Bill Prin Date: Thu, 21 Apr 2016 12:52:31 -0700 Subject: [PATCH 01/51] Add Error Reporting Code --- samples/snippets/README.md | 27 ++++++++++++++++++++ samples/snippets/main.py | 41 ++++++++++++++++++++++++++++++ samples/snippets/requirements.txt | 1 + samples/snippets/startup_script.sh | 35 +++++++++++++++++++++++++ samples/snippets/test_main.py | 22 ++++++++++++++++ 5 files changed, 126 insertions(+) create mode 100644 samples/snippets/README.md create mode 100644 samples/snippets/main.py create mode 100644 samples/snippets/requirements.txt create mode 100644 samples/snippets/startup_script.sh create mode 100644 samples/snippets/test_main.py diff --git a/samples/snippets/README.md b/samples/snippets/README.md new file mode 100644 index 00000000..e88c1445 --- /dev/null +++ b/samples/snippets/README.md @@ -0,0 +1,27 @@ +# Google Error Reorting Samples Samples + +This section contains samples for [Google Cloud Error Reporting](https://cloud.google.com/error-reporting). + +A startup script has been provided to demonstrated how to properly provision a GCE +instance with fluentd configured. Note the intallation of fluentd, the addition of the config file, + and the restarting of the fluetnd service. You can start an instance using +it like this: + + gcloud compute instances create example-instance --metadata-from-file startup-script=startup_script.sh + +or simply use it as reference when creating your own instance. + +After fluentd is configured, main.py could be used to simulate an error: + + gcloud compute copy-files main.py example-instance:~/main.py + +Then, + + gcloud compute ssh example-instance + python ~/main.py + +And you will see the message in the Errors Console. + + + + diff --git a/samples/snippets/main.py b/samples/snippets/main.py new file mode 100644 index 00000000..8ed8d5e9 --- /dev/null +++ b/samples/snippets/main.py @@ -0,0 +1,41 @@ +# Copyright 2016 Google Inc. All rights reserved. +# +# 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. + +# [START error_reporting] +import traceback + +import fluent.event +import fluent.sender + + +def simulate_error(): + fluent.sender.setup('myapp', host='localhost', port=24224) + + def report(ex): + data = {} + data['message'] = '{0}'.format(ex) + data['serviceContext'] = {'service': 'myapp'} + # ... add more metadata + fluent.event.Event('errors', data) + + # report exception data using: + try: + # simulate calling a method that's not defined + raise NameError + except Exception: + report(traceback.format_exc()) +# [END error_reporting] + +if __name__ == '__main__': + simulate_error() diff --git a/samples/snippets/requirements.txt b/samples/snippets/requirements.txt new file mode 100644 index 00000000..04d09eef --- /dev/null +++ b/samples/snippets/requirements.txt @@ -0,0 +1 @@ +fluent-logger==0.4.1 diff --git a/samples/snippets/startup_script.sh b/samples/snippets/startup_script.sh new file mode 100644 index 00000000..f2ef895d --- /dev/null +++ b/samples/snippets/startup_script.sh @@ -0,0 +1,35 @@ +#!/usr/bin/env bash +# Copyright 2016 Google Inc. All rights reserved. +# +# 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 -v + +curl -sSO "https://dl.google.com/cloudagents/install-logging-agent.sh" +chmod +x install-logging-agent.sh +./install-logging-agent.sh +mkdir -p /etc/google-fluentd/config.d/ +cat < /etc/google-fluentd/config.d/forward.conf + + type forward + port 24224 + +EOF +service google-fluentd restart + +apt-get update +apt-get install -yq \ + git build-essential supervisor python python-dev python-pip libffi-dev \ + libssl-dev +pip install fluent-logger + diff --git a/samples/snippets/test_main.py b/samples/snippets/test_main.py new file mode 100644 index 00000000..15064742 --- /dev/null +++ b/samples/snippets/test_main.py @@ -0,0 +1,22 @@ +# Copyright 2016 Google Inc. All rights reserved. +# +# 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. + +import main +import mock + + +@mock.patch("fluent.event") +def test_error_sends(event_mock): + main.simulate_error() + event_mock.Event.assert_called_once_with(mock.ANY, mock.ANY) From 70fe5293d0942587967bde49c72251e3d5658950 Mon Sep 17 00:00:00 2001 From: Jon Wayne Parrott Date: Wed, 4 May 2016 13:00:18 -0700 Subject: [PATCH 02/51] Updating doc links [(#324)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/324) --- samples/snippets/README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/samples/snippets/README.md b/samples/snippets/README.md index e88c1445..4c9a24c6 100644 --- a/samples/snippets/README.md +++ b/samples/snippets/README.md @@ -23,5 +23,8 @@ Then, And you will see the message in the Errors Console. +These samples are used on the following documentation page: + +> https://cloud.google.com/error-reporting/docs/setting-up-on-compute-engine From 3e9f7ef4ba4c9945e54dcce18b46c442ef096d86 Mon Sep 17 00:00:00 2001 From: Jon Wayne Parrott Date: Fri, 15 Jul 2016 12:50:42 -0700 Subject: [PATCH 03/51] Commenting noxfile, renaming a test file. Change-Id: Ice25caa7c035c24a585a66575dda69e170862df8 --- samples/snippets/{test_main.py => main_test.py} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename samples/snippets/{test_main.py => main_test.py} (100%) diff --git a/samples/snippets/test_main.py b/samples/snippets/main_test.py similarity index 100% rename from samples/snippets/test_main.py rename to samples/snippets/main_test.py From 22db3f1e1168653194be89ed3bebe1134f3e333f Mon Sep 17 00:00:00 2001 From: Jon Wayne Parrott Date: Wed, 3 Aug 2016 11:08:27 -0700 Subject: [PATCH 04/51] Update requirements. [(#436)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/436) --- samples/snippets/requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samples/snippets/requirements.txt b/samples/snippets/requirements.txt index 04d09eef..f9fde1f0 100644 --- a/samples/snippets/requirements.txt +++ b/samples/snippets/requirements.txt @@ -1 +1 @@ -fluent-logger==0.4.1 +fluent-logger==0.4.3 From 830d8a203a4e9d11025831b552be3bbbc98fd772 Mon Sep 17 00:00:00 2001 From: Jon Wayne Parrott Date: Fri, 19 Aug 2016 13:56:28 -0700 Subject: [PATCH 05/51] Fix import order lint errors Change-Id: Ieaf7237fc6f925daec46a07d2e81a452b841198a --- samples/snippets/main_test.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/samples/snippets/main_test.py b/samples/snippets/main_test.py index 15064742..11a24d03 100644 --- a/samples/snippets/main_test.py +++ b/samples/snippets/main_test.py @@ -12,9 +12,10 @@ # See the License for the specific language governing permissions and # limitations under the License. -import main import mock +import main + @mock.patch("fluent.event") def test_error_sends(event_mock): From 94862cec4be7a21a530d066bc4eb9e3cf743060d Mon Sep 17 00:00:00 2001 From: Jon Wayne Parrott Date: Fri, 19 Aug 2016 14:13:21 -0700 Subject: [PATCH 06/51] bump Change-Id: I02e7767d13ba267ee9fc72c5b68a57013bb8b8d3 From 287db399dd2a98af34d8c1e205f52826ae8f3bd5 Mon Sep 17 00:00:00 2001 From: DPE bot Date: Tue, 20 Sep 2016 12:26:02 -0700 Subject: [PATCH 07/51] Auto-update dependencies. [(#537)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/537) --- samples/snippets/requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samples/snippets/requirements.txt b/samples/snippets/requirements.txt index f9fde1f0..0119e25c 100644 --- a/samples/snippets/requirements.txt +++ b/samples/snippets/requirements.txt @@ -1 +1 @@ -fluent-logger==0.4.3 +fluent-logger==0.4.4 From af085d96fefda80a72e6a288109f538c449f8ec5 Mon Sep 17 00:00:00 2001 From: Jon Wayne Parrott Date: Tue, 15 Nov 2016 14:58:27 -0800 Subject: [PATCH 08/51] Update samples to support latest Google Cloud Python [(#656)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/656) --- samples/snippets/main.py | 1 + 1 file changed, 1 insertion(+) diff --git a/samples/snippets/main.py b/samples/snippets/main.py index 8ed8d5e9..45208c91 100644 --- a/samples/snippets/main.py +++ b/samples/snippets/main.py @@ -37,5 +37,6 @@ def report(ex): report(traceback.format_exc()) # [END error_reporting] + if __name__ == '__main__': simulate_error() From 36c51b128546ac59b0fbde23050b28e72644ccf5 Mon Sep 17 00:00:00 2001 From: Bill Prin Date: Thu, 17 Nov 2016 13:41:30 -0800 Subject: [PATCH 09/51] Switch Error Reporting to Google Cloud Python [(#663)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/663) * Switch Error Reporting to Google Cloud Python * Switch Error Reporting to Google Cloud Python --- samples/snippets/README.md | 30 ----- samples/snippets/README.rst | 103 ++++++++++++++++++ samples/snippets/README.rst.in | 19 ++++ .../snippets/{main.py => report_exception.py} | 18 +-- ...{main_test.py => report_exception_test.py} | 10 +- samples/snippets/requirements.txt | 2 +- samples/snippets/startup_script.sh | 35 ------ 7 files changed, 129 insertions(+), 88 deletions(-) delete mode 100644 samples/snippets/README.md create mode 100644 samples/snippets/README.rst create mode 100644 samples/snippets/README.rst.in rename samples/snippets/{main.py => report_exception.py} (67%) rename samples/snippets/{main_test.py => report_exception_test.py} (77%) delete mode 100644 samples/snippets/startup_script.sh diff --git a/samples/snippets/README.md b/samples/snippets/README.md deleted file mode 100644 index 4c9a24c6..00000000 --- a/samples/snippets/README.md +++ /dev/null @@ -1,30 +0,0 @@ -# Google Error Reorting Samples Samples - -This section contains samples for [Google Cloud Error Reporting](https://cloud.google.com/error-reporting). - -A startup script has been provided to demonstrated how to properly provision a GCE -instance with fluentd configured. Note the intallation of fluentd, the addition of the config file, - and the restarting of the fluetnd service. You can start an instance using -it like this: - - gcloud compute instances create example-instance --metadata-from-file startup-script=startup_script.sh - -or simply use it as reference when creating your own instance. - -After fluentd is configured, main.py could be used to simulate an error: - - gcloud compute copy-files main.py example-instance:~/main.py - -Then, - - gcloud compute ssh example-instance - python ~/main.py - -And you will see the message in the Errors Console. - - -These samples are used on the following documentation page: - -> https://cloud.google.com/error-reporting/docs/setting-up-on-compute-engine - - diff --git a/samples/snippets/README.rst b/samples/snippets/README.rst new file mode 100644 index 00000000..42f401a4 --- /dev/null +++ b/samples/snippets/README.rst @@ -0,0 +1,103 @@ +.. This file is automatically generated. Do not edit this file directly. + +Stackdriver Error Reporting Python Samples +=============================================================================== + +This directory contains samples for Stackdriver Error Reporting. `Stackdriver Error Reporting`_ aggregates and displays errors produced in + your running cloud services. + + + + +.. _Stackdriver Error Reporting: https://cloud.google.com/error-reporting/docs/ + +Setup +------------------------------------------------------------------------------- + + +Authentication +++++++++++++++ + +Authentication is typically done through `Application Default Credentials`_, +which means you do not have to change the code to authenticate as long as +your environment has credentials. You have a few options for setting up +authentication: + +#. When running locally, use the `Google Cloud SDK`_ + + .. code-block:: bash + + gcloud beta auth application-default login + + +#. When running on App Engine or Compute Engine, credentials are already + set-up. However, you may need to configure your Compute Engine instance + with `additional scopes`_. + +#. You can create a `Service Account key file`_. This file can be used to + authenticate to Google Cloud Platform services from any environment. To use + the file, set the ``GOOGLE_APPLICATION_CREDENTIALS`` environment variable to + the path to the key file, for example: + + .. code-block:: bash + + export GOOGLE_APPLICATION_CREDENTIALS=/path/to/service_account.json + +.. _Application Default Credentials: https://cloud.google.com/docs/authentication#getting_credentials_for_server-centric_flow +.. _additional scopes: https://cloud.google.com/compute/docs/authentication#using +.. _Service Account key file: https://developers.google.com/identity/protocols/OAuth2ServiceAccount#creatinganaccount + +Install Dependencies +++++++++++++++++++++ + +#. Install `pip`_ and `virtualenv`_ if you do not already have them. + +#. Create a virtualenv. Samples are compatible with Python 2.7 and 3.4+. + + .. code-block:: bash + + $ virtualenv env + $ source env/bin/activate + +#. Install the dependencies needed to run the samples. + + .. code-block:: bash + + $ pip install -r requirements.txt + +.. _pip: https://pip.pypa.io/ +.. _virtualenv: https://virtualenv.pypa.io/ + +Samples +------------------------------------------------------------------------------- + +Report Exception ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + + + +To run this sample: + +.. code-block:: bash + + $ python report_exception.py + + + + +The client library +------------------------------------------------------------------------------- + +This sample uses the `Google Cloud Client Library for Python`_. +You can read the documentation for more details on API usage and use GitHub +to `browse the source`_ and `report issues`_. + +.. Google Cloud Client Library for Python: + https://googlecloudplatform.github.io/google-cloud-python/ +.. browse the source: + https://github.com/GoogleCloudPlatform/google-cloud-python +.. report issues: + https://github.com/GoogleCloudPlatform/google-cloud-python/issues + + +.. _Google Cloud SDK: https://cloud.google.com/sdk/ \ No newline at end of file diff --git a/samples/snippets/README.rst.in b/samples/snippets/README.rst.in new file mode 100644 index 00000000..4eeab4bb --- /dev/null +++ b/samples/snippets/README.rst.in @@ -0,0 +1,19 @@ +# This file is used to generate README.rst + +product: + name: Stackdriver Error Reporting + short_name: Error Reporting + url: https://cloud.google.com/error-reporting/docs/ + description: > + `Stackdriver Error Reporting`_ aggregates and displays errors produced in + your running cloud services. + +setup: +- auth +- install_deps + +samples: +- name: Report Exception + file: report_exception.py + +cloud_client_library: true diff --git a/samples/snippets/main.py b/samples/snippets/report_exception.py similarity index 67% rename from samples/snippets/main.py rename to samples/snippets/report_exception.py index 45208c91..40b7ba36 100644 --- a/samples/snippets/main.py +++ b/samples/snippets/report_exception.py @@ -13,28 +13,16 @@ # limitations under the License. # [START error_reporting] -import traceback - -import fluent.event -import fluent.sender +from google.cloud import error_reporting def simulate_error(): - fluent.sender.setup('myapp', host='localhost', port=24224) - - def report(ex): - data = {} - data['message'] = '{0}'.format(ex) - data['serviceContext'] = {'service': 'myapp'} - # ... add more metadata - fluent.event.Event('errors', data) - - # report exception data using: + client = error_reporting.Client() try: # simulate calling a method that's not defined raise NameError except Exception: - report(traceback.format_exc()) + client.report_exception() # [END error_reporting] diff --git a/samples/snippets/main_test.py b/samples/snippets/report_exception_test.py similarity index 77% rename from samples/snippets/main_test.py rename to samples/snippets/report_exception_test.py index 11a24d03..1ec03d1e 100644 --- a/samples/snippets/main_test.py +++ b/samples/snippets/report_exception_test.py @@ -12,12 +12,8 @@ # See the License for the specific language governing permissions and # limitations under the License. -import mock +import report_exception -import main - -@mock.patch("fluent.event") -def test_error_sends(event_mock): - main.simulate_error() - event_mock.Event.assert_called_once_with(mock.ANY, mock.ANY) +def test_error_sends(): + report_exception.simulate_error() diff --git a/samples/snippets/requirements.txt b/samples/snippets/requirements.txt index 0119e25c..0bb3f8d5 100644 --- a/samples/snippets/requirements.txt +++ b/samples/snippets/requirements.txt @@ -1 +1 @@ -fluent-logger==0.4.4 +google-cloud-error-reporting==0.21.0 diff --git a/samples/snippets/startup_script.sh b/samples/snippets/startup_script.sh deleted file mode 100644 index f2ef895d..00000000 --- a/samples/snippets/startup_script.sh +++ /dev/null @@ -1,35 +0,0 @@ -#!/usr/bin/env bash -# Copyright 2016 Google Inc. All rights reserved. -# -# 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 -v - -curl -sSO "https://dl.google.com/cloudagents/install-logging-agent.sh" -chmod +x install-logging-agent.sh -./install-logging-agent.sh -mkdir -p /etc/google-fluentd/config.d/ -cat < /etc/google-fluentd/config.d/forward.conf - - type forward - port 24224 - -EOF -service google-fluentd restart - -apt-get update -apt-get install -yq \ - git build-essential supervisor python python-dev python-pip libffi-dev \ - libssl-dev -pip install fluent-logger - From d0e673dec79e8261af295da93fed3e2b06e357c4 Mon Sep 17 00:00:00 2001 From: DPE bot Date: Tue, 13 Dec 2016 09:54:02 -0800 Subject: [PATCH 10/51] Auto-update dependencies. [(#715)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/715) --- samples/snippets/requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samples/snippets/requirements.txt b/samples/snippets/requirements.txt index 0bb3f8d5..f9e86ea8 100644 --- a/samples/snippets/requirements.txt +++ b/samples/snippets/requirements.txt @@ -1 +1 @@ -google-cloud-error-reporting==0.21.0 +google-cloud-error-reporting==0.22.0 From f7a906009e893baed972eafd8d52a89fcb1e923b Mon Sep 17 00:00:00 2001 From: DPE bot Date: Mon, 24 Apr 2017 13:12:09 -0700 Subject: [PATCH 11/51] Auto-update dependencies. [(#914)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/914) * Auto-update dependencies. * xfail the error reporting test * Fix lint --- samples/snippets/report_exception_test.py | 5 +++++ samples/snippets/requirements.txt | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/samples/snippets/report_exception_test.py b/samples/snippets/report_exception_test.py index 1ec03d1e..fa51b03c 100644 --- a/samples/snippets/report_exception_test.py +++ b/samples/snippets/report_exception_test.py @@ -12,8 +12,13 @@ # See the License for the specific language governing permissions and # limitations under the License. +import pytest + import report_exception +@pytest.mark.xfail( + strict=True, + reason='GoogleCloudPlatform/google-cloud-python#3263') def test_error_sends(): report_exception.simulate_error() diff --git a/samples/snippets/requirements.txt b/samples/snippets/requirements.txt index f9e86ea8..27ed0c07 100644 --- a/samples/snippets/requirements.txt +++ b/samples/snippets/requirements.txt @@ -1 +1 @@ -google-cloud-error-reporting==0.22.0 +google-cloud-error-reporting==0.24.1 From 529716dd08cba38a17391183281aacf86ceac571 Mon Sep 17 00:00:00 2001 From: Jon Wayne Parrott Date: Thu, 27 Apr 2017 09:54:41 -0700 Subject: [PATCH 12/51] Re-generate all readmes --- samples/snippets/README.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samples/snippets/README.rst b/samples/snippets/README.rst index 42f401a4..be94d09c 100644 --- a/samples/snippets/README.rst +++ b/samples/snippets/README.rst @@ -27,7 +27,7 @@ authentication: .. code-block:: bash - gcloud beta auth application-default login + gcloud auth application-default login #. When running on App Engine or Compute Engine, credentials are already From ba620753ee3c28cc03d65e0a8a5a707b5eb7b6f3 Mon Sep 17 00:00:00 2001 From: DPE bot Date: Mon, 1 May 2017 10:49:29 -0700 Subject: [PATCH 13/51] Auto-update dependencies. [(#922)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/922) * Auto-update dependencies. * Fix pubsub iam samples --- samples/snippets/requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samples/snippets/requirements.txt b/samples/snippets/requirements.txt index 27ed0c07..55f72cfa 100644 --- a/samples/snippets/requirements.txt +++ b/samples/snippets/requirements.txt @@ -1 +1 @@ -google-cloud-error-reporting==0.24.1 +google-cloud-error-reporting==0.24.2 From 6a57c0d4f631b3c0e8f319c8d731cb68bc7b98d3 Mon Sep 17 00:00:00 2001 From: Bill Prin Date: Tue, 23 May 2017 17:01:25 -0700 Subject: [PATCH 14/51] Fix README rst links [(#962)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/962) * Fix README rst links * Update all READMEs --- samples/snippets/README.rst | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/samples/snippets/README.rst b/samples/snippets/README.rst index be94d09c..96705705 100644 --- a/samples/snippets/README.rst +++ b/samples/snippets/README.rst @@ -92,11 +92,11 @@ This sample uses the `Google Cloud Client Library for Python`_. You can read the documentation for more details on API usage and use GitHub to `browse the source`_ and `report issues`_. -.. Google Cloud Client Library for Python: +.. _Google Cloud Client Library for Python: https://googlecloudplatform.github.io/google-cloud-python/ -.. browse the source: +.. _browse the source: https://github.com/GoogleCloudPlatform/google-cloud-python -.. report issues: +.. _report issues: https://github.com/GoogleCloudPlatform/google-cloud-python/issues From f6d676e3923c73efde31e5c56ed08a58f7294916 Mon Sep 17 00:00:00 2001 From: DPE bot Date: Tue, 27 Jun 2017 12:41:15 -0700 Subject: [PATCH 15/51] Auto-update dependencies. [(#1004)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/1004) * Auto-update dependencies. * Fix natural language samples * Fix pubsub iam samples * Fix language samples * Fix bigquery samples --- samples/snippets/requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samples/snippets/requirements.txt b/samples/snippets/requirements.txt index 55f72cfa..e1c3061c 100644 --- a/samples/snippets/requirements.txt +++ b/samples/snippets/requirements.txt @@ -1 +1 @@ -google-cloud-error-reporting==0.24.2 +google-cloud-error-reporting==0.25.0 From 671e2e1a206651a45da5d5d34255740bfd978b11 Mon Sep 17 00:00:00 2001 From: DPE bot Date: Thu, 13 Jul 2017 09:12:37 -0700 Subject: [PATCH 16/51] Auto-update dependencies. [(#1011)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/1011) --- samples/snippets/requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samples/snippets/requirements.txt b/samples/snippets/requirements.txt index e1c3061c..735d7852 100644 --- a/samples/snippets/requirements.txt +++ b/samples/snippets/requirements.txt @@ -1 +1 @@ -google-cloud-error-reporting==0.25.0 +google-cloud-error-reporting==0.25.1 From f92e1fabae53270f64c726e0f662df235a45af27 Mon Sep 17 00:00:00 2001 From: DPE bot Date: Mon, 7 Aug 2017 10:04:55 -0700 Subject: [PATCH 17/51] Auto-update dependencies. [(#1055)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/1055) * Auto-update dependencies. * Explicitly use latest bigtable client Change-Id: Id71e9e768f020730e4ca9514a0d7ebaa794e7d9e * Revert language update for now Change-Id: I8867f154e9a5aae00d0047c9caf880e5e8f50c53 * Remove pdb. smh Change-Id: I5ff905fadc026eebbcd45512d4e76e003e3b2b43 --- samples/snippets/requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samples/snippets/requirements.txt b/samples/snippets/requirements.txt index 735d7852..2f62dcf4 100644 --- a/samples/snippets/requirements.txt +++ b/samples/snippets/requirements.txt @@ -1 +1 @@ -google-cloud-error-reporting==0.25.1 +google-cloud-error-reporting==0.26.0 From 1669f652bc89537d140195b95df86c2f1b3241fb Mon Sep 17 00:00:00 2001 From: DPE bot Date: Tue, 29 Aug 2017 16:53:02 -0700 Subject: [PATCH 18/51] Auto-update dependencies. [(#1093)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/1093) * Auto-update dependencies. * Fix storage notification poll sample Change-Id: I6afbc79d15e050531555e4c8e51066996717a0f3 * Fix spanner samples Change-Id: I40069222c60d57e8f3d3878167591af9130895cb * Drop coverage because it's not useful Change-Id: Iae399a7083d7866c3c7b9162d0de244fbff8b522 * Try again to fix flaky logging test Change-Id: I6225c074701970c17c426677ef1935bb6d7e36b4 --- samples/snippets/requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samples/snippets/requirements.txt b/samples/snippets/requirements.txt index 2f62dcf4..71fd34fc 100644 --- a/samples/snippets/requirements.txt +++ b/samples/snippets/requirements.txt @@ -1 +1 @@ -google-cloud-error-reporting==0.26.0 +google-cloud-error-reporting==0.27.0 From 42fdecade2237a98ff8a6b5fb995db30fb376750 Mon Sep 17 00:00:00 2001 From: Jon Wayne Parrott Date: Mon, 18 Sep 2017 11:04:05 -0700 Subject: [PATCH 19/51] Update all generated readme auth instructions [(#1121)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/1121) Change-Id: I03b5eaef8b17ac3dc3c0339fd2c7447bd3e11bd2 --- samples/snippets/README.rst | 32 +++++--------------------------- 1 file changed, 5 insertions(+), 27 deletions(-) diff --git a/samples/snippets/README.rst b/samples/snippets/README.rst index 96705705..141124d7 100644 --- a/samples/snippets/README.rst +++ b/samples/snippets/README.rst @@ -18,34 +18,12 @@ Setup Authentication ++++++++++++++ -Authentication is typically done through `Application Default Credentials`_, -which means you do not have to change the code to authenticate as long as -your environment has credentials. You have a few options for setting up -authentication: +This sample requires you to have authentication setup. Refer to the +`Authentication Getting Started Guide`_ for instructions on setting up +credentials for applications. -#. When running locally, use the `Google Cloud SDK`_ - - .. code-block:: bash - - gcloud auth application-default login - - -#. When running on App Engine or Compute Engine, credentials are already - set-up. However, you may need to configure your Compute Engine instance - with `additional scopes`_. - -#. You can create a `Service Account key file`_. This file can be used to - authenticate to Google Cloud Platform services from any environment. To use - the file, set the ``GOOGLE_APPLICATION_CREDENTIALS`` environment variable to - the path to the key file, for example: - - .. code-block:: bash - - export GOOGLE_APPLICATION_CREDENTIALS=/path/to/service_account.json - -.. _Application Default Credentials: https://cloud.google.com/docs/authentication#getting_credentials_for_server-centric_flow -.. _additional scopes: https://cloud.google.com/compute/docs/authentication#using -.. _Service Account key file: https://developers.google.com/identity/protocols/OAuth2ServiceAccount#creatinganaccount +.. _Authentication Getting Started Guide: + https://cloud.google.com/docs/authentication/getting-started Install Dependencies ++++++++++++++++++++ From a73c2cdc19d0e8ad34a05d98ee056ed538f176ec Mon Sep 17 00:00:00 2001 From: michaelawyu Date: Thu, 12 Oct 2017 10:16:11 -0700 Subject: [PATCH 20/51] Added Link to Python Setup Guide [(#1158)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/1158) * Update Readme.rst to add Python setup guide As requested in b/64770713. This sample is linked in documentation https://cloud.google.com/bigtable/docs/scaling, and it would make more sense to update the guide here than in the documentation. * Update README.rst * Update README.rst * Update README.rst * Update README.rst * Update README.rst * Update install_deps.tmpl.rst * Updated readmegen scripts and re-generated related README files * Fixed the lint error --- samples/snippets/README.rst | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/samples/snippets/README.rst b/samples/snippets/README.rst index 141124d7..5f662b8f 100644 --- a/samples/snippets/README.rst +++ b/samples/snippets/README.rst @@ -28,7 +28,10 @@ credentials for applications. Install Dependencies ++++++++++++++++++++ -#. Install `pip`_ and `virtualenv`_ if you do not already have them. +#. Install `pip`_ and `virtualenv`_ if you do not already have them. You may want to refer to the `Python Development Environment Setup Guide`_ for Google Cloud Platform for instructions. + + .. _Python Development Environment Setup Guide: + https://cloud.google.com/python/setup #. Create a virtualenv. Samples are compatible with Python 2.7 and 3.4+. From 98896943aee992bf630a607ec84777ff29f3f50d Mon Sep 17 00:00:00 2001 From: DPE bot Date: Wed, 1 Nov 2017 12:30:10 -0700 Subject: [PATCH 21/51] Auto-update dependencies. [(#1186)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/1186) --- samples/snippets/requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samples/snippets/requirements.txt b/samples/snippets/requirements.txt index 71fd34fc..d2f22014 100644 --- a/samples/snippets/requirements.txt +++ b/samples/snippets/requirements.txt @@ -1 +1 @@ -google-cloud-error-reporting==0.27.0 +google-cloud-error-reporting==0.28.0 From 677bb94f3d4c6eaca2db6e9da7e6da2f752725f2 Mon Sep 17 00:00:00 2001 From: Andrew Gorcester Date: Fri, 3 Nov 2017 16:45:54 -0700 Subject: [PATCH 22/51] Add error reporting sample for manual reporting --- samples/snippets/report_exception.py | 16 +++++++++++++--- samples/snippets/report_exception_test.py | 9 ++++----- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/samples/snippets/report_exception.py b/samples/snippets/report_exception.py index 40b7ba36..31ef99b0 100644 --- a/samples/snippets/report_exception.py +++ b/samples/snippets/report_exception.py @@ -12,11 +12,11 @@ # See the License for the specific language governing permissions and # limitations under the License. -# [START error_reporting] -from google.cloud import error_reporting - +# [START error_reporting] def simulate_error(): + from google.cloud import error_reporting + client = error_reporting.Client() try: # simulate calling a method that's not defined @@ -26,5 +26,15 @@ def simulate_error(): # [END error_reporting] +# [START error_reporting_manual] +def report_manual_error(): + from google.cloud import error_reporting + + client = error_reporting.Client() + client.report("An error has occurred.") +# [END error_reporting_manual] + + if __name__ == '__main__': simulate_error() + report_manual_error() diff --git a/samples/snippets/report_exception_test.py b/samples/snippets/report_exception_test.py index fa51b03c..042951e9 100644 --- a/samples/snippets/report_exception_test.py +++ b/samples/snippets/report_exception_test.py @@ -12,13 +12,12 @@ # See the License for the specific language governing permissions and # limitations under the License. -import pytest - import report_exception -@pytest.mark.xfail( - strict=True, - reason='GoogleCloudPlatform/google-cloud-python#3263') def test_error_sends(): report_exception.simulate_error() + + +def test_manual_error_sends(): + report_exception.report_manual_error() From 06e86234b00c1c153ffeaddd943bb11a3ab58472 Mon Sep 17 00:00:00 2001 From: Andrew Gorcester Date: Fri, 3 Nov 2017 17:26:23 -0700 Subject: [PATCH 23/51] Readd fluentd samples --- samples/snippets/{ => api}/README.rst | 0 samples/snippets/{ => api}/README.rst.in | 0 .../snippets/{ => api}/report_exception.py | 0 .../{ => api}/report_exception_test.py | 0 samples/snippets/{ => api}/requirements.txt | 0 samples/snippets/fluentd_on_gce/README.md | 30 +++++++++++++ samples/snippets/fluentd_on_gce/main.py | 42 +++++++++++++++++++ samples/snippets/fluentd_on_gce/main_test.py | 23 ++++++++++ .../snippets/fluentd_on_gce/requirements.txt | 1 + .../snippets/fluentd_on_gce/startup_script.sh | 35 ++++++++++++++++ 10 files changed, 131 insertions(+) rename samples/snippets/{ => api}/README.rst (100%) rename samples/snippets/{ => api}/README.rst.in (100%) rename samples/snippets/{ => api}/report_exception.py (100%) rename samples/snippets/{ => api}/report_exception_test.py (100%) rename samples/snippets/{ => api}/requirements.txt (100%) create mode 100644 samples/snippets/fluentd_on_gce/README.md create mode 100644 samples/snippets/fluentd_on_gce/main.py create mode 100644 samples/snippets/fluentd_on_gce/main_test.py create mode 100644 samples/snippets/fluentd_on_gce/requirements.txt create mode 100644 samples/snippets/fluentd_on_gce/startup_script.sh diff --git a/samples/snippets/README.rst b/samples/snippets/api/README.rst similarity index 100% rename from samples/snippets/README.rst rename to samples/snippets/api/README.rst diff --git a/samples/snippets/README.rst.in b/samples/snippets/api/README.rst.in similarity index 100% rename from samples/snippets/README.rst.in rename to samples/snippets/api/README.rst.in diff --git a/samples/snippets/report_exception.py b/samples/snippets/api/report_exception.py similarity index 100% rename from samples/snippets/report_exception.py rename to samples/snippets/api/report_exception.py diff --git a/samples/snippets/report_exception_test.py b/samples/snippets/api/report_exception_test.py similarity index 100% rename from samples/snippets/report_exception_test.py rename to samples/snippets/api/report_exception_test.py diff --git a/samples/snippets/requirements.txt b/samples/snippets/api/requirements.txt similarity index 100% rename from samples/snippets/requirements.txt rename to samples/snippets/api/requirements.txt diff --git a/samples/snippets/fluentd_on_gce/README.md b/samples/snippets/fluentd_on_gce/README.md new file mode 100644 index 00000000..4c9a24c6 --- /dev/null +++ b/samples/snippets/fluentd_on_gce/README.md @@ -0,0 +1,30 @@ +# Google Error Reorting Samples Samples + +This section contains samples for [Google Cloud Error Reporting](https://cloud.google.com/error-reporting). + +A startup script has been provided to demonstrated how to properly provision a GCE +instance with fluentd configured. Note the intallation of fluentd, the addition of the config file, + and the restarting of the fluetnd service. You can start an instance using +it like this: + + gcloud compute instances create example-instance --metadata-from-file startup-script=startup_script.sh + +or simply use it as reference when creating your own instance. + +After fluentd is configured, main.py could be used to simulate an error: + + gcloud compute copy-files main.py example-instance:~/main.py + +Then, + + gcloud compute ssh example-instance + python ~/main.py + +And you will see the message in the Errors Console. + + +These samples are used on the following documentation page: + +> https://cloud.google.com/error-reporting/docs/setting-up-on-compute-engine + + diff --git a/samples/snippets/fluentd_on_gce/main.py b/samples/snippets/fluentd_on_gce/main.py new file mode 100644 index 00000000..45208c91 --- /dev/null +++ b/samples/snippets/fluentd_on_gce/main.py @@ -0,0 +1,42 @@ +# Copyright 2016 Google Inc. All rights reserved. +# +# 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. + +# [START error_reporting] +import traceback + +import fluent.event +import fluent.sender + + +def simulate_error(): + fluent.sender.setup('myapp', host='localhost', port=24224) + + def report(ex): + data = {} + data['message'] = '{0}'.format(ex) + data['serviceContext'] = {'service': 'myapp'} + # ... add more metadata + fluent.event.Event('errors', data) + + # report exception data using: + try: + # simulate calling a method that's not defined + raise NameError + except Exception: + report(traceback.format_exc()) +# [END error_reporting] + + +if __name__ == '__main__': + simulate_error() diff --git a/samples/snippets/fluentd_on_gce/main_test.py b/samples/snippets/fluentd_on_gce/main_test.py new file mode 100644 index 00000000..11a24d03 --- /dev/null +++ b/samples/snippets/fluentd_on_gce/main_test.py @@ -0,0 +1,23 @@ +# Copyright 2016 Google Inc. All rights reserved. +# +# 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. + +import mock + +import main + + +@mock.patch("fluent.event") +def test_error_sends(event_mock): + main.simulate_error() + event_mock.Event.assert_called_once_with(mock.ANY, mock.ANY) diff --git a/samples/snippets/fluentd_on_gce/requirements.txt b/samples/snippets/fluentd_on_gce/requirements.txt new file mode 100644 index 00000000..0119e25c --- /dev/null +++ b/samples/snippets/fluentd_on_gce/requirements.txt @@ -0,0 +1 @@ +fluent-logger==0.4.4 diff --git a/samples/snippets/fluentd_on_gce/startup_script.sh b/samples/snippets/fluentd_on_gce/startup_script.sh new file mode 100644 index 00000000..f2ef895d --- /dev/null +++ b/samples/snippets/fluentd_on_gce/startup_script.sh @@ -0,0 +1,35 @@ +#!/usr/bin/env bash +# Copyright 2016 Google Inc. All rights reserved. +# +# 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 -v + +curl -sSO "https://dl.google.com/cloudagents/install-logging-agent.sh" +chmod +x install-logging-agent.sh +./install-logging-agent.sh +mkdir -p /etc/google-fluentd/config.d/ +cat < /etc/google-fluentd/config.d/forward.conf + + type forward + port 24224 + +EOF +service google-fluentd restart + +apt-get update +apt-get install -yq \ + git build-essential supervisor python python-dev python-pip libffi-dev \ + libssl-dev +pip install fluent-logger + From afe2b3350bb3a59aa0c94b7a48281c41453026b5 Mon Sep 17 00:00:00 2001 From: Andrew Gorcester Date: Fri, 3 Nov 2017 17:32:05 -0700 Subject: [PATCH 24/51] rename dir --- samples/snippets/{fluentd_on_gce => fluent_on_compute}/README.md | 0 samples/snippets/{fluentd_on_gce => fluent_on_compute}/main.py | 0 .../snippets/{fluentd_on_gce => fluent_on_compute}/main_test.py | 0 .../{fluentd_on_gce => fluent_on_compute}/requirements.txt | 0 .../{fluentd_on_gce => fluent_on_compute}/startup_script.sh | 0 5 files changed, 0 insertions(+), 0 deletions(-) rename samples/snippets/{fluentd_on_gce => fluent_on_compute}/README.md (100%) rename samples/snippets/{fluentd_on_gce => fluent_on_compute}/main.py (100%) rename samples/snippets/{fluentd_on_gce => fluent_on_compute}/main_test.py (100%) rename samples/snippets/{fluentd_on_gce => fluent_on_compute}/requirements.txt (100%) rename samples/snippets/{fluentd_on_gce => fluent_on_compute}/startup_script.sh (100%) diff --git a/samples/snippets/fluentd_on_gce/README.md b/samples/snippets/fluent_on_compute/README.md similarity index 100% rename from samples/snippets/fluentd_on_gce/README.md rename to samples/snippets/fluent_on_compute/README.md diff --git a/samples/snippets/fluentd_on_gce/main.py b/samples/snippets/fluent_on_compute/main.py similarity index 100% rename from samples/snippets/fluentd_on_gce/main.py rename to samples/snippets/fluent_on_compute/main.py diff --git a/samples/snippets/fluentd_on_gce/main_test.py b/samples/snippets/fluent_on_compute/main_test.py similarity index 100% rename from samples/snippets/fluentd_on_gce/main_test.py rename to samples/snippets/fluent_on_compute/main_test.py diff --git a/samples/snippets/fluentd_on_gce/requirements.txt b/samples/snippets/fluent_on_compute/requirements.txt similarity index 100% rename from samples/snippets/fluentd_on_gce/requirements.txt rename to samples/snippets/fluent_on_compute/requirements.txt diff --git a/samples/snippets/fluentd_on_gce/startup_script.sh b/samples/snippets/fluent_on_compute/startup_script.sh similarity index 100% rename from samples/snippets/fluentd_on_gce/startup_script.sh rename to samples/snippets/fluent_on_compute/startup_script.sh From 46365c6b0b9c09c41279b9db56920c6b65370d2c Mon Sep 17 00:00:00 2001 From: DPE bot Date: Tue, 7 Nov 2017 15:10:33 -0800 Subject: [PATCH 25/51] Auto-update dependencies. [(#1205)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/1205) --- samples/snippets/fluent_on_compute/requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samples/snippets/fluent_on_compute/requirements.txt b/samples/snippets/fluent_on_compute/requirements.txt index 0119e25c..df09e046 100644 --- a/samples/snippets/fluent_on_compute/requirements.txt +++ b/samples/snippets/fluent_on_compute/requirements.txt @@ -1 +1 @@ -fluent-logger==0.4.4 +fluent-logger==0.5.3 From 9cf05323c5835acede28a89c167326abc43f1026 Mon Sep 17 00:00:00 2001 From: DPE bot Date: Mon, 13 Nov 2017 09:22:23 -0800 Subject: [PATCH 26/51] Auto-update dependencies. [(#1215)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/1215) --- samples/snippets/fluent_on_compute/requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samples/snippets/fluent_on_compute/requirements.txt b/samples/snippets/fluent_on_compute/requirements.txt index df09e046..1c5b4da5 100644 --- a/samples/snippets/fluent_on_compute/requirements.txt +++ b/samples/snippets/fluent_on_compute/requirements.txt @@ -1 +1 @@ -fluent-logger==0.5.3 +fluent-logger==0.6.0 From 060977cdfae5678c04e298923a8aac268887efea Mon Sep 17 00:00:00 2001 From: DPE bot Date: Mon, 4 Dec 2017 09:39:46 -0800 Subject: [PATCH 27/51] Auto-update dependencies. [(#1245)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/1245) --- samples/snippets/fluent_on_compute/requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samples/snippets/fluent_on_compute/requirements.txt b/samples/snippets/fluent_on_compute/requirements.txt index 1c5b4da5..c20856dc 100644 --- a/samples/snippets/fluent_on_compute/requirements.txt +++ b/samples/snippets/fluent_on_compute/requirements.txt @@ -1 +1 @@ -fluent-logger==0.6.0 +fluent-logger==0.6.2 From 0f75778ea34ac94709b5387a55eb187c1d52d22f Mon Sep 17 00:00:00 2001 From: DPE bot Date: Wed, 6 Dec 2017 15:09:32 -0800 Subject: [PATCH 28/51] Auto-update dependencies. [(#1248)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/1248) --- samples/snippets/fluent_on_compute/requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samples/snippets/fluent_on_compute/requirements.txt b/samples/snippets/fluent_on_compute/requirements.txt index c20856dc..f7160128 100644 --- a/samples/snippets/fluent_on_compute/requirements.txt +++ b/samples/snippets/fluent_on_compute/requirements.txt @@ -1 +1 @@ -fluent-logger==0.6.2 +fluent-logger==0.7.0 From daf3bdf33c1407c533b43511edc0bc230df72e89 Mon Sep 17 00:00:00 2001 From: michaelawyu Date: Thu, 7 Dec 2017 10:34:29 -0800 Subject: [PATCH 29/51] Added "Open in Cloud Shell" buttons to README files [(#1254)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/1254) --- samples/snippets/api/README.rst | 8 ++++++++ samples/snippets/api/README.rst.in | 2 ++ samples/snippets/fluent_on_compute/README.md | 5 +++++ 3 files changed, 15 insertions(+) diff --git a/samples/snippets/api/README.rst b/samples/snippets/api/README.rst index 5f662b8f..c5898717 100644 --- a/samples/snippets/api/README.rst +++ b/samples/snippets/api/README.rst @@ -3,6 +3,10 @@ Stackdriver Error Reporting Python Samples =============================================================================== +.. image:: https://gstatic.com/cloudssh/images/open-btn.png + :target: https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/GoogleCloudPlatform/python-docs-samples&page=editor&open_in_editor=error_reporting/api/README.rst + + This directory contains samples for Stackdriver Error Reporting. `Stackdriver Error Reporting`_ aggregates and displays errors produced in your running cloud services. @@ -55,6 +59,10 @@ Samples Report Exception +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ +.. image:: https://gstatic.com/cloudssh/images/open-btn.png + :target: https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/GoogleCloudPlatform/python-docs-samples&page=editor&open_in_editor=error_reporting/api/report_exception.py;error_reporting/api/README.rst + + To run this sample: diff --git a/samples/snippets/api/README.rst.in b/samples/snippets/api/README.rst.in index 4eeab4bb..ac60cc80 100644 --- a/samples/snippets/api/README.rst.in +++ b/samples/snippets/api/README.rst.in @@ -17,3 +17,5 @@ samples: file: report_exception.py cloud_client_library: true + +folder: error_reporting/api \ No newline at end of file diff --git a/samples/snippets/fluent_on_compute/README.md b/samples/snippets/fluent_on_compute/README.md index 4c9a24c6..d3a58c16 100644 --- a/samples/snippets/fluent_on_compute/README.md +++ b/samples/snippets/fluent_on_compute/README.md @@ -1,5 +1,10 @@ # Google Error Reorting Samples Samples +[![Open in Cloud Shell][shell_img]][shell_link] + +[shell_img]: http://gstatic.com/cloudssh/images/open-btn.png +[shell_link]: https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/GoogleCloudPlatform/python-docs-samples&page=editor&open_in_editor=error_reporting/fluent_on_compute/README.md + This section contains samples for [Google Cloud Error Reporting](https://cloud.google.com/error-reporting). A startup script has been provided to demonstrated how to properly provision a GCE From 011a7199706e7efa65bf2e73ae816c18153b40c4 Mon Sep 17 00:00:00 2001 From: DPE bot Date: Thu, 14 Dec 2017 10:14:39 -0800 Subject: [PATCH 30/51] Auto-update dependencies. [(#1276)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/1276) --- samples/snippets/fluent_on_compute/requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samples/snippets/fluent_on_compute/requirements.txt b/samples/snippets/fluent_on_compute/requirements.txt index f7160128..9d9029e1 100644 --- a/samples/snippets/fluent_on_compute/requirements.txt +++ b/samples/snippets/fluent_on_compute/requirements.txt @@ -1 +1 @@ -fluent-logger==0.7.0 +fluent-logger==0.8.0 From d66bb141b7ec8e1415225eea006ffd3a0cbf12b8 Mon Sep 17 00:00:00 2001 From: DPE bot Date: Tue, 2 Jan 2018 14:02:47 -0800 Subject: [PATCH 31/51] Auto-update dependencies. [(#1282)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/1282) * Auto-update dependencies. * Fix storage acl sample Change-Id: I413bea899fdde4c4859e4070a9da25845b81f7cf --- samples/snippets/fluent_on_compute/requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samples/snippets/fluent_on_compute/requirements.txt b/samples/snippets/fluent_on_compute/requirements.txt index 9d9029e1..11c52d4b 100644 --- a/samples/snippets/fluent_on_compute/requirements.txt +++ b/samples/snippets/fluent_on_compute/requirements.txt @@ -1 +1 @@ -fluent-logger==0.8.0 +fluent-logger==0.9.0 From 71c29cde2538954654ccd294337861d830420771 Mon Sep 17 00:00:00 2001 From: DPE bot Date: Tue, 16 Jan 2018 11:20:59 -0800 Subject: [PATCH 32/51] Auto-update dependencies. [(#1317)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/1317) --- samples/snippets/fluent_on_compute/requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samples/snippets/fluent_on_compute/requirements.txt b/samples/snippets/fluent_on_compute/requirements.txt index 11c52d4b..c64e4541 100644 --- a/samples/snippets/fluent_on_compute/requirements.txt +++ b/samples/snippets/fluent_on_compute/requirements.txt @@ -1 +1 @@ -fluent-logger==0.9.0 +fluent-logger==0.9.1 From fbac152eca7e23b30c77f6b1aeb8ea1495c62b04 Mon Sep 17 00:00:00 2001 From: DPE bot Date: Thu, 1 Feb 2018 22:20:35 -0800 Subject: [PATCH 33/51] Auto-update dependencies. [(#1320)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/1320) --- samples/snippets/api/requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samples/snippets/api/requirements.txt b/samples/snippets/api/requirements.txt index d2f22014..1e6bfb86 100644 --- a/samples/snippets/api/requirements.txt +++ b/samples/snippets/api/requirements.txt @@ -1 +1 @@ -google-cloud-error-reporting==0.28.0 +google-cloud-error-reporting==0.29.0 From f844f2a829c5f9b7805a9d937420efc1a12542ac Mon Sep 17 00:00:00 2001 From: DPE bot Date: Mon, 26 Feb 2018 09:03:37 -0800 Subject: [PATCH 34/51] Auto-update dependencies. [(#1359)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/1359) --- samples/snippets/fluent_on_compute/requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samples/snippets/fluent_on_compute/requirements.txt b/samples/snippets/fluent_on_compute/requirements.txt index c64e4541..3bea1b27 100644 --- a/samples/snippets/fluent_on_compute/requirements.txt +++ b/samples/snippets/fluent_on_compute/requirements.txt @@ -1 +1 @@ -fluent-logger==0.9.1 +fluent-logger==0.9.2 From 1b6b9a254e789e439a216edf1b4cc3ef5231e65c Mon Sep 17 00:00:00 2001 From: DPE bot Date: Mon, 5 Mar 2018 12:28:55 -0800 Subject: [PATCH 35/51] Auto-update dependencies. [(#1377)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/1377) * Auto-update dependencies. * Update requirements.txt --- samples/snippets/api/requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samples/snippets/api/requirements.txt b/samples/snippets/api/requirements.txt index 1e6bfb86..0112091f 100644 --- a/samples/snippets/api/requirements.txt +++ b/samples/snippets/api/requirements.txt @@ -1 +1 @@ -google-cloud-error-reporting==0.29.0 +google-cloud-error-reporting==0.29.1 From e782c59814e0c48df011296054d735efd7d51fb3 Mon Sep 17 00:00:00 2001 From: chenyumic Date: Fri, 6 Apr 2018 22:57:36 -0700 Subject: [PATCH 36/51] Regenerate the README files and fix the Open in Cloud Shell link for some samples [(#1441)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/1441) --- samples/snippets/api/README.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/samples/snippets/api/README.rst b/samples/snippets/api/README.rst index c5898717..63881855 100644 --- a/samples/snippets/api/README.rst +++ b/samples/snippets/api/README.rst @@ -13,7 +13,7 @@ This directory contains samples for Stackdriver Error Reporting. `Stackdriver Er -.. _Stackdriver Error Reporting: https://cloud.google.com/error-reporting/docs/ +.. _Stackdriver Error Reporting: https://cloud.google.com/error-reporting/docs/ Setup ------------------------------------------------------------------------------- @@ -60,7 +60,7 @@ Report Exception +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ .. image:: https://gstatic.com/cloudssh/images/open-btn.png - :target: https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/GoogleCloudPlatform/python-docs-samples&page=editor&open_in_editor=error_reporting/api/report_exception.py;error_reporting/api/README.rst + :target: https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/GoogleCloudPlatform/python-docs-samples&page=editor&open_in_editor=error_reporting/api/report_exception.py,error_reporting/api/README.rst From 232d0fdbf7332e77641b629df5c6dc9c44555a5c Mon Sep 17 00:00:00 2001 From: Frank Natividad Date: Thu, 26 Apr 2018 10:26:41 -0700 Subject: [PATCH 37/51] Update READMEs to fix numbering and add git clone [(#1464)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/1464) --- samples/snippets/api/README.rst | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/samples/snippets/api/README.rst b/samples/snippets/api/README.rst index 63881855..74bcd639 100644 --- a/samples/snippets/api/README.rst +++ b/samples/snippets/api/README.rst @@ -32,10 +32,16 @@ credentials for applications. Install Dependencies ++++++++++++++++++++ +#. Clone python-docs-samples and change directory to the sample directory you want to use. + + .. code-block:: bash + + $ git clone https://github.com/GoogleCloudPlatform/python-docs-samples.git + #. Install `pip`_ and `virtualenv`_ if you do not already have them. You may want to refer to the `Python Development Environment Setup Guide`_ for Google Cloud Platform for instructions. - .. _Python Development Environment Setup Guide: - https://cloud.google.com/python/setup + .. _Python Development Environment Setup Guide: + https://cloud.google.com/python/setup #. Create a virtualenv. Samples are compatible with Python 2.7 and 3.4+. From fb658e92f849aae79dba08d9c4262028cdf220e3 Mon Sep 17 00:00:00 2001 From: DPE bot Date: Tue, 28 Aug 2018 11:17:45 -0700 Subject: [PATCH 38/51] Auto-update dependencies. [(#1658)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/1658) * Auto-update dependencies. * Rollback appengine/standard/bigquery/. * Rollback appengine/standard/iap/. * Rollback bigtable/metricscaler. * Rolledback appengine/flexible/datastore. * Rollback dataproc/ * Rollback jobs/api_client * Rollback vision/cloud-client. * Rollback functions/ocr/app. * Rollback iot/api-client/end_to_end_example. * Rollback storage/cloud-client. * Rollback kms/api-client. * Rollback dlp/ * Rollback bigquery/cloud-client. * Rollback iot/api-client/manager. * Rollback appengine/flexible/cloudsql_postgresql. --- samples/snippets/api/requirements.txt | 2 +- samples/snippets/fluent_on_compute/requirements.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/samples/snippets/api/requirements.txt b/samples/snippets/api/requirements.txt index 0112091f..96eb846d 100644 --- a/samples/snippets/api/requirements.txt +++ b/samples/snippets/api/requirements.txt @@ -1 +1 @@ -google-cloud-error-reporting==0.29.1 +google-cloud-error-reporting==0.30.0 diff --git a/samples/snippets/fluent_on_compute/requirements.txt b/samples/snippets/fluent_on_compute/requirements.txt index 3bea1b27..1b1073c1 100644 --- a/samples/snippets/fluent_on_compute/requirements.txt +++ b/samples/snippets/fluent_on_compute/requirements.txt @@ -1 +1 @@ -fluent-logger==0.9.2 +fluent-logger==0.9.3 From 0a360ecf4bc09823132e5624e23bfe0025ca6ada Mon Sep 17 00:00:00 2001 From: Charles Engelke Date: Thu, 15 Nov 2018 11:38:32 -0800 Subject: [PATCH 39/51] Put in new region code error_reporting_quickstart [(#1842)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/1842) --- samples/snippets/api/report_exception.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/samples/snippets/api/report_exception.py b/samples/snippets/api/report_exception.py index 31ef99b0..d1312e61 100644 --- a/samples/snippets/api/report_exception.py +++ b/samples/snippets/api/report_exception.py @@ -14,6 +14,7 @@ # [START error_reporting] +# [START error_reporting_quickstart] def simulate_error(): from google.cloud import error_reporting @@ -23,6 +24,7 @@ def simulate_error(): raise NameError except Exception: client.report_exception() +# [END error_reporting_quickstart] # [END error_reporting] From d0c50a8e3cb1c7347901e7e4fb99415eeb8d1b21 Mon Sep 17 00:00:00 2001 From: Charles Engelke Date: Thu, 15 Nov 2018 11:47:45 -0800 Subject: [PATCH 40/51] New region tags [(#1843)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/1843) --- samples/snippets/api/report_exception.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/samples/snippets/api/report_exception.py b/samples/snippets/api/report_exception.py index d1312e61..2b7e8f06 100644 --- a/samples/snippets/api/report_exception.py +++ b/samples/snippets/api/report_exception.py @@ -15,6 +15,7 @@ # [START error_reporting] # [START error_reporting_quickstart] +# [START error_reporting_setup_python] def simulate_error(): from google.cloud import error_reporting @@ -24,16 +25,19 @@ def simulate_error(): raise NameError except Exception: client.report_exception() +# [END error_reporting_setup_python] # [END error_reporting_quickstart] # [END error_reporting] # [START error_reporting_manual] +# [START error_reporting_setup_python_manual] def report_manual_error(): from google.cloud import error_reporting client = error_reporting.Client() client.report("An error has occurred.") +# [START error_reporting_setup_python_manual] # [END error_reporting_manual] From 952704d0e9ed5b9ca25fb38517fe44f9a551ce9f Mon Sep 17 00:00:00 2001 From: DPEBot Date: Wed, 6 Feb 2019 12:06:35 -0800 Subject: [PATCH 41/51] Auto-update dependencies. [(#1980)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/1980) * Auto-update dependencies. * Update requirements.txt * Update requirements.txt --- samples/snippets/api/requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samples/snippets/api/requirements.txt b/samples/snippets/api/requirements.txt index 96eb846d..deb4c891 100644 --- a/samples/snippets/api/requirements.txt +++ b/samples/snippets/api/requirements.txt @@ -1 +1 @@ -google-cloud-error-reporting==0.30.0 +google-cloud-error-reporting==0.30.1 From 52e97d2bd294b847fa7eee7f3e9dca3267a0dcaa Mon Sep 17 00:00:00 2001 From: Gus Class Date: Wed, 23 Oct 2019 16:27:00 -0700 Subject: [PATCH 42/51] Adds updates including compute [(#2436)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/2436) * Adds updates including compute * Python 2 compat pytest * Fixing weird \r\n issue from GH merge * Put asset tests back in * Re-add pod operator test * Hack parameter for k8s pod operator --- samples/snippets/api/requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samples/snippets/api/requirements.txt b/samples/snippets/api/requirements.txt index deb4c891..9035e7cd 100644 --- a/samples/snippets/api/requirements.txt +++ b/samples/snippets/api/requirements.txt @@ -1 +1 @@ -google-cloud-error-reporting==0.30.1 +google-cloud-error-reporting==0.32.1 From e4b17e330bb19d669a4fe564bf8a9dc2a14a2ac9 Mon Sep 17 00:00:00 2001 From: DPEBot Date: Fri, 20 Dec 2019 17:41:38 -0800 Subject: [PATCH 43/51] Auto-update dependencies. [(#2005)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/2005) * Auto-update dependencies. * Revert update of appengine/flexible/datastore. * revert update of appengine/flexible/scipy * revert update of bigquery/bqml * revert update of bigquery/cloud-client * revert update of bigquery/datalab-migration * revert update of bigtable/quickstart * revert update of compute/api * revert update of container_registry/container_analysis * revert update of dataflow/run_template * revert update of datastore/cloud-ndb * revert update of dialogflow/cloud-client * revert update of dlp * revert update of functions/imagemagick * revert update of functions/ocr/app * revert update of healthcare/api-client/fhir * revert update of iam/api-client * revert update of iot/api-client/gcs_file_to_device * revert update of iot/api-client/mqtt_example * revert update of language/automl * revert update of run/image-processing * revert update of vision/automl * revert update testing/requirements.txt * revert update of vision/cloud-client/detect * revert update of vision/cloud-client/product_search * revert update of jobs/v2/api_client * revert update of jobs/v3/api_client * revert update of opencensus * revert update of translate/cloud-client * revert update to speech/cloud-client Co-authored-by: Kurtis Van Gent <31518063+kurtisvg@users.noreply.github.com> Co-authored-by: Doug Mahugh --- samples/snippets/api/requirements.txt | 2 +- samples/snippets/fluent_on_compute/requirements.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/samples/snippets/api/requirements.txt b/samples/snippets/api/requirements.txt index 9035e7cd..c9ac0851 100644 --- a/samples/snippets/api/requirements.txt +++ b/samples/snippets/api/requirements.txt @@ -1 +1 @@ -google-cloud-error-reporting==0.32.1 +google-cloud-error-reporting==0.33.0 diff --git a/samples/snippets/fluent_on_compute/requirements.txt b/samples/snippets/fluent_on_compute/requirements.txt index 1b1073c1..5501f897 100644 --- a/samples/snippets/fluent_on_compute/requirements.txt +++ b/samples/snippets/fluent_on_compute/requirements.txt @@ -1 +1 @@ -fluent-logger==0.9.3 +fluent-logger==0.9.4 From d25ffa73f4a5c25998e9382fc2194e571091b787 Mon Sep 17 00:00:00 2001 From: WhiteSource Renovate Date: Sat, 29 Feb 2020 00:04:14 +0100 Subject: [PATCH 44/51] chore(deps): update dependency fluent-logger to v0.9.5 [(#3004)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/3004) --- samples/snippets/fluent_on_compute/requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samples/snippets/fluent_on_compute/requirements.txt b/samples/snippets/fluent_on_compute/requirements.txt index 5501f897..3c6a29f8 100644 --- a/samples/snippets/fluent_on_compute/requirements.txt +++ b/samples/snippets/fluent_on_compute/requirements.txt @@ -1 +1 @@ -fluent-logger==0.9.4 +fluent-logger==0.9.5 From 232f6781a10efe0b94405ddd7867a2109bb7bf50 Mon Sep 17 00:00:00 2001 From: WhiteSource Renovate Date: Tue, 10 Mar 2020 23:28:04 +0100 Subject: [PATCH 45/51] chore(deps): update dependency fluent-logger to v0.9.6 [(#3080)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/3080) This PR contains the following updates: | Package | Update | Change | |---|---|---| | [fluent-logger](https://togithub.com/fluent/fluent-logger-python) | patch | `==0.9.5` -> `==0.9.6` | --- ### Release Notes
fluent/fluent-logger-python ### [`v0.9.6`](https://togithub.com/fluent/fluent-logger-python/compare/v0.9.5...v0.9.6) [Compare Source](https://togithub.com/fluent/fluent-logger-python/compare/v0.9.5...v0.9.6)
--- ### Renovate configuration :date: **Schedule**: At any time (no schedule defined). :vertical_traffic_light: **Automerge**: Disabled by config. Please merge this manually once you are satisfied. :recycle: **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox. :no_bell: **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] If you want to rebase/retry this PR, check this box --- This PR has been generated by [WhiteSource Renovate](https://renovate.whitesourcesoftware.com). View repository job log [here](https://app.renovatebot.com/dashboard#GoogleCloudPlatform/python-docs-samples). --- samples/snippets/fluent_on_compute/requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samples/snippets/fluent_on_compute/requirements.txt b/samples/snippets/fluent_on_compute/requirements.txt index 3c6a29f8..d1c2863f 100644 --- a/samples/snippets/fluent_on_compute/requirements.txt +++ b/samples/snippets/fluent_on_compute/requirements.txt @@ -1 +1 @@ -fluent-logger==0.9.5 +fluent-logger==0.9.6 From 70025641b9201590f4c4b85a7625fa371822ac8f Mon Sep 17 00:00:00 2001 From: Kurtis Van Gent <31518063+kurtisvg@users.noreply.github.com> Date: Wed, 1 Apr 2020 19:11:50 -0700 Subject: [PATCH 46/51] Simplify noxfile setup. [(#2806)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/2806) * chore(deps): update dependency requests to v2.23.0 * Simplify noxfile and add version control. * Configure appengine/standard to only test Python 2.7. * Update Kokokro configs to match noxfile. * Add requirements-test to each folder. * Remove Py2 versions from everything execept appengine/standard. * Remove conftest.py. * Remove appengine/standard/conftest.py * Remove 'no-sucess-flaky-report' from pytest.ini. * Add GAE SDK back to appengine/standard tests. * Fix typo. * Roll pytest to python 2 version. * Add a bunch of testing requirements. * Remove typo. * Add appengine lib directory back in. * Add some additional requirements. * Fix issue with flake8 args. * Even more requirements. * Readd appengine conftest.py. * Add a few more requirements. * Even more Appengine requirements. * Add webtest for appengine/standard/mailgun. * Add some additional requirements. * Add workaround for issue with mailjet-rest. * Add responses for appengine/standard/mailjet. Co-authored-by: Renovate Bot --- samples/snippets/api/requirements-test.txt | 1 + samples/snippets/fluent_on_compute/requirements-test.txt | 2 ++ 2 files changed, 3 insertions(+) create mode 100644 samples/snippets/api/requirements-test.txt create mode 100644 samples/snippets/fluent_on_compute/requirements-test.txt diff --git a/samples/snippets/api/requirements-test.txt b/samples/snippets/api/requirements-test.txt new file mode 100644 index 00000000..781d4326 --- /dev/null +++ b/samples/snippets/api/requirements-test.txt @@ -0,0 +1 @@ +pytest==5.3.2 diff --git a/samples/snippets/fluent_on_compute/requirements-test.txt b/samples/snippets/fluent_on_compute/requirements-test.txt new file mode 100644 index 00000000..41c4d511 --- /dev/null +++ b/samples/snippets/fluent_on_compute/requirements-test.txt @@ -0,0 +1,2 @@ +pytest==5.3.2 +mock==3.0.5 From ea66147df37dd6a52b095b45c029d3201c331910 Mon Sep 17 00:00:00 2001 From: WhiteSource Renovate Date: Tue, 19 May 2020 00:25:20 +0200 Subject: [PATCH 47/51] chore(deps): update dependency google-cloud-error-reporting to v0.34.0 [(#3782)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/3782) --- samples/snippets/api/requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samples/snippets/api/requirements.txt b/samples/snippets/api/requirements.txt index c9ac0851..242254e8 100644 --- a/samples/snippets/api/requirements.txt +++ b/samples/snippets/api/requirements.txt @@ -1 +1 @@ -google-cloud-error-reporting==0.33.0 +google-cloud-error-reporting==0.34.0 From 65c7657b4490faa3de54fcd8cb82641b0fbff26b Mon Sep 17 00:00:00 2001 From: WhiteSource Renovate Date: Mon, 13 Jul 2020 00:46:30 +0200 Subject: [PATCH 48/51] chore(deps): update dependency pytest to v5.4.3 [(#4279)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/4279) * chore(deps): update dependency pytest to v5.4.3 * specify pytest for python 2 in appengine Co-authored-by: Leah Cole --- samples/snippets/api/requirements-test.txt | 2 +- samples/snippets/fluent_on_compute/requirements-test.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/samples/snippets/api/requirements-test.txt b/samples/snippets/api/requirements-test.txt index 781d4326..79738af5 100644 --- a/samples/snippets/api/requirements-test.txt +++ b/samples/snippets/api/requirements-test.txt @@ -1 +1 @@ -pytest==5.3.2 +pytest==5.4.3 diff --git a/samples/snippets/fluent_on_compute/requirements-test.txt b/samples/snippets/fluent_on_compute/requirements-test.txt index 41c4d511..1a71e3e3 100644 --- a/samples/snippets/fluent_on_compute/requirements-test.txt +++ b/samples/snippets/fluent_on_compute/requirements-test.txt @@ -1,2 +1,2 @@ -pytest==5.3.2 +pytest==5.4.3 mock==3.0.5 From 2c0785ffed9b79a8975b102c3a19df0f805b35b3 Mon Sep 17 00:00:00 2001 From: WhiteSource Renovate Date: Mon, 13 Jul 2020 07:10:34 +0200 Subject: [PATCH 49/51] chore(deps): update dependency mock to v4 [(#4287)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/4287) * chore(deps): update dependency mock to v4 * specify mock version for appengine python 2 Co-authored-by: Leah Cole --- samples/snippets/fluent_on_compute/requirements-test.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samples/snippets/fluent_on_compute/requirements-test.txt b/samples/snippets/fluent_on_compute/requirements-test.txt index 1a71e3e3..676ff949 100644 --- a/samples/snippets/fluent_on_compute/requirements-test.txt +++ b/samples/snippets/fluent_on_compute/requirements-test.txt @@ -1,2 +1,2 @@ pytest==5.4.3 -mock==3.0.5 +mock==4.0.2 From 705ade37fe6c486219bdde1c36c5febde3888344 Mon Sep 17 00:00:00 2001 From: WhiteSource Renovate Date: Sat, 1 Aug 2020 21:51:00 +0200 Subject: [PATCH 50/51] Update dependency pytest to v6 [(#4390)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/4390) --- samples/snippets/api/requirements-test.txt | 2 +- samples/snippets/fluent_on_compute/requirements-test.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/samples/snippets/api/requirements-test.txt b/samples/snippets/api/requirements-test.txt index 79738af5..7e460c8c 100644 --- a/samples/snippets/api/requirements-test.txt +++ b/samples/snippets/api/requirements-test.txt @@ -1 +1 @@ -pytest==5.4.3 +pytest==6.0.1 diff --git a/samples/snippets/fluent_on_compute/requirements-test.txt b/samples/snippets/fluent_on_compute/requirements-test.txt index 676ff949..2466e250 100644 --- a/samples/snippets/fluent_on_compute/requirements-test.txt +++ b/samples/snippets/fluent_on_compute/requirements-test.txt @@ -1,2 +1,2 @@ -pytest==5.4.3 +pytest==6.0.1 mock==4.0.2 From 59853ee23e7be1125d8ad154c9e874f3bd27dd95 Mon Sep 17 00:00:00 2001 From: arithmetic1728 Date: Wed, 12 Aug 2020 15:57:28 -0700 Subject: [PATCH 51/51] chore: update templates --- .github/CODEOWNERS | 8 + .gitignore | 3 +- .kokoro/build.sh | 8 +- .kokoro/docker/docs/Dockerfile | 98 ++++ .kokoro/docker/docs/fetch_gpg_keys.sh | 45 ++ .kokoro/docs/common.cfg | 21 +- .kokoro/docs/docs-presubmit.cfg | 17 + .kokoro/publish-docs.sh | 39 +- .kokoro/trampoline_v2.sh | 487 ++++++++++++++++++ .trampolinerc | 51 ++ docs/conf.py | 11 +- noxfile.py | 37 ++ samples/snippets/api/noxfile.py | 224 ++++++++ samples/snippets/fluent_on_compute/noxfile.py | 224 ++++++++ synth.metadata | 11 +- synth.py | 11 +- 16 files changed, 1268 insertions(+), 27 deletions(-) create mode 100644 .github/CODEOWNERS create mode 100644 .kokoro/docker/docs/Dockerfile create mode 100755 .kokoro/docker/docs/fetch_gpg_keys.sh create mode 100644 .kokoro/docs/docs-presubmit.cfg create mode 100755 .kokoro/trampoline_v2.sh create mode 100644 .trampolinerc create mode 100644 samples/snippets/api/noxfile.py create mode 100644 samples/snippets/fluent_on_compute/noxfile.py diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS new file mode 100644 index 00000000..d2cf5a10 --- /dev/null +++ b/.github/CODEOWNERS @@ -0,0 +1,8 @@ +# Code owners file. +# This file controls who is tagged for review for any given pull request. +# +# For syntax help see: +# https://help.github.com/en/github/creating-cloning-and-archiving-repositories/about-code-owners#codeowners-syntax + + +/samples/**/*.py @googleapis/python-samples-owners \ No newline at end of file diff --git a/.gitignore b/.gitignore index b87e1ed5..b9daa52f 100644 --- a/.gitignore +++ b/.gitignore @@ -46,6 +46,7 @@ pip-log.txt # Built documentation docs/_build bigquery/docs/generated +docs.metadata # Virtual environment env/ @@ -57,4 +58,4 @@ system_tests/local_test_setup # Make sure a generated file isn't accidentally committed. pylintrc -pylintrc.test \ No newline at end of file +pylintrc.test diff --git a/.kokoro/build.sh b/.kokoro/build.sh index 8d62ff18..8e64a1c9 100755 --- a/.kokoro/build.sh +++ b/.kokoro/build.sh @@ -36,4 +36,10 @@ python3.6 -m pip uninstall --yes --quiet nox-automation python3.6 -m pip install --upgrade --quiet nox python3.6 -m nox --version -python3.6 -m nox +# 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:-}" +else + python3.6 -m nox +fi diff --git a/.kokoro/docker/docs/Dockerfile b/.kokoro/docker/docs/Dockerfile new file mode 100644 index 00000000..412b0b56 --- /dev/null +++ b/.kokoro/docker/docs/Dockerfile @@ -0,0 +1,98 @@ +# 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. + +from ubuntu:20.04 + +ENV DEBIAN_FRONTEND noninteractive + +# Ensure local Python is preferred over distribution Python. +ENV PATH /usr/local/bin:$PATH + +# Install dependencies. +RUN apt-get update \ + && apt-get install -y --no-install-recommends \ + apt-transport-https \ + build-essential \ + ca-certificates \ + curl \ + dirmngr \ + git \ + gpg-agent \ + graphviz \ + libbz2-dev \ + libdb5.3-dev \ + libexpat1-dev \ + libffi-dev \ + liblzma-dev \ + libreadline-dev \ + libsnappy-dev \ + libssl-dev \ + libsqlite3-dev \ + portaudio19-dev \ + redis-server \ + software-properties-common \ + ssh \ + sudo \ + tcl \ + tcl-dev \ + tk \ + tk-dev \ + uuid-dev \ + wget \ + zlib1g-dev \ + && add-apt-repository universe \ + && apt-get update \ + && apt-get -y install jq \ + && apt-get clean autoclean \ + && apt-get autoremove -y \ + && rm -rf /var/lib/apt/lists/* \ + && rm -f /var/cache/apt/archives/*.deb + + +COPY fetch_gpg_keys.sh /tmp +# Install the desired versions of Python. +RUN set -ex \ + && export GNUPGHOME="$(mktemp -d)" \ + && echo "disable-ipv6" >> "${GNUPGHOME}/dirmngr.conf" \ + && /tmp/fetch_gpg_keys.sh \ + && for PYTHON_VERSION in 3.7.8 3.8.5; do \ + wget --no-check-certificate -O python-${PYTHON_VERSION}.tar.xz "https://www.python.org/ftp/python/${PYTHON_VERSION%%[a-z]*}/Python-$PYTHON_VERSION.tar.xz" \ + && wget --no-check-certificate -O python-${PYTHON_VERSION}.tar.xz.asc "https://www.python.org/ftp/python/${PYTHON_VERSION%%[a-z]*}/Python-$PYTHON_VERSION.tar.xz.asc" \ + && gpg --batch --verify python-${PYTHON_VERSION}.tar.xz.asc python-${PYTHON_VERSION}.tar.xz \ + && rm -r python-${PYTHON_VERSION}.tar.xz.asc \ + && mkdir -p /usr/src/python-${PYTHON_VERSION} \ + && tar -xJC /usr/src/python-${PYTHON_VERSION} --strip-components=1 -f python-${PYTHON_VERSION}.tar.xz \ + && rm python-${PYTHON_VERSION}.tar.xz \ + && cd /usr/src/python-${PYTHON_VERSION} \ + && ./configure \ + --enable-shared \ + # This works only on Python 2.7 and throws a warning on every other + # version, but seems otherwise harmless. + --enable-unicode=ucs4 \ + --with-system-ffi \ + --without-ensurepip \ + && make -j$(nproc) \ + && make install \ + && ldconfig \ + ; done \ + && rm -rf "${GNUPGHOME}" \ + && rm -rf /usr/src/python* \ + && rm -rf ~/.cache/ + +RUN wget -O /tmp/get-pip.py 'https://bootstrap.pypa.io/get-pip.py' \ + && python3.7 /tmp/get-pip.py \ + && python3.8 /tmp/get-pip.py \ + && rm /tmp/get-pip.py + +CMD ["python3.7"] diff --git a/.kokoro/docker/docs/fetch_gpg_keys.sh b/.kokoro/docker/docs/fetch_gpg_keys.sh new file mode 100755 index 00000000..d653dd86 --- /dev/null +++ b/.kokoro/docker/docs/fetch_gpg_keys.sh @@ -0,0 +1,45 @@ +#!/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. + +# A script to fetch gpg keys with retry. +# Avoid jinja parsing the file. +# + +function retry { + if [[ "${#}" -le 1 ]]; then + echo "Usage: ${0} retry_count commands.." + exit 1 + fi + local retries=${1} + local command="${@:2}" + until [[ "${retries}" -le 0 ]]; do + $command && return 0 + if [[ $? -ne 0 ]]; then + echo "command failed, retrying" + ((retries--)) + fi + done + return 1 +} + +# 3.6.9, 3.7.5 (Ned Deily) +retry 3 gpg --keyserver ha.pool.sks-keyservers.net --recv-keys \ + 0D96DF4D4110E5C43FBFB17F2D347EA6AA65421D + +# 3.8.0 (Łukasz Langa) +retry 3 gpg --keyserver ha.pool.sks-keyservers.net --recv-keys \ + E3FF2839C048B25C084DEBE9B26995E310250568 + +# diff --git a/.kokoro/docs/common.cfg b/.kokoro/docs/common.cfg index 7cdc05f8..f3e7d6d1 100644 --- a/.kokoro/docs/common.cfg +++ b/.kokoro/docs/common.cfg @@ -11,12 +11,12 @@ action { gfile_resources: "/bigstore/cloud-devrel-kokoro-resources/trampoline" # Use the trampoline script to run in docker. -build_file: "python-error-reporting/.kokoro/trampoline.sh" +build_file: "python-error-reporting/.kokoro/trampoline_v2.sh" # Configure the docker image for kokoro-trampoline. env_vars: { key: "TRAMPOLINE_IMAGE" - value: "gcr.io/cloud-devrel-kokoro-resources/python-multi" + value: "gcr.io/cloud-devrel-kokoro-resources/python-lib-docs" } env_vars: { key: "TRAMPOLINE_BUILD_FILE" @@ -28,6 +28,23 @@ env_vars: { value: "docs-staging" } +env_vars: { + key: "V2_STAGING_BUCKET" + value: "docs-staging-v2-staging" +} + +# It will upload the docker image after successful builds. +env_vars: { + key: "TRAMPOLINE_IMAGE_UPLOAD" + value: "true" +} + +# It will always build the docker image. +env_vars: { + key: "TRAMPOLINE_DOCKERFILE" + value: ".kokoro/docker/docs/Dockerfile" +} + # Fetch the token needed for reporting release status to GitHub before_action { fetch_keystore { diff --git a/.kokoro/docs/docs-presubmit.cfg b/.kokoro/docs/docs-presubmit.cfg new file mode 100644 index 00000000..11181078 --- /dev/null +++ b/.kokoro/docs/docs-presubmit.cfg @@ -0,0 +1,17 @@ +# Format: //devtools/kokoro/config/proto/build.proto + +env_vars: { + key: "STAGING_BUCKET" + value: "gcloud-python-test" +} + +env_vars: { + key: "V2_STAGING_BUCKET" + value: "gcloud-python-test" +} + +# We only upload the image in the main `docs` build. +env_vars: { + key: "TRAMPOLINE_IMAGE_UPLOAD" + value: "false" +} diff --git a/.kokoro/publish-docs.sh b/.kokoro/publish-docs.sh index 307339cd..8acb14e8 100755 --- a/.kokoro/publish-docs.sh +++ b/.kokoro/publish-docs.sh @@ -18,26 +18,16 @@ set -eo pipefail # Disable buffering, so that the logs stream through. export PYTHONUNBUFFERED=1 -cd github/python-error-reporting - -# Remove old nox -python3.6 -m pip uninstall --yes --quiet nox-automation +export PATH="${HOME}/.local/bin:${PATH}" # Install nox -python3.6 -m pip install --upgrade --quiet nox -python3.6 -m nox --version +python3 -m pip install --user --upgrade --quiet nox +python3 -m nox --version # build docs nox -s docs -python3 -m pip install gcp-docuploader - -# install a json parser -sudo apt-get update -sudo apt-get -y install software-properties-common -sudo add-apt-repository universe -sudo apt-get update -sudo apt-get -y install jq +python3 -m pip install --user gcp-docuploader # create metadata python3 -m docuploader create-metadata \ @@ -52,4 +42,23 @@ python3 -m docuploader create-metadata \ cat docs.metadata # upload docs -python3 -m docuploader upload docs/_build/html --metadata-file docs.metadata --staging-bucket docs-staging +python3 -m docuploader upload docs/_build/html --metadata-file docs.metadata --staging-bucket "${STAGING_BUCKET}" + + +# docfx yaml files +nox -s docfx + +# create metadata. +python3 -m docuploader create-metadata \ + --name=$(jq --raw-output '.name // empty' .repo-metadata.json) \ + --version=$(python3 setup.py --version) \ + --language=$(jq --raw-output '.language // empty' .repo-metadata.json) \ + --distribution-name=$(python3 setup.py --name) \ + --product-page=$(jq --raw-output '.product_documentation // empty' .repo-metadata.json) \ + --github-repository=$(jq --raw-output '.repo // empty' .repo-metadata.json) \ + --issue-tracker=$(jq --raw-output '.issue_tracker // empty' .repo-metadata.json) + +cat docs.metadata + +# upload docs +python3 -m docuploader upload docs/_build/html/docfx_yaml --metadata-file docs.metadata --destination-prefix docfx --staging-bucket "${V2_STAGING_BUCKET}" diff --git a/.kokoro/trampoline_v2.sh b/.kokoro/trampoline_v2.sh new file mode 100755 index 00000000..719bcd5b --- /dev/null +++ b/.kokoro/trampoline_v2.sh @@ -0,0 +1,487 @@ +#!/usr/bin/env 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. + +# trampoline_v2.sh +# +# This script does 3 things. +# +# 1. Prepare the Docker image for the test +# 2. Run the Docker with appropriate flags to run the test +# 3. Upload the newly built Docker image +# +# in a way that is somewhat compatible with trampoline_v1. +# +# To run this script, first download few files from gcs to /dev/shm. +# (/dev/shm is passed into the container as KOKORO_GFILE_DIR). +# +# gsutil cp gs://cloud-devrel-kokoro-resources/python-docs-samples/secrets_viewer_service_account.json /dev/shm +# gsutil cp gs://cloud-devrel-kokoro-resources/python-docs-samples/automl_secrets.txt /dev/shm +# +# Then run the script. +# .kokoro/trampoline_v2.sh +# +# These environment variables are required: +# TRAMPOLINE_IMAGE: The docker image to use. +# TRAMPOLINE_DOCKERFILE: The location of the Dockerfile. +# +# You can optionally change these environment variables: +# TRAMPOLINE_IMAGE_UPLOAD: +# (true|false): Whether to upload the Docker image after the +# successful builds. +# TRAMPOLINE_BUILD_FILE: The script to run in the docker container. +# TRAMPOLINE_WORKSPACE: The workspace path in the docker container. +# Defaults to /workspace. +# Potentially there are some repo specific envvars in .trampolinerc in +# the project root. + + +set -euo pipefail + +TRAMPOLINE_VERSION="2.0.5" + +if command -v tput >/dev/null && [[ -n "${TERM:-}" ]]; then + readonly IO_COLOR_RED="$(tput setaf 1)" + readonly IO_COLOR_GREEN="$(tput setaf 2)" + readonly IO_COLOR_YELLOW="$(tput setaf 3)" + readonly IO_COLOR_RESET="$(tput sgr0)" +else + readonly IO_COLOR_RED="" + readonly IO_COLOR_GREEN="" + readonly IO_COLOR_YELLOW="" + readonly IO_COLOR_RESET="" +fi + +function function_exists { + [ $(LC_ALL=C type -t $1)"" == "function" ] +} + +# Logs a message using the given color. The first argument must be one +# of the IO_COLOR_* variables defined above, such as +# "${IO_COLOR_YELLOW}". The remaining arguments will be logged in the +# given color. The log message will also have an RFC-3339 timestamp +# prepended (in UTC). You can disable the color output by setting +# TERM=vt100. +function log_impl() { + local color="$1" + shift + local timestamp="$(date -u "+%Y-%m-%dT%H:%M:%SZ")" + echo "================================================================" + echo "${color}${timestamp}:" "$@" "${IO_COLOR_RESET}" + echo "================================================================" +} + +# Logs the given message with normal coloring and a timestamp. +function log() { + log_impl "${IO_COLOR_RESET}" "$@" +} + +# Logs the given message in green with a timestamp. +function log_green() { + log_impl "${IO_COLOR_GREEN}" "$@" +} + +# Logs the given message in yellow with a timestamp. +function log_yellow() { + log_impl "${IO_COLOR_YELLOW}" "$@" +} + +# Logs the given message in red with a timestamp. +function log_red() { + log_impl "${IO_COLOR_RED}" "$@" +} + +readonly tmpdir=$(mktemp -d -t ci-XXXXXXXX) +readonly tmphome="${tmpdir}/h" +mkdir -p "${tmphome}" + +function cleanup() { + rm -rf "${tmpdir}" +} +trap cleanup EXIT + +RUNNING_IN_CI="${RUNNING_IN_CI:-false}" + +# The workspace in the container, defaults to /workspace. +TRAMPOLINE_WORKSPACE="${TRAMPOLINE_WORKSPACE:-/workspace}" + +pass_down_envvars=( + # TRAMPOLINE_V2 variables. + # Tells scripts whether they are running as part of CI or not. + "RUNNING_IN_CI" + # Indicates which CI system we're in. + "TRAMPOLINE_CI" + # Indicates the version of the script. + "TRAMPOLINE_VERSION" +) + +log_yellow "Building with Trampoline ${TRAMPOLINE_VERSION}" + +# Detect which CI systems we're in. If we're in any of the CI systems +# we support, `RUNNING_IN_CI` will be true and `TRAMPOLINE_CI` will be +# the name of the CI system. Both envvars will be passing down to the +# container for telling which CI system we're in. +if [[ -n "${KOKORO_BUILD_ID:-}" ]]; then + # descriptive env var for indicating it's on CI. + RUNNING_IN_CI="true" + TRAMPOLINE_CI="kokoro" + if [[ "${TRAMPOLINE_USE_LEGACY_SERVICE_ACCOUNT:-}" == "true" ]]; then + if [[ ! -f "${KOKORO_GFILE_DIR}/kokoro-trampoline.service-account.json" ]]; then + log_red "${KOKORO_GFILE_DIR}/kokoro-trampoline.service-account.json does not exist. Did you forget to mount cloud-devrel-kokoro-resources/trampoline? Aborting." + exit 1 + fi + # This service account will be activated later. + TRAMPOLINE_SERVICE_ACCOUNT="${KOKORO_GFILE_DIR}/kokoro-trampoline.service-account.json" + else + if [[ "${TRAMPOLINE_VERBOSE:-}" == "true" ]]; then + gcloud auth list + fi + log_yellow "Configuring Container Registry access" + gcloud auth configure-docker --quiet + fi + pass_down_envvars+=( + # KOKORO dynamic variables. + "KOKORO_BUILD_NUMBER" + "KOKORO_BUILD_ID" + "KOKORO_JOB_NAME" + "KOKORO_GIT_COMMIT" + "KOKORO_GITHUB_COMMIT" + "KOKORO_GITHUB_PULL_REQUEST_NUMBER" + "KOKORO_GITHUB_PULL_REQUEST_COMMIT" + # For Build Cop Bot + "KOKORO_GITHUB_COMMIT_URL" + "KOKORO_GITHUB_PULL_REQUEST_URL" + ) +elif [[ "${TRAVIS:-}" == "true" ]]; then + RUNNING_IN_CI="true" + TRAMPOLINE_CI="travis" + pass_down_envvars+=( + "TRAVIS_BRANCH" + "TRAVIS_BUILD_ID" + "TRAVIS_BUILD_NUMBER" + "TRAVIS_BUILD_WEB_URL" + "TRAVIS_COMMIT" + "TRAVIS_COMMIT_MESSAGE" + "TRAVIS_COMMIT_RANGE" + "TRAVIS_JOB_NAME" + "TRAVIS_JOB_NUMBER" + "TRAVIS_JOB_WEB_URL" + "TRAVIS_PULL_REQUEST" + "TRAVIS_PULL_REQUEST_BRANCH" + "TRAVIS_PULL_REQUEST_SHA" + "TRAVIS_PULL_REQUEST_SLUG" + "TRAVIS_REPO_SLUG" + "TRAVIS_SECURE_ENV_VARS" + "TRAVIS_TAG" + ) +elif [[ -n "${GITHUB_RUN_ID:-}" ]]; then + RUNNING_IN_CI="true" + TRAMPOLINE_CI="github-workflow" + pass_down_envvars+=( + "GITHUB_WORKFLOW" + "GITHUB_RUN_ID" + "GITHUB_RUN_NUMBER" + "GITHUB_ACTION" + "GITHUB_ACTIONS" + "GITHUB_ACTOR" + "GITHUB_REPOSITORY" + "GITHUB_EVENT_NAME" + "GITHUB_EVENT_PATH" + "GITHUB_SHA" + "GITHUB_REF" + "GITHUB_HEAD_REF" + "GITHUB_BASE_REF" + ) +elif [[ "${CIRCLECI:-}" == "true" ]]; then + RUNNING_IN_CI="true" + TRAMPOLINE_CI="circleci" + pass_down_envvars+=( + "CIRCLE_BRANCH" + "CIRCLE_BUILD_NUM" + "CIRCLE_BUILD_URL" + "CIRCLE_COMPARE_URL" + "CIRCLE_JOB" + "CIRCLE_NODE_INDEX" + "CIRCLE_NODE_TOTAL" + "CIRCLE_PREVIOUS_BUILD_NUM" + "CIRCLE_PROJECT_REPONAME" + "CIRCLE_PROJECT_USERNAME" + "CIRCLE_REPOSITORY_URL" + "CIRCLE_SHA1" + "CIRCLE_STAGE" + "CIRCLE_USERNAME" + "CIRCLE_WORKFLOW_ID" + "CIRCLE_WORKFLOW_JOB_ID" + "CIRCLE_WORKFLOW_UPSTREAM_JOB_IDS" + "CIRCLE_WORKFLOW_WORKSPACE_ID" + ) +fi + +# Configure the service account for pulling the docker image. +function repo_root() { + local dir="$1" + while [[ ! -d "${dir}/.git" ]]; do + dir="$(dirname "$dir")" + done + echo "${dir}" +} + +# Detect the project root. In CI builds, we assume the script is in +# the git tree and traverse from there, otherwise, traverse from `pwd` +# to find `.git` directory. +if [[ "${RUNNING_IN_CI:-}" == "true" ]]; then + PROGRAM_PATH="$(realpath "$0")" + PROGRAM_DIR="$(dirname "${PROGRAM_PATH}")" + PROJECT_ROOT="$(repo_root "${PROGRAM_DIR}")" +else + PROJECT_ROOT="$(repo_root $(pwd))" +fi + +log_yellow "Changing to the project root: ${PROJECT_ROOT}." +cd "${PROJECT_ROOT}" + +# To support relative path for `TRAMPOLINE_SERVICE_ACCOUNT`, we need +# to use this environment variable in `PROJECT_ROOT`. +if [[ -n "${TRAMPOLINE_SERVICE_ACCOUNT:-}" ]]; then + + mkdir -p "${tmpdir}/gcloud" + gcloud_config_dir="${tmpdir}/gcloud" + + log_yellow "Using isolated gcloud config: ${gcloud_config_dir}." + export CLOUDSDK_CONFIG="${gcloud_config_dir}" + + log_yellow "Using ${TRAMPOLINE_SERVICE_ACCOUNT} for authentication." + gcloud auth activate-service-account \ + --key-file "${TRAMPOLINE_SERVICE_ACCOUNT}" + log_yellow "Configuring Container Registry access" + gcloud auth configure-docker --quiet +fi + +required_envvars=( + # The basic trampoline configurations. + "TRAMPOLINE_IMAGE" + "TRAMPOLINE_BUILD_FILE" +) + +if [[ -f "${PROJECT_ROOT}/.trampolinerc" ]]; then + source "${PROJECT_ROOT}/.trampolinerc" +fi + +log_yellow "Checking environment variables." +for e in "${required_envvars[@]}" +do + if [[ -z "${!e:-}" ]]; then + log "Missing ${e} env var. Aborting." + exit 1 + fi +done + +# We want to support legacy style TRAMPOLINE_BUILD_FILE used with V1 +# script: e.g. "github/repo-name/.kokoro/run_tests.sh" +TRAMPOLINE_BUILD_FILE="${TRAMPOLINE_BUILD_FILE#github/*/}" +log_yellow "Using TRAMPOLINE_BUILD_FILE: ${TRAMPOLINE_BUILD_FILE}" + +# ignore error on docker operations and test execution +set +e + +log_yellow "Preparing Docker image." +# We only download the docker image in CI builds. +if [[ "${RUNNING_IN_CI:-}" == "true" ]]; then + # Download the docker image specified by `TRAMPOLINE_IMAGE` + + # We may want to add --max-concurrent-downloads flag. + + log_yellow "Start pulling the Docker image: ${TRAMPOLINE_IMAGE}." + if docker pull "${TRAMPOLINE_IMAGE}"; then + log_green "Finished pulling the Docker image: ${TRAMPOLINE_IMAGE}." + has_image="true" + else + log_red "Failed pulling the Docker image: ${TRAMPOLINE_IMAGE}." + has_image="false" + fi +else + # For local run, check if we have the image. + if docker images "${TRAMPOLINE_IMAGE}:latest" | grep "${TRAMPOLINE_IMAGE}"; then + has_image="true" + else + has_image="false" + fi +fi + + +# The default user for a Docker container has uid 0 (root). To avoid +# creating root-owned files in the build directory we tell docker to +# use the current user ID. +user_uid="$(id -u)" +user_gid="$(id -g)" +user_name="$(id -un)" + +# To allow docker in docker, we add the user to the docker group in +# the host os. +docker_gid=$(cut -d: -f3 < <(getent group docker)) + +update_cache="false" +if [[ "${TRAMPOLINE_DOCKERFILE:-none}" != "none" ]]; then + # Build the Docker image from the source. + context_dir=$(dirname "${TRAMPOLINE_DOCKERFILE}") + docker_build_flags=( + "-f" "${TRAMPOLINE_DOCKERFILE}" + "-t" "${TRAMPOLINE_IMAGE}" + "--build-arg" "UID=${user_uid}" + "--build-arg" "USERNAME=${user_name}" + ) + if [[ "${has_image}" == "true" ]]; then + docker_build_flags+=("--cache-from" "${TRAMPOLINE_IMAGE}") + fi + + log_yellow "Start building the docker image." + if [[ "${TRAMPOLINE_VERBOSE:-false}" == "true" ]]; then + echo "docker build" "${docker_build_flags[@]}" "${context_dir}" + fi + + # ON CI systems, we want to suppress docker build logs, only + # output the logs when it fails. + if [[ "${RUNNING_IN_CI:-}" == "true" ]]; then + if docker build "${docker_build_flags[@]}" "${context_dir}" \ + > "${tmpdir}/docker_build.log" 2>&1; then + if [[ "${TRAMPOLINE_VERBOSE:-}" == "true" ]]; then + cat "${tmpdir}/docker_build.log" + fi + + log_green "Finished building the docker image." + update_cache="true" + else + log_red "Failed to build the Docker image, aborting." + log_yellow "Dumping the build logs:" + cat "${tmpdir}/docker_build.log" + exit 1 + fi + else + if docker build "${docker_build_flags[@]}" "${context_dir}"; then + log_green "Finished building the docker image." + update_cache="true" + else + log_red "Failed to build the Docker image, aborting." + exit 1 + fi + fi +else + if [[ "${has_image}" != "true" ]]; then + log_red "We do not have ${TRAMPOLINE_IMAGE} locally, aborting." + exit 1 + fi +fi + +# We use an array for the flags so they are easier to document. +docker_flags=( + # Remove the container after it exists. + "--rm" + + # Use the host network. + "--network=host" + + # Run in priviledged mode. We are not using docker for sandboxing or + # isolation, just for packaging our dev tools. + "--privileged" + + # Run the docker script with the user id. Because the docker image gets to + # write in ${PWD} you typically want this to be your user id. + # To allow docker in docker, we need to use docker gid on the host. + "--user" "${user_uid}:${docker_gid}" + + # Pass down the USER. + "--env" "USER=${user_name}" + + # Mount the project directory inside the Docker container. + "--volume" "${PROJECT_ROOT}:${TRAMPOLINE_WORKSPACE}" + "--workdir" "${TRAMPOLINE_WORKSPACE}" + "--env" "PROJECT_ROOT=${TRAMPOLINE_WORKSPACE}" + + # Mount the temporary home directory. + "--volume" "${tmphome}:/h" + "--env" "HOME=/h" + + # Allow docker in docker. + "--volume" "/var/run/docker.sock:/var/run/docker.sock" + + # Mount the /tmp so that docker in docker can mount the files + # there correctly. + "--volume" "/tmp:/tmp" + # Pass down the KOKORO_GFILE_DIR and KOKORO_KEYSTORE_DIR + # TODO(tmatsuo): This part is not portable. + "--env" "TRAMPOLINE_SECRET_DIR=/secrets" + "--volume" "${KOKORO_GFILE_DIR:-/dev/shm}:/secrets/gfile" + "--env" "KOKORO_GFILE_DIR=/secrets/gfile" + "--volume" "${KOKORO_KEYSTORE_DIR:-/dev/shm}:/secrets/keystore" + "--env" "KOKORO_KEYSTORE_DIR=/secrets/keystore" +) + +# Add an option for nicer output if the build gets a tty. +if [[ -t 0 ]]; then + docker_flags+=("-it") +fi + +# Passing down env vars +for e in "${pass_down_envvars[@]}" +do + if [[ -n "${!e:-}" ]]; then + docker_flags+=("--env" "${e}=${!e}") + fi +done + +# If arguments are given, all arguments will become the commands run +# in the container, otherwise run TRAMPOLINE_BUILD_FILE. +if [[ $# -ge 1 ]]; then + log_yellow "Running the given commands '" "${@:1}" "' in the container." + readonly commands=("${@:1}") + if [[ "${TRAMPOLINE_VERBOSE:-}" == "true" ]]; then + echo docker run "${docker_flags[@]}" "${TRAMPOLINE_IMAGE}" "${commands[@]}" + fi + docker run "${docker_flags[@]}" "${TRAMPOLINE_IMAGE}" "${commands[@]}" +else + log_yellow "Running the tests in a Docker container." + docker_flags+=("--entrypoint=${TRAMPOLINE_BUILD_FILE}") + if [[ "${TRAMPOLINE_VERBOSE:-}" == "true" ]]; then + echo docker run "${docker_flags[@]}" "${TRAMPOLINE_IMAGE}" + fi + docker run "${docker_flags[@]}" "${TRAMPOLINE_IMAGE}" +fi + + +test_retval=$? + +if [[ ${test_retval} -eq 0 ]]; then + log_green "Build finished with ${test_retval}" +else + log_red "Build finished with ${test_retval}" +fi + +# Only upload it when the test passes. +if [[ "${update_cache}" == "true" ]] && \ + [[ $test_retval == 0 ]] && \ + [[ "${TRAMPOLINE_IMAGE_UPLOAD:-false}" == "true" ]]; then + log_yellow "Uploading the Docker image." + if docker push "${TRAMPOLINE_IMAGE}"; then + log_green "Finished uploading the Docker image." + else + log_red "Failed uploading the Docker image." + fi + # Call trampoline_after_upload_hook if it's defined. + if function_exists trampoline_after_upload_hook; then + trampoline_after_upload_hook + fi + +fi + +exit "${test_retval}" diff --git a/.trampolinerc b/.trampolinerc new file mode 100644 index 00000000..995ee291 --- /dev/null +++ b/.trampolinerc @@ -0,0 +1,51 @@ +# 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. + +# Template for .trampolinerc + +# Add required env vars here. +required_envvars+=( + "STAGING_BUCKET" + "V2_STAGING_BUCKET" +) + +# Add env vars which are passed down into the container here. +pass_down_envvars+=( + "STAGING_BUCKET" + "V2_STAGING_BUCKET" +) + +# Prevent unintentional override on the default image. +if [[ "${TRAMPOLINE_IMAGE_UPLOAD:-false}" == "true" ]] && \ + [[ -z "${TRAMPOLINE_IMAGE:-}" ]]; then + echo "Please set TRAMPOLINE_IMAGE if you want to upload the Docker image." + exit 1 +fi + +# Define the default value if it makes sense. +if [[ -z "${TRAMPOLINE_IMAGE_UPLOAD:-}" ]]; then + TRAMPOLINE_IMAGE_UPLOAD="" +fi + +if [[ -z "${TRAMPOLINE_IMAGE:-}" ]]; then + TRAMPOLINE_IMAGE="" +fi + +if [[ -z "${TRAMPOLINE_DOCKERFILE:-}" ]]; then + TRAMPOLINE_DOCKERFILE="" +fi + +if [[ -z "${TRAMPOLINE_BUILD_FILE:-}" ]]; then + TRAMPOLINE_BUILD_FILE="" +fi diff --git a/docs/conf.py b/docs/conf.py index af91f6e5..755f4854 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -20,6 +20,10 @@ # documentation root, use os.path.abspath to make it absolute, like shown here. sys.path.insert(0, os.path.abspath("..")) +# For plugins that can not read conf.py. +# See also: https://github.com/docascode/sphinx-docfx-yaml/issues/85 +sys.path.insert(0, os.path.abspath(".")) + __version__ = "" # -- General configuration ------------------------------------------------ @@ -90,7 +94,12 @@ # List of patterns, relative to source directory, that match files and # directories to ignore when looking for source files. -exclude_patterns = ["_build"] +exclude_patterns = [ + "_build", + "samples/AUTHORING_GUIDE.md", + "samples/CONTRIBUTING.md", + "samples/snippets/README.rst", +] # The reST default role (used for this markup: `text`) to use for all # documents. diff --git a/noxfile.py b/noxfile.py index 0889d616..1116c841 100644 --- a/noxfile.py +++ b/noxfile.py @@ -100,6 +100,10 @@ def system(session): """Run the system test suite.""" system_test_path = os.path.join("tests", "system.py") system_test_folder_path = os.path.join("tests", "system") + + # Check the value of `RUN_SYSTEM_TESTS` env var. It defaults to true. + if os.environ.get("RUN_SYSTEM_TESTS", "true") == "false": + session.skip("RUN_SYSTEM_TESTS is set to false, skipping") # Sanity check: Only run tests if the environment variable is set. if not os.environ.get("GOOGLE_APPLICATION_CREDENTIALS", ""): session.skip("Credentials must be set via environment variable") @@ -161,3 +165,36 @@ def docs(session): os.path.join("docs", ""), os.path.join("docs", "_build", "html", ""), ) + + +@nox.session(python=DEFAULT_PYTHON_VERSION) +def docfx(session): + """Build the docfx yaml files for this library.""" + + session.install("-e", ".") + session.install("sphinx<3.0.0", "alabaster", "recommonmark", "sphinx-docfx-yaml") + + shutil.rmtree(os.path.join("docs", "_build"), ignore_errors=True) + session.run( + "sphinx-build", + "-T", # show full traceback on exception + "-N", # no colors + "-D", + ( + "extensions=sphinx.ext.autodoc," + "sphinx.ext.autosummary," + "docfx_yaml.extension," + "sphinx.ext.intersphinx," + "sphinx.ext.coverage," + "sphinx.ext.napoleon," + "sphinx.ext.todo," + "sphinx.ext.viewcode," + "recommonmark" + ), + "-b", + "html", + "-d", + os.path.join("docs", "_build", "doctrees", ""), + os.path.join("docs", ""), + os.path.join("docs", "_build", "html", ""), + ) diff --git a/samples/snippets/api/noxfile.py b/samples/snippets/api/noxfile.py new file mode 100644 index 00000000..ba55d7ce --- /dev/null +++ b/samples/snippets/api/noxfile.py @@ -0,0 +1,224 @@ +# Copyright 2019 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. + +from __future__ import print_function + +import os +from pathlib import Path +import sys + +import nox + + +# WARNING - WARNING - WARNING - WARNING - WARNING +# WARNING - WARNING - WARNING - WARNING - WARNING +# DO NOT EDIT THIS FILE EVER! +# WARNING - WARNING - WARNING - WARNING - WARNING +# WARNING - WARNING - WARNING - WARNING - WARNING + +# Copy `noxfile_config.py` to your directory and modify it instead. + + +# `TEST_CONFIG` dict is a configuration hook that allows users to +# modify the test configurations. The values here should be in sync +# with `noxfile_config.py`. Users will copy `noxfile_config.py` into +# their directory and modify it. + +TEST_CONFIG = { + # You can opt out from the test for specific Python versions. + 'ignored_versions': ["2.7"], + + # An envvar key for determining the project id to use. Change it + # to 'BUILD_SPECIFIC_GCLOUD_PROJECT' if you want to opt in using a + # build specific Cloud project. You can also use your own string + # to use your own Cloud project. + 'gcloud_project_env': 'GOOGLE_CLOUD_PROJECT', + # 'gcloud_project_env': 'BUILD_SPECIFIC_GCLOUD_PROJECT', + + # A dictionary you want to inject into your test. Don't put any + # secrets here. These values will override predefined values. + 'envs': {}, +} + + +try: + # Ensure we can import noxfile_config in the project's directory. + sys.path.append('.') + from noxfile_config import TEST_CONFIG_OVERRIDE +except ImportError as e: + print("No user noxfile_config found: detail: {}".format(e)) + TEST_CONFIG_OVERRIDE = {} + +# Update the TEST_CONFIG with the user supplied values. +TEST_CONFIG.update(TEST_CONFIG_OVERRIDE) + + +def get_pytest_env_vars(): + """Returns a dict for pytest invocation.""" + ret = {} + + # Override the GCLOUD_PROJECT and the alias. + env_key = TEST_CONFIG['gcloud_project_env'] + # This should error out if not set. + ret['GOOGLE_CLOUD_PROJECT'] = os.environ[env_key] + + # Apply user supplied envs. + ret.update(TEST_CONFIG['envs']) + return ret + + +# DO NOT EDIT - automatically generated. +# All versions used to tested samples. +ALL_VERSIONS = ["2.7", "3.6", "3.7", "3.8"] + +# Any default versions that should be ignored. +IGNORED_VERSIONS = TEST_CONFIG['ignored_versions'] + +TESTED_VERSIONS = sorted([v for v in ALL_VERSIONS if v not in IGNORED_VERSIONS]) + +INSTALL_LIBRARY_FROM_SOURCE = bool(os.environ.get("INSTALL_LIBRARY_FROM_SOURCE", False)) +# +# Style Checks +# + + +def _determine_local_import_names(start_dir): + """Determines all import names that should be considered "local". + + This is used when running the linter to insure that import order is + properly checked. + """ + file_ext_pairs = [os.path.splitext(path) for path in os.listdir(start_dir)] + return [ + basename + for basename, extension in file_ext_pairs + if extension == ".py" + or os.path.isdir(os.path.join(start_dir, basename)) + and basename not in ("__pycache__") + ] + + +# Linting with flake8. +# +# We ignore the following rules: +# E203: whitespace before ‘:’ +# E266: too many leading ‘#’ for block comment +# E501: line too long +# I202: Additional newline in a section of imports +# +# We also need to specify the rules which are ignored by default: +# ['E226', 'W504', 'E126', 'E123', 'W503', 'E24', 'E704', 'E121'] +FLAKE8_COMMON_ARGS = [ + "--show-source", + "--builtin=gettext", + "--max-complexity=20", + "--import-order-style=google", + "--exclude=.nox,.cache,env,lib,generated_pb2,*_pb2.py,*_pb2_grpc.py", + "--ignore=E121,E123,E126,E203,E226,E24,E266,E501,E704,W503,W504,I202", + "--max-line-length=88", +] + + +@nox.session +def lint(session): + session.install("flake8", "flake8-import-order") + + local_names = _determine_local_import_names(".") + args = FLAKE8_COMMON_ARGS + [ + "--application-import-names", + ",".join(local_names), + "." + ] + session.run("flake8", *args) + + +# +# Sample Tests +# + + +PYTEST_COMMON_ARGS = ["--junitxml=sponge_log.xml"] + + +def _session_tests(session, post_install=None): + """Runs py.test for a particular project.""" + if os.path.exists("requirements.txt"): + session.install("-r", "requirements.txt") + + if os.path.exists("requirements-test.txt"): + session.install("-r", "requirements-test.txt") + + if INSTALL_LIBRARY_FROM_SOURCE: + session.install("-e", _get_repo_root()) + + if post_install: + post_install(session) + + session.run( + "pytest", + *(PYTEST_COMMON_ARGS + session.posargs), + # Pytest will return 5 when no tests are collected. This can happen + # on travis where slow and flaky tests are excluded. + # See http://doc.pytest.org/en/latest/_modules/_pytest/main.html + success_codes=[0, 5], + env=get_pytest_env_vars() + ) + + +@nox.session(python=ALL_VERSIONS) +def py(session): + """Runs py.test for a sample using the specified version of Python.""" + if session.python in TESTED_VERSIONS: + _session_tests(session) + else: + session.skip("SKIPPED: {} tests are disabled for this sample.".format( + session.python + )) + + +# +# Readmegen +# + + +def _get_repo_root(): + """ Returns the root folder of the project. """ + # Get root of this repository. Assume we don't have directories nested deeper than 10 items. + p = Path(os.getcwd()) + for i in range(10): + if p is None: + break + if Path(p / ".git").exists(): + return str(p) + p = p.parent + raise Exception("Unable to detect repository root.") + + +GENERATED_READMES = sorted([x for x in Path(".").rglob("*.rst.in")]) + + +@nox.session +@nox.parametrize("path", GENERATED_READMES) +def readmegen(session, path): + """(Re-)generates the readme for a sample.""" + session.install("jinja2", "pyyaml") + dir_ = os.path.dirname(path) + + if os.path.exists(os.path.join(dir_, "requirements.txt")): + session.install("-r", os.path.join(dir_, "requirements.txt")) + + in_file = os.path.join(dir_, "README.rst.in") + session.run( + "python", _get_repo_root() + "/scripts/readme-gen/readme_gen.py", in_file + ) diff --git a/samples/snippets/fluent_on_compute/noxfile.py b/samples/snippets/fluent_on_compute/noxfile.py new file mode 100644 index 00000000..ba55d7ce --- /dev/null +++ b/samples/snippets/fluent_on_compute/noxfile.py @@ -0,0 +1,224 @@ +# Copyright 2019 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. + +from __future__ import print_function + +import os +from pathlib import Path +import sys + +import nox + + +# WARNING - WARNING - WARNING - WARNING - WARNING +# WARNING - WARNING - WARNING - WARNING - WARNING +# DO NOT EDIT THIS FILE EVER! +# WARNING - WARNING - WARNING - WARNING - WARNING +# WARNING - WARNING - WARNING - WARNING - WARNING + +# Copy `noxfile_config.py` to your directory and modify it instead. + + +# `TEST_CONFIG` dict is a configuration hook that allows users to +# modify the test configurations. The values here should be in sync +# with `noxfile_config.py`. Users will copy `noxfile_config.py` into +# their directory and modify it. + +TEST_CONFIG = { + # You can opt out from the test for specific Python versions. + 'ignored_versions': ["2.7"], + + # An envvar key for determining the project id to use. Change it + # to 'BUILD_SPECIFIC_GCLOUD_PROJECT' if you want to opt in using a + # build specific Cloud project. You can also use your own string + # to use your own Cloud project. + 'gcloud_project_env': 'GOOGLE_CLOUD_PROJECT', + # 'gcloud_project_env': 'BUILD_SPECIFIC_GCLOUD_PROJECT', + + # A dictionary you want to inject into your test. Don't put any + # secrets here. These values will override predefined values. + 'envs': {}, +} + + +try: + # Ensure we can import noxfile_config in the project's directory. + sys.path.append('.') + from noxfile_config import TEST_CONFIG_OVERRIDE +except ImportError as e: + print("No user noxfile_config found: detail: {}".format(e)) + TEST_CONFIG_OVERRIDE = {} + +# Update the TEST_CONFIG with the user supplied values. +TEST_CONFIG.update(TEST_CONFIG_OVERRIDE) + + +def get_pytest_env_vars(): + """Returns a dict for pytest invocation.""" + ret = {} + + # Override the GCLOUD_PROJECT and the alias. + env_key = TEST_CONFIG['gcloud_project_env'] + # This should error out if not set. + ret['GOOGLE_CLOUD_PROJECT'] = os.environ[env_key] + + # Apply user supplied envs. + ret.update(TEST_CONFIG['envs']) + return ret + + +# DO NOT EDIT - automatically generated. +# All versions used to tested samples. +ALL_VERSIONS = ["2.7", "3.6", "3.7", "3.8"] + +# Any default versions that should be ignored. +IGNORED_VERSIONS = TEST_CONFIG['ignored_versions'] + +TESTED_VERSIONS = sorted([v for v in ALL_VERSIONS if v not in IGNORED_VERSIONS]) + +INSTALL_LIBRARY_FROM_SOURCE = bool(os.environ.get("INSTALL_LIBRARY_FROM_SOURCE", False)) +# +# Style Checks +# + + +def _determine_local_import_names(start_dir): + """Determines all import names that should be considered "local". + + This is used when running the linter to insure that import order is + properly checked. + """ + file_ext_pairs = [os.path.splitext(path) for path in os.listdir(start_dir)] + return [ + basename + for basename, extension in file_ext_pairs + if extension == ".py" + or os.path.isdir(os.path.join(start_dir, basename)) + and basename not in ("__pycache__") + ] + + +# Linting with flake8. +# +# We ignore the following rules: +# E203: whitespace before ‘:’ +# E266: too many leading ‘#’ for block comment +# E501: line too long +# I202: Additional newline in a section of imports +# +# We also need to specify the rules which are ignored by default: +# ['E226', 'W504', 'E126', 'E123', 'W503', 'E24', 'E704', 'E121'] +FLAKE8_COMMON_ARGS = [ + "--show-source", + "--builtin=gettext", + "--max-complexity=20", + "--import-order-style=google", + "--exclude=.nox,.cache,env,lib,generated_pb2,*_pb2.py,*_pb2_grpc.py", + "--ignore=E121,E123,E126,E203,E226,E24,E266,E501,E704,W503,W504,I202", + "--max-line-length=88", +] + + +@nox.session +def lint(session): + session.install("flake8", "flake8-import-order") + + local_names = _determine_local_import_names(".") + args = FLAKE8_COMMON_ARGS + [ + "--application-import-names", + ",".join(local_names), + "." + ] + session.run("flake8", *args) + + +# +# Sample Tests +# + + +PYTEST_COMMON_ARGS = ["--junitxml=sponge_log.xml"] + + +def _session_tests(session, post_install=None): + """Runs py.test for a particular project.""" + if os.path.exists("requirements.txt"): + session.install("-r", "requirements.txt") + + if os.path.exists("requirements-test.txt"): + session.install("-r", "requirements-test.txt") + + if INSTALL_LIBRARY_FROM_SOURCE: + session.install("-e", _get_repo_root()) + + if post_install: + post_install(session) + + session.run( + "pytest", + *(PYTEST_COMMON_ARGS + session.posargs), + # Pytest will return 5 when no tests are collected. This can happen + # on travis where slow and flaky tests are excluded. + # See http://doc.pytest.org/en/latest/_modules/_pytest/main.html + success_codes=[0, 5], + env=get_pytest_env_vars() + ) + + +@nox.session(python=ALL_VERSIONS) +def py(session): + """Runs py.test for a sample using the specified version of Python.""" + if session.python in TESTED_VERSIONS: + _session_tests(session) + else: + session.skip("SKIPPED: {} tests are disabled for this sample.".format( + session.python + )) + + +# +# Readmegen +# + + +def _get_repo_root(): + """ Returns the root folder of the project. """ + # Get root of this repository. Assume we don't have directories nested deeper than 10 items. + p = Path(os.getcwd()) + for i in range(10): + if p is None: + break + if Path(p / ".git").exists(): + return str(p) + p = p.parent + raise Exception("Unable to detect repository root.") + + +GENERATED_READMES = sorted([x for x in Path(".").rglob("*.rst.in")]) + + +@nox.session +@nox.parametrize("path", GENERATED_READMES) +def readmegen(session, path): + """(Re-)generates the readme for a sample.""" + session.install("jinja2", "pyyaml") + dir_ = os.path.dirname(path) + + if os.path.exists(os.path.join(dir_, "requirements.txt")): + session.install("-r", os.path.join(dir_, "requirements.txt")) + + in_file = os.path.join(dir_, "README.rst.in") + session.run( + "python", _get_repo_root() + "/scripts/readme-gen/readme_gen.py", in_file + ) diff --git a/synth.metadata b/synth.metadata index ccbf1f4d..7f27343f 100644 --- a/synth.metadata +++ b/synth.metadata @@ -4,22 +4,21 @@ "git": { "name": ".", "remote": "https://github.com/googleapis/python-error-reporting.git", - "sha": "840d67c09502ae99ce4771c66bde1cefb961a367" + "sha": "397c0f8fb57b31a2c74f0cfc410a017e6e3ae712" } }, { "git": { - "name": "googleapis", - "remote": "https://github.com/googleapis/googleapis.git", - "sha": "5202cfe3e5c2907a1a21a4c6d4bd0812029b6aa3", - "internalRef": "319247865" + "name": "synthtool", + "remote": "https://github.com/googleapis/synthtool.git", + "sha": "5747555f7620113d9a2078a48f4c047a99d31b3e" } }, { "git": { "name": "synthtool", "remote": "https://github.com/googleapis/synthtool.git", - "sha": "303271797a360f8a439203413f13a160f2f5b3b4" + "sha": "5747555f7620113d9a2078a48f4c047a99d31b3e" } } ], diff --git a/synth.py b/synth.py index dc6e7550..089acd53 100644 --- a/synth.py +++ b/synth.py @@ -15,6 +15,7 @@ """This script is used to synthesize generated parts of this library.""" import synthtool as s from synthtool import gcp +from synthtool.languages import python gapic = gcp.GAPICBazel() common = gcp.CommonTemplates() @@ -117,10 +118,18 @@ # Add templated files # ---------------------------------------------------------------------------- templated_files = common.py_library( - unit_cov_level=97, cov_level=98, system_test_dependencies=["test_utils"] + samples=True, + unit_cov_level=97, + cov_level=98, + system_test_dependencies=["test_utils"] ) s.move(templated_files) +# ---------------------------------------------------------------------------- +# Samples templates +# ---------------------------------------------------------------------------- +python.py_samples(skip_readmes=True) + # TODO(busunkim): Use latest sphinx after microgenerator transition s.replace("noxfile.py", """['"]sphinx['"]""", '"sphinx<3.0.0"')