From d792f6368571e99a6242f078d58660e9496ac5e6 Mon Sep 17 00:00:00 2001 From: arithmetic1728 <58957152+arithmetic1728@users.noreply.github.com> Date: Mon, 31 Aug 2020 16:22:15 -0700 Subject: [PATCH 01/62] docs: add samples from python-docs-samples/tasks (#36) * Add samples for Cloud Tasks [(#1068)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/1068) * Add samples for Cloud Tasks * Respond to tasks sample review * Update app engine queues samples * Address review feedback * Address review issues and convert pull queue sample to not use API key auth * Reform pull queues to match appengine queues changes to auth, command line input, readme * flake8 and fix comment * Fix Tasks sample test issues. * Remove queue.yaml, now unused * Add required flag on certain arguments to command-line tools * Auto-update dependencies. [(#1116)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/1116) * Auto-update dependencies. [(#1133)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/1133) * Auto-update dependencies. * Fix missing http library Change-Id: I99faa600f2f3f1f50f57694fc9835d7f35bda250 * Update Task Queue samples for beta * Use full import to get client * Auto-update dependencies. [(#1186)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/1186) * Auto-update dependencies. [(#1217)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/1217) * Added "Open in Cloud Shell" buttons to README files [(#1254)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/1254) * Add comments and region tags to Cloud Tasks samples [(#1271)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/1271) * Standardize on CamelCase, reword confusing endpoint name [(#1288)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/1288) * Auto-update dependencies. [(#1309)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/1309) * Rename pull to lease and fix name/parent confusion [(#1311)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/1311) * Updated region tags for pull queue samples [(#1329)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/1329) * Auto-update dependencies. [(#1320)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/1320) * Auto-update dependencies. [(#1355)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/1355) * Auto-update dependencies. [(#1359)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/1359) * Auto-update dependencies. * Update Cloud Tasks Samples [(#1529)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/1529) * passing create task * Passing tests * updates to region tags * update region tags [(#1532)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/1532) * update Tasks Sample for App Engine [(#1541)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/1541) * update gcloud command for creating queues * deploys and runs * update license * passing tests * Fix run command [(#1563)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/1563) * Updated library for TTS GA [(#1552)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/1552) * update gcloud command for Cloud Tasks [(#1566)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/1566) * update gcloud command * update pull queue command * update pull queue command * Update Cloud Tasks Push Queue Sample [(#1698)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/1698) * deleted pull queues * updated samples * fix dependency versions * [Cloud Tasks] Move samples to new folder [(#2114)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/2114) * Move samples to keep consistent with other langauges * Ad system tests as well * [Cloud Tasks] Add task with authentication sample [(#2113)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/2113) * Add task with authentication sample * Fix linting * Fix linting * Fix spacing * Update tests with service account * Move samples and update READMEs * Update version and linting * Update task sample comments [(#2156)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/2156) * Update task comments * Update readme * Update queue name * update gcloud [(#2208)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/2208) * Add protobuf dep and install instructions [(#2250)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/2250) * Add Migration Guide Snippets for Cloud Tasks [(#2316)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/2316) * Migration guide * remove app and update migraitonn * snippets for migration guide - tests added * lint * remove print statements * Styling changes * Travis trigger * Update create_http_task.py [(#2187)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/2187) Updates `create_http_task.py` to have missing `in_seconds` variable * Adds updates for samples profiler ... vision [(#2439)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/2439) * Update Cloud Tasks library version [(#2516)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/2516) * Update to new library * update library version * Adds Task name while creating Task [(#2543)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/2543) * Task Name in Creating HTTP Task with Token [(#2700)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/2700) * chore(deps): update dependency google-cloud-tasks to v1.5.0 [(#3168)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/3168) * chore(deps): update dependency googleapis-common-protos to v1.51.0 [(#3171)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/3171) This PR contains the following updates: | Package | Update | Change | |---|---|---| | [googleapis-common-protos](https://togithub.com/googleapis/googleapis) | minor | `==1.6.0` -> `==1.51.0` | --- ### 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**: Never, 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). * 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 * Remove dependency googleapis-common-protos [(#3955)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/3955) * Update dependency googleapis-common-protos to v1.52.0 * Update requirements.txt * Update requirements.txt * Update requirements.txt Co-authored-by: Bu Sun Kim <8822365+busunkim96@users.noreply.github.com> * Replace GCLOUD_PROJECT with GOOGLE_CLOUD_PROJECT. [(#4022)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/4022) * [tasks] testing: use fixtures for the queue [(#4049)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/4049) fixes #4045 fixes #4044 I don't know why these tests started to fail, but anyways we'd better use fixtures and temporary queues. * add python snippets and tests for creating, listing, and deleting queues [(#4012)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/4012) * add python snippets and tests for creating, listing, and deleting queues * fix grammar * update licenses * apply suggested fixes and format with black * refine delete_queue_test with fixture for setup * utilize fixtures and match format of create_http_task_test * utilize fixtures in list_queues_test and create_queue_test * make create_queue_test call the right function * still attempt to delete queue after test runs in case of failure * attempt to delete queue in case of failure, using try/except approach * add print when NotFound is caught * fix import Co-authored-by: Averi Kitsch Co-authored-by: Takashi Matsuo * docs(tasks): service_account_email parameter example [(#4183)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/4183) * docs(tasks): serviceAccountEmail parameter example * docs(tasks): parameter name camel => snake case * docs(tasks): comment order = function param order * 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 * Update dependency pytest to v6 [(#4390)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/4390) * tasks: added json content-type request [(#4473)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/4473) - added json payload compatibility - fix imports and code block used on https://cloud.google.com/tasks/docs/creating-http-target-tasks#python ## Description Fixes # Note: It's a good idea to open an issue first for discussion. ## Checklist - [ ] I have followed [Sample Guidelines from AUTHORING_GUIDE.MD](https://github.com/GoogleCloudPlatform/python-docs-samples/blob/master/AUTHORING_GUIDE.md) - [ ] README is updated to include [all relevant information](https://github.com/GoogleCloudPlatform/python-docs-samples/blob/master/AUTHORING_GUIDE.md#readme-file) - [ ] **Tests** pass: `nox -s py-3.6` (see [Test Environment Setup](https://github.com/GoogleCloudPlatform/python-docs-samples/blob/master/AUTHORING_GUIDE.md#test-environment-setup)) - [ ] **Lint** pass: `nox -s lint` (see [Test Environment Setup](https://github.com/GoogleCloudPlatform/python-docs-samples/blob/master/AUTHORING_GUIDE.md#test-environment-setup)) - [ ] These samples need a new **API enabled** in testing projects to pass (let us know which ones) - [ ] These samples need a new/updated **env vars** in testing projects set to pass (let us know which ones) - [ ] Please **merge** this PR for me once it is approved. - [ ] This sample adds a new sample directory, and I updated the [CODEOWNERS file](https://github.com/GoogleCloudPlatform/python-docs-samples/blob/master/.github/CODEOWNERS) with the codeowners for this sample * docs: add samples from python-docs-samples/tasks * chore: update templates Co-authored-by: Andrew Gorcester Co-authored-by: Andrew Gorcester Co-authored-by: DPE bot Co-authored-by: michaelawyu Co-authored-by: ellenevans <35748459+ellenevans@users.noreply.github.com> Co-authored-by: Averi Kitsch Co-authored-by: michaelawyu Co-authored-by: Noah Negrey Co-authored-by: Alex Voorhees Co-authored-by: Gus Class Co-authored-by: Sarath Kaul Co-authored-by: Sarath Kaul Co-authored-by: WhiteSource Renovate Co-authored-by: Kurtis Van Gent <31518063+kurtisvg@users.noreply.github.com> Co-authored-by: Bu Sun Kim <8822365+busunkim96@users.noreply.github.com> Co-authored-by: Takashi Matsuo Co-authored-by: Aaron Johnson Co-authored-by: Adam Ross Co-authored-by: Leah Cole Co-authored-by: Joab Leite S. Neto --- cloud-tasks/snippets/create_http_task.py | 138 +++++++++++ cloud-tasks/snippets/create_http_task_test.py | 48 ++++ .../snippets/create_http_task_with_token.py | 86 +++++++ .../create_http_task_with_token_test.py | 53 +++++ cloud-tasks/snippets/noxfile.py | 224 ++++++++++++++++++ cloud-tasks/snippets/requirements-test.txt | 1 + cloud-tasks/snippets/requirements.txt | 1 + 7 files changed, 551 insertions(+) create mode 100644 cloud-tasks/snippets/create_http_task.py create mode 100644 cloud-tasks/snippets/create_http_task_test.py create mode 100644 cloud-tasks/snippets/create_http_task_with_token.py create mode 100644 cloud-tasks/snippets/create_http_task_with_token_test.py create mode 100644 cloud-tasks/snippets/noxfile.py create mode 100644 cloud-tasks/snippets/requirements-test.txt create mode 100644 cloud-tasks/snippets/requirements.txt diff --git a/cloud-tasks/snippets/create_http_task.py b/cloud-tasks/snippets/create_http_task.py new file mode 100644 index 000000000000..23896209a104 --- /dev/null +++ b/cloud-tasks/snippets/create_http_task.py @@ -0,0 +1,138 @@ +# Copyright 2019 Google LLC 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. + +from __future__ import print_function + +import argparse + + +def create_http_task(project, + queue, + location, + url, + payload=None, + in_seconds=None, + task_name=None): + # [START cloud_tasks_create_http_task] + """Create a task for a given queue with an arbitrary payload.""" + + from google.cloud import tasks_v2 + from google.protobuf import timestamp_pb2 + import datetime + import json + + # Create a client. + client = tasks_v2.CloudTasksClient() + + # TODO(developer): Uncomment these lines and replace with your values. + # project = 'my-project-id' + # queue = 'my-queue' + # location = 'us-central1' + # url = 'https://example.com/task_handler' + # payload = 'hello' or {'param': 'value'} for application/json + + # Construct the fully qualified queue name. + parent = client.queue_path(project, location, queue) + + # Construct the request body. + task = { + 'http_request': { # Specify the type of request. + 'http_method': 'POST', + 'url': url # The full url path that the task will be sent to. + } + } + if payload is not None: + if isinstance(payload, dict): + # Convert dict to JSON string + payload = json.dumps(payload) + # specify http content-type to application/json + task['http_request']['headers'] = {'Content-type': 'application/json'} + + # The API expects a payload of type bytes. + converted_payload = payload.encode() + + # Add the payload to the request. + task['http_request']['body'] = converted_payload + + if in_seconds is not None: + # Convert "seconds from now" into an rfc3339 datetime string. + d = datetime.datetime.utcnow() + datetime.timedelta(seconds=in_seconds) + + # Create Timestamp protobuf. + timestamp = timestamp_pb2.Timestamp() + timestamp.FromDatetime(d) + + # Add the timestamp to the tasks. + task['schedule_time'] = timestamp + + if task_name is not None: + # Add the name to tasks. + task['name'] = task_name + + # Use the client to build and send the task. + response = client.create_task(parent, task) + + print('Created task {}'.format(response.name)) + # [END cloud_tasks_create_http_task] + return response + + +if __name__ == '__main__': + parser = argparse.ArgumentParser( + description=create_http_task.__doc__, + formatter_class=argparse.RawDescriptionHelpFormatter) + + parser.add_argument( + '--project', + help='Project of the queue to add the task to.', + required=True, + ) + + parser.add_argument( + '--queue', + help='ID (short name) of the queue to add the task to.', + required=True, + ) + + parser.add_argument( + '--location', + help='Location of the queue to add the task to.', + required=True, + ) + + parser.add_argument( + '--url', + help='The full url path that the request will be sent to.', + required=True, + ) + + parser.add_argument( + '--payload', + help='Optional payload to attach to the push queue.' + ) + + parser.add_argument( + '--in_seconds', type=int, + help='The number of seconds from now to schedule task attempt.' + ) + + parser.add_argument( + '--task_name', + help='Task name of the task to create' + ) + args = parser.parse_args() + + create_http_task( + args.project, args.queue, args.location, args.url, + args.payload, args.in_seconds, args.task_name) diff --git a/cloud-tasks/snippets/create_http_task_test.py b/cloud-tasks/snippets/create_http_task_test.py new file mode 100644 index 000000000000..b0fb3ed758b0 --- /dev/null +++ b/cloud-tasks/snippets/create_http_task_test.py @@ -0,0 +1,48 @@ +# Copyright 2019 Google LLC 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 os +import uuid + +from google.cloud import tasks_v2 +import pytest + +import create_http_task + +TEST_PROJECT_ID = os.getenv('GOOGLE_CLOUD_PROJECT') +TEST_LOCATION = os.getenv('TEST_QUEUE_LOCATION', 'us-central1') +TEST_QUEUE_NAME = f'my-queue-{uuid.uuid4().hex}' + + +@pytest.fixture() +def test_queue(): + client = tasks_v2.CloudTasksClient() + parent = client.location_path(TEST_PROJECT_ID, TEST_LOCATION) + queue = { + # The fully qualified path to the queue + 'name': client.queue_path( + TEST_PROJECT_ID, TEST_LOCATION, TEST_QUEUE_NAME), + } + q = client.create_queue(parent, queue) + + yield q + + client.delete_queue(q.name) + + +def test_create_http_task(test_queue): + url = 'https://example.com/task_handler' + result = create_http_task.create_http_task( + TEST_PROJECT_ID, TEST_QUEUE_NAME, TEST_LOCATION, url) + assert TEST_QUEUE_NAME in result.name diff --git a/cloud-tasks/snippets/create_http_task_with_token.py b/cloud-tasks/snippets/create_http_task_with_token.py new file mode 100644 index 000000000000..7320ede3a998 --- /dev/null +++ b/cloud-tasks/snippets/create_http_task_with_token.py @@ -0,0 +1,86 @@ +# Copyright 2019 Google LLC 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. + +from __future__ import print_function + +import datetime + + +def create_http_task(project, + queue, + location, + url, + service_account_email, + payload=None, + in_seconds=None, + task_name=None): + # [START cloud_tasks_create_http_task_with_token] + """Create a task for a given queue with an arbitrary payload.""" + + from google.cloud import tasks_v2 + from google.protobuf import timestamp_pb2 + + # Create a client. + client = tasks_v2.CloudTasksClient() + + # TODO(developer): Uncomment these lines and replace with your values. + # project = 'my-project-id' + # queue = 'my-queue' + # location = 'us-central1' + # url = 'https://example.com/task_handler' + # service_account_email = 'service-account@my-project-id.iam.gserviceaccount.com'; + # payload = 'hello' + + # Construct the fully qualified queue name. + parent = client.queue_path(project, location, queue) + + # Construct the request body. + task = { + 'http_request': { # Specify the type of request. + 'http_method': 'POST', + 'url': url, # The full url path that the task will be sent to. + 'oidc_token': { + 'service_account_email': service_account_email + } + } + } + + if payload is not None: + # The API expects a payload of type bytes. + converted_payload = payload.encode() + + # Add the payload to the request. + task['http_request']['body'] = converted_payload + + if in_seconds is not None: + # Convert "seconds from now" into an rfc3339 datetime string. + d = datetime.datetime.utcnow() + datetime.timedelta(seconds=in_seconds) + + # Create Timestamp protobuf. + timestamp = timestamp_pb2.Timestamp() + timestamp.FromDatetime(d) + + # Add the timestamp to the tasks. + task['schedule_time'] = timestamp + + if task_name is not None: + # Add the name to tasks. + task['name'] = task_name + + # Use the client to build and send the task. + response = client.create_task(parent, task) + + print('Created task {}'.format(response.name)) + return response +# [END cloud_tasks_create_http_task_with_token] diff --git a/cloud-tasks/snippets/create_http_task_with_token_test.py b/cloud-tasks/snippets/create_http_task_with_token_test.py new file mode 100644 index 000000000000..dd90d9199b1e --- /dev/null +++ b/cloud-tasks/snippets/create_http_task_with_token_test.py @@ -0,0 +1,53 @@ +# Copyright 2019 Google LLC 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 os +import uuid + +from google.cloud import tasks_v2 +import pytest + +import create_http_task_with_token + +TEST_PROJECT_ID = os.getenv('GOOGLE_CLOUD_PROJECT') +TEST_LOCATION = os.getenv('TEST_QUEUE_LOCATION', 'us-central1') +TEST_QUEUE_NAME = f'my-queue-{uuid.uuid4().hex}' +TEST_SERVICE_ACCOUNT = ( + 'test-run-invoker@python-docs-samples-tests.iam.gserviceaccount.com') + + +@pytest.fixture() +def test_queue(): + client = tasks_v2.CloudTasksClient() + parent = client.location_path(TEST_PROJECT_ID, TEST_LOCATION) + queue = { + # The fully qualified path to the queue + 'name': client.queue_path( + TEST_PROJECT_ID, TEST_LOCATION, TEST_QUEUE_NAME), + } + q = client.create_queue(parent, queue) + + yield q + + client.delete_queue(q.name) + + +def test_create_http_task_with_token(test_queue): + url = 'https://example.com/task_handler' + result = create_http_task_with_token.create_http_task(TEST_PROJECT_ID, + TEST_QUEUE_NAME, + TEST_LOCATION, + url, + TEST_SERVICE_ACCOUNT) + assert TEST_QUEUE_NAME in result.name diff --git a/cloud-tasks/snippets/noxfile.py b/cloud-tasks/snippets/noxfile.py new file mode 100644 index 000000000000..ba55d7ce53ca --- /dev/null +++ b/cloud-tasks/snippets/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/cloud-tasks/snippets/requirements-test.txt b/cloud-tasks/snippets/requirements-test.txt new file mode 100644 index 000000000000..7e460c8c866e --- /dev/null +++ b/cloud-tasks/snippets/requirements-test.txt @@ -0,0 +1 @@ +pytest==6.0.1 diff --git a/cloud-tasks/snippets/requirements.txt b/cloud-tasks/snippets/requirements.txt new file mode 100644 index 000000000000..b7bc58a3b74e --- /dev/null +++ b/cloud-tasks/snippets/requirements.txt @@ -0,0 +1 @@ +google-cloud-tasks==1.5.0 From 29c7b48333ece2545819463b7fd9bd992fb44f05 Mon Sep 17 00:00:00 2001 From: arithmetic1728 <58957152+arithmetic1728@users.noreply.github.com> Date: Wed, 2 Sep 2020 12:54:12 -0700 Subject: [PATCH 02/62] feat!: migrate to use microgen (#38) * feat!: migrate to use microgen * Update UPGRADING.md Co-authored-by: Bu Sun Kim <8822365+busunkim96@users.noreply.github.com> Co-authored-by: Bu Sun Kim <8822365+busunkim96@users.noreply.github.com> --- cloud-tasks/snippets/create_http_task.py | 74 +++++++++---------- cloud-tasks/snippets/create_http_task_test.py | 20 ++--- .../snippets/create_http_task_with_token.py | 42 ++++++----- .../create_http_task_with_token_test.py | 28 ++++--- 4 files changed, 80 insertions(+), 84 deletions(-) diff --git a/cloud-tasks/snippets/create_http_task.py b/cloud-tasks/snippets/create_http_task.py index 23896209a104..1b75e69c2b64 100644 --- a/cloud-tasks/snippets/create_http_task.py +++ b/cloud-tasks/snippets/create_http_task.py @@ -17,13 +17,9 @@ import argparse -def create_http_task(project, - queue, - location, - url, - payload=None, - in_seconds=None, - task_name=None): +def create_http_task( + project, queue, location, url, payload=None, in_seconds=None, task_name=None +): # [START cloud_tasks_create_http_task] """Create a task for a given queue with an arbitrary payload.""" @@ -47,23 +43,23 @@ def create_http_task(project, # Construct the request body. task = { - 'http_request': { # Specify the type of request. - 'http_method': 'POST', - 'url': url # The full url path that the task will be sent to. - } + "http_request": { # Specify the type of request. + "http_method": tasks_v2.HttpMethod.POST, + "url": url, # The full url path that the task will be sent to. + } } if payload is not None: if isinstance(payload, dict): # Convert dict to JSON string payload = json.dumps(payload) # specify http content-type to application/json - task['http_request']['headers'] = {'Content-type': 'application/json'} + task["http_request"]["headers"] = {"Content-type": "application/json"} # The API expects a payload of type bytes. converted_payload = payload.encode() # Add the payload to the request. - task['http_request']['body'] = converted_payload + task["http_request"]["body"] = converted_payload if in_seconds is not None: # Convert "seconds from now" into an rfc3339 datetime string. @@ -74,65 +70,65 @@ def create_http_task(project, timestamp.FromDatetime(d) # Add the timestamp to the tasks. - task['schedule_time'] = timestamp + task["schedule_time"] = timestamp if task_name is not None: # Add the name to tasks. - task['name'] = task_name + task["name"] = task_name # Use the client to build and send the task. - response = client.create_task(parent, task) + response = client.create_task(request={"parent": parent, "task": task}) - print('Created task {}'.format(response.name)) + print("Created task {}".format(response.name)) # [END cloud_tasks_create_http_task] return response -if __name__ == '__main__': +if __name__ == "__main__": parser = argparse.ArgumentParser( description=create_http_task.__doc__, - formatter_class=argparse.RawDescriptionHelpFormatter) + formatter_class=argparse.RawDescriptionHelpFormatter, + ) parser.add_argument( - '--project', - help='Project of the queue to add the task to.', - required=True, + "--project", help="Project of the queue to add the task to.", required=True, ) parser.add_argument( - '--queue', - help='ID (short name) of the queue to add the task to.', + "--queue", + help="ID (short name) of the queue to add the task to.", required=True, ) parser.add_argument( - '--location', - help='Location of the queue to add the task to.', - required=True, + "--location", help="Location of the queue to add the task to.", required=True, ) parser.add_argument( - '--url', - help='The full url path that the request will be sent to.', + "--url", + help="The full url path that the request will be sent to.", required=True, ) parser.add_argument( - '--payload', - help='Optional payload to attach to the push queue.' + "--payload", help="Optional payload to attach to the push queue." ) parser.add_argument( - '--in_seconds', type=int, - help='The number of seconds from now to schedule task attempt.' + "--in_seconds", + type=int, + help="The number of seconds from now to schedule task attempt.", ) - parser.add_argument( - '--task_name', - help='Task name of the task to create' - ) + parser.add_argument("--task_name", help="Task name of the task to create") args = parser.parse_args() create_http_task( - args.project, args.queue, args.location, args.url, - args.payload, args.in_seconds, args.task_name) + args.project, + args.queue, + args.location, + args.url, + args.payload, + args.in_seconds, + args.task_name, + ) diff --git a/cloud-tasks/snippets/create_http_task_test.py b/cloud-tasks/snippets/create_http_task_test.py index b0fb3ed758b0..20cfced96b9c 100644 --- a/cloud-tasks/snippets/create_http_task_test.py +++ b/cloud-tasks/snippets/create_http_task_test.py @@ -20,29 +20,29 @@ import create_http_task -TEST_PROJECT_ID = os.getenv('GOOGLE_CLOUD_PROJECT') -TEST_LOCATION = os.getenv('TEST_QUEUE_LOCATION', 'us-central1') -TEST_QUEUE_NAME = f'my-queue-{uuid.uuid4().hex}' +TEST_PROJECT_ID = os.getenv("GOOGLE_CLOUD_PROJECT") +TEST_LOCATION = os.getenv("TEST_QUEUE_LOCATION", "us-central1") +TEST_QUEUE_NAME = f"my-queue-{uuid.uuid4().hex}" @pytest.fixture() def test_queue(): client = tasks_v2.CloudTasksClient() - parent = client.location_path(TEST_PROJECT_ID, TEST_LOCATION) + parent = f"projects/{TEST_PROJECT_ID}/locations/{TEST_LOCATION}" queue = { # The fully qualified path to the queue - 'name': client.queue_path( - TEST_PROJECT_ID, TEST_LOCATION, TEST_QUEUE_NAME), + "name": client.queue_path(TEST_PROJECT_ID, TEST_LOCATION, TEST_QUEUE_NAME), } - q = client.create_queue(parent, queue) + q = client.create_queue(request={"parent": parent, "queue": queue}) yield q - client.delete_queue(q.name) + client.delete_queue(request={"name": q.name}) def test_create_http_task(test_queue): - url = 'https://example.com/task_handler' + url = "https://example.com/task_handler" result = create_http_task.create_http_task( - TEST_PROJECT_ID, TEST_QUEUE_NAME, TEST_LOCATION, url) + TEST_PROJECT_ID, TEST_QUEUE_NAME, TEST_LOCATION, url + ) assert TEST_QUEUE_NAME in result.name diff --git a/cloud-tasks/snippets/create_http_task_with_token.py b/cloud-tasks/snippets/create_http_task_with_token.py index 7320ede3a998..9c32c5960b72 100644 --- a/cloud-tasks/snippets/create_http_task_with_token.py +++ b/cloud-tasks/snippets/create_http_task_with_token.py @@ -17,14 +17,16 @@ import datetime -def create_http_task(project, - queue, - location, - url, - service_account_email, - payload=None, - in_seconds=None, - task_name=None): +def create_http_task( + project, + queue, + location, + url, + service_account_email, + payload=None, + in_seconds=None, + task_name=None, +): # [START cloud_tasks_create_http_task_with_token] """Create a task for a given queue with an arbitrary payload.""" @@ -47,13 +49,11 @@ def create_http_task(project, # Construct the request body. task = { - 'http_request': { # Specify the type of request. - 'http_method': 'POST', - 'url': url, # The full url path that the task will be sent to. - 'oidc_token': { - 'service_account_email': service_account_email - } - } + "http_request": { # Specify the type of request. + "http_method": tasks_v2.HttpMethod.POST, + "url": url, # The full url path that the task will be sent to. + "oidc_token": {"service_account_email": service_account_email}, + } } if payload is not None: @@ -61,7 +61,7 @@ def create_http_task(project, converted_payload = payload.encode() # Add the payload to the request. - task['http_request']['body'] = converted_payload + task["http_request"]["body"] = converted_payload if in_seconds is not None: # Convert "seconds from now" into an rfc3339 datetime string. @@ -72,15 +72,17 @@ def create_http_task(project, timestamp.FromDatetime(d) # Add the timestamp to the tasks. - task['schedule_time'] = timestamp + task["schedule_time"] = timestamp if task_name is not None: # Add the name to tasks. - task['name'] = task_name + task["name"] = task_name # Use the client to build and send the task. - response = client.create_task(parent, task) + response = client.create_task(request={"parent": parent, "task": task}) - print('Created task {}'.format(response.name)) + print("Created task {}".format(response.name)) return response + + # [END cloud_tasks_create_http_task_with_token] diff --git a/cloud-tasks/snippets/create_http_task_with_token_test.py b/cloud-tasks/snippets/create_http_task_with_token_test.py index dd90d9199b1e..b93c343740d5 100644 --- a/cloud-tasks/snippets/create_http_task_with_token_test.py +++ b/cloud-tasks/snippets/create_http_task_with_token_test.py @@ -20,34 +20,32 @@ import create_http_task_with_token -TEST_PROJECT_ID = os.getenv('GOOGLE_CLOUD_PROJECT') -TEST_LOCATION = os.getenv('TEST_QUEUE_LOCATION', 'us-central1') -TEST_QUEUE_NAME = f'my-queue-{uuid.uuid4().hex}' +TEST_PROJECT_ID = os.getenv("GOOGLE_CLOUD_PROJECT") +TEST_LOCATION = os.getenv("TEST_QUEUE_LOCATION", "us-central1") +TEST_QUEUE_NAME = f"my-queue-{uuid.uuid4().hex}" TEST_SERVICE_ACCOUNT = ( - 'test-run-invoker@python-docs-samples-tests.iam.gserviceaccount.com') + "test-run-invoker@python-docs-samples-tests.iam.gserviceaccount.com" +) @pytest.fixture() def test_queue(): client = tasks_v2.CloudTasksClient() - parent = client.location_path(TEST_PROJECT_ID, TEST_LOCATION) + parent = f"projects/{TEST_PROJECT_ID}/locations/{TEST_LOCATION}" queue = { # The fully qualified path to the queue - 'name': client.queue_path( - TEST_PROJECT_ID, TEST_LOCATION, TEST_QUEUE_NAME), + "name": client.queue_path(TEST_PROJECT_ID, TEST_LOCATION, TEST_QUEUE_NAME), } - q = client.create_queue(parent, queue) + q = client.create_queue(request={"parent": parent, "queue": queue}) yield q - client.delete_queue(q.name) + client.delete_queue(request={"name": q.name}) def test_create_http_task_with_token(test_queue): - url = 'https://example.com/task_handler' - result = create_http_task_with_token.create_http_task(TEST_PROJECT_ID, - TEST_QUEUE_NAME, - TEST_LOCATION, - url, - TEST_SERVICE_ACCOUNT) + url = "https://example.com/task_handler" + result = create_http_task_with_token.create_http_task( + TEST_PROJECT_ID, TEST_QUEUE_NAME, TEST_LOCATION, url, TEST_SERVICE_ACCOUNT + ) assert TEST_QUEUE_NAME in result.name From a9447379b999bd39b1b63dadfc60a01ce678af8a Mon Sep 17 00:00:00 2001 From: WhiteSource Renovate Date: Wed, 16 Sep 2020 17:02:49 +0200 Subject: [PATCH 03/62] chore(deps): update dependency google-cloud-tasks to v2 (#41) --- cloud-tasks/snippets/requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cloud-tasks/snippets/requirements.txt b/cloud-tasks/snippets/requirements.txt index b7bc58a3b74e..6211e439237f 100644 --- a/cloud-tasks/snippets/requirements.txt +++ b/cloud-tasks/snippets/requirements.txt @@ -1 +1 @@ -google-cloud-tasks==1.5.0 +google-cloud-tasks==2.0.0 From ef58b96e048f8311b518d3e07648e74babc02004 Mon Sep 17 00:00:00 2001 From: Yoshi Automation Bot Date: Mon, 7 Dec 2020 15:48:38 -0800 Subject: [PATCH 04/62] feat: add common resource helpers; expose client transport; add shebang to fixup scripts (#34) --- cloud-tasks/snippets/noxfile.py | 39 ++++++++++++++++++++++++++------- 1 file changed, 31 insertions(+), 8 deletions(-) diff --git a/cloud-tasks/snippets/noxfile.py b/cloud-tasks/snippets/noxfile.py index ba55d7ce53ca..bca0522ec4d9 100644 --- a/cloud-tasks/snippets/noxfile.py +++ b/cloud-tasks/snippets/noxfile.py @@ -17,6 +17,7 @@ import os from pathlib import Path import sys +from typing import Callable, Dict, List, Optional import nox @@ -39,6 +40,10 @@ # You can opt out from the test for specific Python versions. 'ignored_versions': ["2.7"], + # Old samples are opted out of enforcing Python type hints + # All new samples should feature them + 'enforce_type_hints': False, + # 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 @@ -64,7 +69,7 @@ TEST_CONFIG.update(TEST_CONFIG_OVERRIDE) -def get_pytest_env_vars(): +def get_pytest_env_vars() -> Dict[str, str]: """Returns a dict for pytest invocation.""" ret = {} @@ -93,7 +98,7 @@ def get_pytest_env_vars(): # -def _determine_local_import_names(start_dir): +def _determine_local_import_names(start_dir: str) -> List[str]: """Determines all import names that should be considered "local". This is used when running the linter to insure that import order is @@ -131,8 +136,11 @@ def _determine_local_import_names(start_dir): @nox.session -def lint(session): - session.install("flake8", "flake8-import-order") +def lint(session: nox.sessions.Session) -> None: + if not TEST_CONFIG['enforce_type_hints']: + session.install("flake8", "flake8-import-order") + else: + session.install("flake8", "flake8-import-order", "flake8-annotations") local_names = _determine_local_import_names(".") args = FLAKE8_COMMON_ARGS + [ @@ -141,8 +149,18 @@ def lint(session): "." ] session.run("flake8", *args) +# +# Black +# +@nox.session +def blacken(session: nox.sessions.Session) -> None: + session.install("black") + python_files = [path for path in os.listdir(".") if path.endswith(".py")] + + session.run("black", *python_files) + # # Sample Tests # @@ -151,7 +169,7 @@ def lint(session): PYTEST_COMMON_ARGS = ["--junitxml=sponge_log.xml"] -def _session_tests(session, post_install=None): +def _session_tests(session: nox.sessions.Session, post_install: Callable = None) -> None: """Runs py.test for a particular project.""" if os.path.exists("requirements.txt"): session.install("-r", "requirements.txt") @@ -177,7 +195,7 @@ def _session_tests(session, post_install=None): @nox.session(python=ALL_VERSIONS) -def py(session): +def py(session: nox.sessions.Session) -> None: """Runs py.test for a sample using the specified version of Python.""" if session.python in TESTED_VERSIONS: _session_tests(session) @@ -192,7 +210,7 @@ def py(session): # -def _get_repo_root(): +def _get_repo_root() -> Optional[str]: """ 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()) @@ -201,6 +219,11 @@ def _get_repo_root(): break if Path(p / ".git").exists(): return str(p) + # .git is not available in repos cloned via Cloud Build + # setup.py is always in the library's root, so use that instead + # https://github.com/googleapis/synthtool/issues/792 + if Path(p / "setup.py").exists(): + return str(p) p = p.parent raise Exception("Unable to detect repository root.") @@ -210,7 +233,7 @@ def _get_repo_root(): @nox.session @nox.parametrize("path", GENERATED_READMES) -def readmegen(session, path): +def readmegen(session: nox.sessions.Session, path: str) -> None: """(Re-)generates the readme for a sample.""" session.install("jinja2", "pyyaml") dir_ = os.path.dirname(path) From 6c3908a3561a116d8112c0633bf06e1d869f4e96 Mon Sep 17 00:00:00 2001 From: Averi Kitsch Date: Mon, 21 Dec 2020 16:21:46 -0800 Subject: [PATCH 05/62] fix: Update sample comments (#58) * fix: Update sample comments * fix: remove unused imports --- cloud-tasks/snippets/create_http_task.py | 2 ++ .../snippets/create_http_task_with_token.py | 20 ------------------- 2 files changed, 2 insertions(+), 20 deletions(-) diff --git a/cloud-tasks/snippets/create_http_task.py b/cloud-tasks/snippets/create_http_task.py index 1b75e69c2b64..056dde0cc700 100644 --- a/cloud-tasks/snippets/create_http_task.py +++ b/cloud-tasks/snippets/create_http_task.py @@ -37,6 +37,8 @@ def create_http_task( # location = 'us-central1' # url = 'https://example.com/task_handler' # payload = 'hello' or {'param': 'value'} for application/json + # in_seconds = 180 + # task_name = 'my-unique-task' # Construct the fully qualified queue name. parent = client.queue_path(project, location, queue) diff --git a/cloud-tasks/snippets/create_http_task_with_token.py b/cloud-tasks/snippets/create_http_task_with_token.py index 9c32c5960b72..6f6909866d56 100644 --- a/cloud-tasks/snippets/create_http_task_with_token.py +++ b/cloud-tasks/snippets/create_http_task_with_token.py @@ -14,8 +14,6 @@ from __future__ import print_function -import datetime - def create_http_task( project, @@ -24,14 +22,11 @@ def create_http_task( url, service_account_email, payload=None, - in_seconds=None, - task_name=None, ): # [START cloud_tasks_create_http_task_with_token] """Create a task for a given queue with an arbitrary payload.""" from google.cloud import tasks_v2 - from google.protobuf import timestamp_pb2 # Create a client. client = tasks_v2.CloudTasksClient() @@ -63,21 +58,6 @@ def create_http_task( # Add the payload to the request. task["http_request"]["body"] = converted_payload - if in_seconds is not None: - # Convert "seconds from now" into an rfc3339 datetime string. - d = datetime.datetime.utcnow() + datetime.timedelta(seconds=in_seconds) - - # Create Timestamp protobuf. - timestamp = timestamp_pb2.Timestamp() - timestamp.FromDatetime(d) - - # Add the timestamp to the tasks. - task["schedule_time"] = timestamp - - if task_name is not None: - # Add the name to tasks. - task["name"] = task_name - # Use the client to build and send the task. response = client.create_task(request={"parent": parent, "task": task}) From 924dab7526db50ae869c6dc64b0aae0c53791689 Mon Sep 17 00:00:00 2001 From: WhiteSource Renovate Date: Wed, 13 Jan 2021 20:07:57 +0100 Subject: [PATCH 06/62] chore(deps): update dependency google-cloud-tasks to v2.1.0 (#63) --- cloud-tasks/snippets/requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cloud-tasks/snippets/requirements.txt b/cloud-tasks/snippets/requirements.txt index 6211e439237f..115eabf947d1 100644 --- a/cloud-tasks/snippets/requirements.txt +++ b/cloud-tasks/snippets/requirements.txt @@ -1 +1 @@ -google-cloud-tasks==2.0.0 +google-cloud-tasks==2.1.0 From 4bed1623def0d9f6b6ea87b12faa037d2499f44e Mon Sep 17 00:00:00 2001 From: Yoshi Automation Bot Date: Tue, 23 Feb 2021 18:33:41 -0800 Subject: [PATCH 07/62] chore: upgrade gapic-generator-python to 0.39.1 (#64) feat(v2beta3, v2beta2): introducing fields: ListQueuesRequest.read_mask, GetQueueRequest.read_mask, Queue.task_ttl, Queue.tombstone_ttl, Queue.stats and introducing messages: QueueStats feat: add from_service_account_info method to clients docs(v2beta3): updates to max burst size description docs(v2beta2): updates to AppEngineHttpRequest description test: add 3.9 unit tests docs: fix type references in docstrings --- cloud-tasks/snippets/noxfile.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cloud-tasks/snippets/noxfile.py b/cloud-tasks/snippets/noxfile.py index bca0522ec4d9..97bf7da80e39 100644 --- a/cloud-tasks/snippets/noxfile.py +++ b/cloud-tasks/snippets/noxfile.py @@ -85,7 +85,7 @@ def get_pytest_env_vars() -> Dict[str, str]: # DO NOT EDIT - automatically generated. # All versions used to tested samples. -ALL_VERSIONS = ["2.7", "3.6", "3.7", "3.8"] +ALL_VERSIONS = ["2.7", "3.6", "3.7", "3.8", "3.9"] # Any default versions that should be ignored. IGNORED_VERSIONS = TEST_CONFIG['ignored_versions'] From ba19d22aeb08ed13263abb9f6f79a614689fc8ae Mon Sep 17 00:00:00 2001 From: WhiteSource Renovate Date: Wed, 24 Feb 2021 17:24:02 +0100 Subject: [PATCH 08/62] chore(deps): update dependency google-cloud-tasks to v2.2.0 (#71) [![WhiteSource Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com) This PR contains the following updates: | Package | Change | Age | Adoption | Passing | Confidence | |---|---|---|---|---|---| | [google-cloud-tasks](https://togithub.com/googleapis/python-tasks) | `==2.1.0` -> `==2.2.0` | [![age](https://badges.renovateapi.com/packages/pypi/google-cloud-tasks/2.2.0/age-slim)](https://docs.renovatebot.com/merge-confidence/) | [![adoption](https://badges.renovateapi.com/packages/pypi/google-cloud-tasks/2.2.0/adoption-slim)](https://docs.renovatebot.com/merge-confidence/) | [![passing](https://badges.renovateapi.com/packages/pypi/google-cloud-tasks/2.2.0/compatibility-slim/2.1.0)](https://docs.renovatebot.com/merge-confidence/) | [![confidence](https://badges.renovateapi.com/packages/pypi/google-cloud-tasks/2.2.0/confidence-slim/2.1.0)](https://docs.renovatebot.com/merge-confidence/) | --- ### Release Notes
googleapis/python-tasks ### [`v2.2.0`](https://togithub.com/googleapis/python-tasks/blob/master/CHANGELOG.md#​220-httpswwwgithubcomgoogleapispython-taskscomparev210v220-2021-02-24) [Compare Source](https://togithub.com/googleapis/python-tasks/compare/v2.1.0...v2.2.0) ##### Features - add from_service_account_info method to clients ([e1fdc76](https://www.github.com/googleapis/python-tasks/commit/e1fdc76f5369e53067a1748aecce9fa3940d9ee1)) - **v2beta3, v2beta2:** introducing fields: ListQueuesRequest.read_mask, GetQueueRequest.read_mask, Queue.task_ttl, Queue.tombstone_ttl, Queue.stats and introducing messages: QueueStats ([e1fdc76](https://www.github.com/googleapis/python-tasks/commit/e1fdc76f5369e53067a1748aecce9fa3940d9ee1)) ##### Bug Fixes - remove client recv msg limit fix: add enums to `types/__init__.py` ([#​56](https://www.github.com/googleapis/python-tasks/issues/56)) ([6a5bfaf](https://www.github.com/googleapis/python-tasks/commit/6a5bfaf63b46567897c36907772b10ea4b0dff43)) - Update sample comments ([#​58](https://www.github.com/googleapis/python-tasks/issues/58)) ([3eb30b3](https://www.github.com/googleapis/python-tasks/commit/3eb30b349b9092a2a2fb08116855139418ebd371)) ##### Documentation - fix type references in docstrings ([e1fdc76](https://www.github.com/googleapis/python-tasks/commit/e1fdc76f5369e53067a1748aecce9fa3940d9ee1)) - **v2beta2:** updates to AppEngineHttpRequest description ([e1fdc76](https://www.github.com/googleapis/python-tasks/commit/e1fdc76f5369e53067a1748aecce9fa3940d9ee1)) - **v2beta3:** updates to max burst size description ([e1fdc76](https://www.github.com/googleapis/python-tasks/commit/e1fdc76f5369e53067a1748aecce9fa3940d9ee1))
--- ### 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#github/googleapis/python-tasks). --- cloud-tasks/snippets/requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cloud-tasks/snippets/requirements.txt b/cloud-tasks/snippets/requirements.txt index 115eabf947d1..e543c96a7aea 100644 --- a/cloud-tasks/snippets/requirements.txt +++ b/cloud-tasks/snippets/requirements.txt @@ -1 +1 @@ -google-cloud-tasks==2.1.0 +google-cloud-tasks==2.2.0 From 9ed9d0ce0044054f8dcc7c8456a6ed583e93164e Mon Sep 17 00:00:00 2001 From: Yoshi Automation Bot Date: Mon, 12 Apr 2021 07:51:53 -0700 Subject: [PATCH 09/62] chore: add constraints file check for python samples (#87) This is the sibling PR to https://github.com/GoogleCloudPlatform/python-docs-samples/pull/5611 and this is the issue opened for it https://github.com/GoogleCloudPlatform/python-docs-samples/issues/5549 If you look at the files in [this example repo](https://github.com/leahecole/testrepo-githubapp/pull/31/files), you'll see that renovate successfully opened a PR on three constraints files in `samples` directories and subdirectories, and properly ignored `constraints` files at the root level cc @tswast TODO: - [x] update renovate to check for samples/constraints.txt dependency updates - [x] run lint locally to double check that I'm not introducing lint error Source-Author: Leah E. Cole <6719667+leahecole@users.noreply.github.com> Source-Date: Fri Apr 9 22:50:04 2021 -0700 Source-Repo: googleapis/synthtool Source-Sha: 0a071b3460344886297a304253bf924aa68ddb7e Source-Link: https://github.com/googleapis/synthtool/commit/0a071b3460344886297a304253bf924aa68ddb7e --- cloud-tasks/snippets/noxfile.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/cloud-tasks/snippets/noxfile.py b/cloud-tasks/snippets/noxfile.py index 97bf7da80e39..956cdf4f9250 100644 --- a/cloud-tasks/snippets/noxfile.py +++ b/cloud-tasks/snippets/noxfile.py @@ -172,10 +172,16 @@ def blacken(session: nox.sessions.Session) -> None: def _session_tests(session: nox.sessions.Session, post_install: Callable = None) -> None: """Runs py.test for a particular project.""" if os.path.exists("requirements.txt"): - session.install("-r", "requirements.txt") + if os.path.exists("constraints.txt"): + session.install("-r", "requirements.txt", "-c", "constraints.txt") + else: + session.install("-r", "requirements.txt") if os.path.exists("requirements-test.txt"): - session.install("-r", "requirements-test.txt") + if os.path.exists("constraints-test.txt"): + session.install("-r", "requirements-test.txt", "-c", "constraints-test.txt") + else: + session.install("-r", "requirements-test.txt") if INSTALL_LIBRARY_FROM_SOURCE: session.install("-e", _get_repo_root()) From 8971aaaec2c50b4ddcf4939186a786d27a6fd58d Mon Sep 17 00:00:00 2001 From: WhiteSource Renovate Date: Tue, 13 Apr 2021 19:31:06 +0200 Subject: [PATCH 10/62] chore(deps): update dependency pytest to v6.2.3 (#88) --- cloud-tasks/snippets/requirements-test.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cloud-tasks/snippets/requirements-test.txt b/cloud-tasks/snippets/requirements-test.txt index 7e460c8c866e..f7e3ec09da60 100644 --- a/cloud-tasks/snippets/requirements-test.txt +++ b/cloud-tasks/snippets/requirements-test.txt @@ -1 +1 @@ -pytest==6.0.1 +pytest==6.2.3 From 594e2b360bebdbb0e33a15880e2abad18f4e6414 Mon Sep 17 00:00:00 2001 From: WhiteSource Renovate Date: Fri, 14 May 2021 03:07:10 +0200 Subject: [PATCH 11/62] chore(deps): update dependency pytest to v6.2.4 (#101) --- cloud-tasks/snippets/requirements-test.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cloud-tasks/snippets/requirements-test.txt b/cloud-tasks/snippets/requirements-test.txt index f7e3ec09da60..95ea1e6a02b0 100644 --- a/cloud-tasks/snippets/requirements-test.txt +++ b/cloud-tasks/snippets/requirements-test.txt @@ -1 +1 @@ -pytest==6.2.3 +pytest==6.2.4 From 46877b0016d16ae5ae545b1e9619dfd04fb9bcd3 Mon Sep 17 00:00:00 2001 From: "gcf-owl-bot[bot]" <78513119+gcf-owl-bot[bot]@users.noreply.github.com> Date: Sat, 22 May 2021 09:18:24 +0000 Subject: [PATCH 12/62] chore: new owl bot post processor docker image (#110) gcr.io/repo-automation-bots/owlbot-python:latest@sha256:3c3a445b3ddc99ccd5d31edc4b4519729635d20693900db32c4f587ed51f7479 --- cloud-tasks/snippets/noxfile.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/cloud-tasks/snippets/noxfile.py b/cloud-tasks/snippets/noxfile.py index 956cdf4f9250..5ff9e1db5808 100644 --- a/cloud-tasks/snippets/noxfile.py +++ b/cloud-tasks/snippets/noxfile.py @@ -50,7 +50,10 @@ # to use your own Cloud project. 'gcloud_project_env': 'GOOGLE_CLOUD_PROJECT', # 'gcloud_project_env': 'BUILD_SPECIFIC_GCLOUD_PROJECT', - + # If you need to use a specific version of pip, + # change pip_version_override to the string representation + # of the version number, for example, "20.2.4" + "pip_version_override": None, # A dictionary you want to inject into your test. Don't put any # secrets here. These values will override predefined values. 'envs': {}, @@ -170,6 +173,9 @@ def blacken(session: nox.sessions.Session) -> None: def _session_tests(session: nox.sessions.Session, post_install: Callable = None) -> None: + if TEST_CONFIG["pip_version_override"]: + pip_version = TEST_CONFIG["pip_version_override"] + session.install(f"pip=={pip_version}") """Runs py.test for a particular project.""" if os.path.exists("requirements.txt"): if os.path.exists("constraints.txt"): From 63790833c00b705b5697d66bd734df49161add85 Mon Sep 17 00:00:00 2001 From: WhiteSource Renovate Date: Thu, 3 Jun 2021 06:02:23 +0200 Subject: [PATCH 13/62] chore(deps): update dependency google-cloud-tasks to v2.3.0 (#114) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit [![WhiteSource Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com) This PR contains the following updates: | Package | Change | Age | Adoption | Passing | Confidence | |---|---|---|---|---|---| | [google-cloud-tasks](https://togithub.com/googleapis/python-tasks) | `==2.2.0` -> `==2.3.0` | [![age](https://badges.renovateapi.com/packages/pypi/google-cloud-tasks/2.3.0/age-slim)](https://docs.renovatebot.com/merge-confidence/) | [![adoption](https://badges.renovateapi.com/packages/pypi/google-cloud-tasks/2.3.0/adoption-slim)](https://docs.renovatebot.com/merge-confidence/) | [![passing](https://badges.renovateapi.com/packages/pypi/google-cloud-tasks/2.3.0/compatibility-slim/2.2.0)](https://docs.renovatebot.com/merge-confidence/) | [![confidence](https://badges.renovateapi.com/packages/pypi/google-cloud-tasks/2.3.0/confidence-slim/2.2.0)](https://docs.renovatebot.com/merge-confidence/) | --- ### Release Notes
googleapis/python-tasks ### [`v2.3.0`](https://togithub.com/googleapis/python-tasks/blob/master/CHANGELOG.md#​230-httpswwwgithubcomgoogleapispython-taskscomparev220v230-2021-05-28) [Compare Source](https://togithub.com/googleapis/python-tasks/compare/v2.2.0...v2.3.0) ##### Features - add `from_service_account_info` ([#​80](https://www.github.com/googleapis/python-tasks/issues/80)) ([2498225](https://www.github.com/googleapis/python-tasks/commit/2498225112ddb4b112b387dec71631c29a6db71e)) - support self-signed JWT flow for service accounts ([1acf20c](https://www.github.com/googleapis/python-tasks/commit/1acf20ca440a5396ee03205b5c2301b84e368926)) ##### Bug Fixes - add async client to %name\_%version/init.py ([1acf20c](https://www.github.com/googleapis/python-tasks/commit/1acf20ca440a5396ee03205b5c2301b84e368926)) - use correct retry deadlines ([2498225](https://www.github.com/googleapis/python-tasks/commit/2498225112ddb4b112b387dec71631c29a6db71e)) ##### Documentation - fix grammar in documentation ([#​112](https://www.github.com/googleapis/python-tasks/issues/112)) ([6f93a19](https://www.github.com/googleapis/python-tasks/commit/6f93a190311bd5468827496685072388a951e670))
--- ### Configuration 📅 **Schedule**: At any time (no schedule defined). 🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied. ♻️ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox. 🔕 **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#github/googleapis/python-tasks). --- cloud-tasks/snippets/requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cloud-tasks/snippets/requirements.txt b/cloud-tasks/snippets/requirements.txt index e543c96a7aea..c463504c31ea 100644 --- a/cloud-tasks/snippets/requirements.txt +++ b/cloud-tasks/snippets/requirements.txt @@ -1 +1 @@ -google-cloud-tasks==2.2.0 +google-cloud-tasks==2.3.0 From 7774b3cb919d4f67d6f454a6d262609e83a5c080 Mon Sep 17 00:00:00 2001 From: Averi Kitsch Date: Mon, 21 Jun 2021 14:52:56 -0700 Subject: [PATCH 14/62] fix: update sample for task name (#120) --- cloud-tasks/snippets/create_http_task.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cloud-tasks/snippets/create_http_task.py b/cloud-tasks/snippets/create_http_task.py index 056dde0cc700..e6d7435e1337 100644 --- a/cloud-tasks/snippets/create_http_task.py +++ b/cloud-tasks/snippets/create_http_task.py @@ -76,7 +76,7 @@ def create_http_task( if task_name is not None: # Add the name to tasks. - task["name"] = task_name + task["name"] = client.task_path(project, location, queue, task_name) # Use the client to build and send the task. response = client.create_task(request={"parent": parent, "task": task}) From 17b753057d90acb9eea9a96970bfc17d0dd6fce6 Mon Sep 17 00:00:00 2001 From: WhiteSource Renovate Date: Sat, 3 Jul 2021 13:40:23 +0200 Subject: [PATCH 15/62] chore(deps): update dependency google-cloud-tasks to v2.4.0 (#127) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit [![WhiteSource Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com) This PR contains the following updates: | Package | Change | Age | Adoption | Passing | Confidence | |---|---|---|---|---|---| | [google-cloud-tasks](https://togithub.com/googleapis/python-tasks) | `==2.3.0` -> `==2.4.0` | [![age](https://badges.renovateapi.com/packages/pypi/google-cloud-tasks/2.4.0/age-slim)](https://docs.renovatebot.com/merge-confidence/) | [![adoption](https://badges.renovateapi.com/packages/pypi/google-cloud-tasks/2.4.0/adoption-slim)](https://docs.renovatebot.com/merge-confidence/) | [![passing](https://badges.renovateapi.com/packages/pypi/google-cloud-tasks/2.4.0/compatibility-slim/2.3.0)](https://docs.renovatebot.com/merge-confidence/) | [![confidence](https://badges.renovateapi.com/packages/pypi/google-cloud-tasks/2.4.0/confidence-slim/2.3.0)](https://docs.renovatebot.com/merge-confidence/) | --- ### Release Notes
googleapis/python-tasks ### [`v2.4.0`](https://togithub.com/googleapis/python-tasks/blob/master/CHANGELOG.md#​240-httpswwwgithubcomgoogleapispython-taskscomparev230v240-2021-07-01) [Compare Source](https://togithub.com/googleapis/python-tasks/compare/v2.3.0...v2.4.0) ##### Features - add always_use_jwt_access ([#​122](https://www.github.com/googleapis/python-tasks/issues/122)) ([87c9ccc](https://www.github.com/googleapis/python-tasks/commit/87c9cccb42237eb421c72411652985a7fbe1c16a)) ##### Bug Fixes - disable always_use_jwt_access ([#​126](https://www.github.com/googleapis/python-tasks/issues/126)) ([54d2286](https://www.github.com/googleapis/python-tasks/commit/54d2286b153c36b7a50b5a936517aa59e10ad27c)) - update sample for task name ([#​120](https://www.github.com/googleapis/python-tasks/issues/120)) ([b1be2de](https://www.github.com/googleapis/python-tasks/commit/b1be2de174fc37d0eb90bbf877851c11ddb14907)) ##### Documentation - omit mention of Python 2.7 in CONTRIBUTING.rst ([#​116](https://www.github.com/googleapis/python-tasks/issues/116)) ([0732ab7](https://www.github.com/googleapis/python-tasks/commit/0732ab7d726fdf564897fad009f8a5da45b5c017)), closes [#​1126](https://www.github.com/googleapis/python-tasks/issues/1126)
--- ### Configuration 📅 **Schedule**: At any time (no schedule defined). 🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied. ♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox. 🔕 **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#github/googleapis/python-tasks). --- cloud-tasks/snippets/requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cloud-tasks/snippets/requirements.txt b/cloud-tasks/snippets/requirements.txt index c463504c31ea..b56d36f7993d 100644 --- a/cloud-tasks/snippets/requirements.txt +++ b/cloud-tasks/snippets/requirements.txt @@ -1 +1 @@ -google-cloud-tasks==2.3.0 +google-cloud-tasks==2.4.0 From 4ef90dad9cd466a94f70d7e7fef3328fc6599300 Mon Sep 17 00:00:00 2001 From: Ehsan Karamad Date: Wed, 21 Jul 2021 13:13:22 -0400 Subject: [PATCH 16/62] feat: Set `audience` field in authenticated HTTP task example (#138) * Add explicit `audience1 field Unset `audience` will be take the URL as default value. When there are query and fragment parts, this would lead to authentication errors (401). * Add explicit `audience1 field feat: Set `audience` in authenticated HTTP task Unset `audience` will be take the URL as default value. When there are query and fragment parts, this would lead to authentication errors (401). * feat: Add explicit `audience1 field Unset `audience` will be take the URL as default value. When there are query and fragment parts, this would lead to authentication errors (401). --- cloud-tasks/snippets/create_http_task_with_token.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/cloud-tasks/snippets/create_http_task_with_token.py b/cloud-tasks/snippets/create_http_task_with_token.py index 6f6909866d56..f09e85382bec 100644 --- a/cloud-tasks/snippets/create_http_task_with_token.py +++ b/cloud-tasks/snippets/create_http_task_with_token.py @@ -21,6 +21,7 @@ def create_http_task( location, url, service_account_email, + audience=None, payload=None, ): # [START cloud_tasks_create_http_task_with_token] @@ -35,7 +36,8 @@ def create_http_task( # project = 'my-project-id' # queue = 'my-queue' # location = 'us-central1' - # url = 'https://example.com/task_handler' + # url = 'https://example.com/task_handler?param=value' + # audience = 'https://example.com/task_handler' # service_account_email = 'service-account@my-project-id.iam.gserviceaccount.com'; # payload = 'hello' @@ -47,7 +49,7 @@ def create_http_task( "http_request": { # Specify the type of request. "http_method": tasks_v2.HttpMethod.POST, "url": url, # The full url path that the task will be sent to. - "oidc_token": {"service_account_email": service_account_email}, + "oidc_token": {"service_account_email": service_account_email, "audience": audience}, } } From e280d0876be74b2e337c00f2e856807822a60493 Mon Sep 17 00:00:00 2001 From: "gcf-owl-bot[bot]" <78513119+gcf-owl-bot[bot]@users.noreply.github.com> Date: Thu, 22 Jul 2021 13:50:23 +0000 Subject: [PATCH 17/62] feat: add Samples section to CONTRIBUTING.rst (#135) Source-Link: https://github.com/googleapis/synthtool/commit/52e4e46eff2a0b70e3ff5506a02929d089d077d4 Post-Processor: gcr.io/repo-automation-bots/owlbot-python:latest@sha256:6186535cbdbf6b9fe61f00294929221d060634dae4a0795c1cefdbc995b2d605 --- cloud-tasks/snippets/noxfile.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/cloud-tasks/snippets/noxfile.py b/cloud-tasks/snippets/noxfile.py index 5ff9e1db5808..6a8ccdae22c9 100644 --- a/cloud-tasks/snippets/noxfile.py +++ b/cloud-tasks/snippets/noxfile.py @@ -28,8 +28,9 @@ # WARNING - WARNING - WARNING - WARNING - WARNING # WARNING - WARNING - WARNING - WARNING - WARNING -# Copy `noxfile_config.py` to your directory and modify it instead. +BLACK_VERSION = "black==19.10b0" +# 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 @@ -159,7 +160,7 @@ def lint(session: nox.sessions.Session) -> None: @nox.session def blacken(session: nox.sessions.Session) -> None: - session.install("black") + session.install(BLACK_VERSION) python_files = [path for path in os.listdir(".") if path.endswith(".py")] session.run("black", *python_files) From 2f7f79826bddc68d71eb335490431974392268f5 Mon Sep 17 00:00:00 2001 From: WhiteSource Renovate Date: Thu, 22 Jul 2021 16:10:38 +0200 Subject: [PATCH 18/62] chore(deps): update dependency google-cloud-tasks to v2.5.0 (#140) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit [![WhiteSource Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com) This PR contains the following updates: | Package | Change | Age | Adoption | Passing | Confidence | |---|---|---|---|---|---| | [google-cloud-tasks](https://togithub.com/googleapis/python-tasks) | `==2.4.0` -> `==2.5.0` | [![age](https://badges.renovateapi.com/packages/pypi/google-cloud-tasks/2.5.0/age-slim)](https://docs.renovatebot.com/merge-confidence/) | [![adoption](https://badges.renovateapi.com/packages/pypi/google-cloud-tasks/2.5.0/adoption-slim)](https://docs.renovatebot.com/merge-confidence/) | [![passing](https://badges.renovateapi.com/packages/pypi/google-cloud-tasks/2.5.0/compatibility-slim/2.4.0)](https://docs.renovatebot.com/merge-confidence/) | [![confidence](https://badges.renovateapi.com/packages/pypi/google-cloud-tasks/2.5.0/confidence-slim/2.4.0)](https://docs.renovatebot.com/merge-confidence/) | --- ### Release Notes
googleapis/python-tasks ### [`v2.5.0`](https://togithub.com/googleapis/python-tasks/blob/master/CHANGELOG.md#​250-httpswwwgithubcomgoogleapispython-taskscomparev240v250-2021-07-21) [Compare Source](https://togithub.com/googleapis/python-tasks/compare/v2.4.0...v2.5.0) ##### Features - Set `audience` field in authenticated HTTP task example ([#​138](https://www.github.com/googleapis/python-tasks/issues/138)) ([7a5a0c6](https://www.github.com/googleapis/python-tasks/commit/7a5a0c6ca5372035521d5366373054a7ba95f2bd)) ##### Bug Fixes - **deps:** pin 'google-{api,cloud}-core', 'google-auth' to allow 2.x versions ([#​134](https://www.github.com/googleapis/python-tasks/issues/134)) ([fd3cb31](https://www.github.com/googleapis/python-tasks/commit/fd3cb31bc1d36e5b6373bfa3d3bb9bb65aeb3f90))
--- ### Configuration 📅 **Schedule**: At any time (no schedule defined). 🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied. ♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox. 🔕 **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#github/googleapis/python-tasks). --- cloud-tasks/snippets/requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cloud-tasks/snippets/requirements.txt b/cloud-tasks/snippets/requirements.txt index b56d36f7993d..68147e188ca3 100644 --- a/cloud-tasks/snippets/requirements.txt +++ b/cloud-tasks/snippets/requirements.txt @@ -1 +1 @@ -google-cloud-tasks==2.4.0 +google-cloud-tasks==2.5.0 From b1e0306d75b6de78074213b29419365e7807f9e3 Mon Sep 17 00:00:00 2001 From: WhiteSource Renovate Date: Thu, 29 Jul 2021 13:08:04 +0200 Subject: [PATCH 19/62] chore(deps): update dependency google-cloud-tasks to v2.5.1 (#146) --- cloud-tasks/snippets/requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cloud-tasks/snippets/requirements.txt b/cloud-tasks/snippets/requirements.txt index 68147e188ca3..ce0a9070a985 100644 --- a/cloud-tasks/snippets/requirements.txt +++ b/cloud-tasks/snippets/requirements.txt @@ -1 +1 @@ -google-cloud-tasks==2.5.0 +google-cloud-tasks==2.5.1 From 516f8336c291dd188d28047086d2b34216fb2e29 Mon Sep 17 00:00:00 2001 From: "gcf-owl-bot[bot]" <78513119+gcf-owl-bot[bot]@users.noreply.github.com> Date: Wed, 11 Aug 2021 16:32:42 +0000 Subject: [PATCH 20/62] chore: fix INSTALL_LIBRARY_FROM_SOURCE in noxfile.py (#150) Source-Link: https://github.com/googleapis/synthtool/commit/6252f2cd074c38f37b44abe5e96d128733eb1b61 Post-Processor: gcr.io/repo-automation-bots/owlbot-python:latest@sha256:50e35228649c47b6ca82aa0be3ff9eb2afce51c82b66c4a03fe4afeb5ff6c0fc --- cloud-tasks/snippets/noxfile.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cloud-tasks/snippets/noxfile.py b/cloud-tasks/snippets/noxfile.py index 6a8ccdae22c9..125bb619cc49 100644 --- a/cloud-tasks/snippets/noxfile.py +++ b/cloud-tasks/snippets/noxfile.py @@ -96,7 +96,7 @@ def get_pytest_env_vars() -> Dict[str, str]: 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)) +INSTALL_LIBRARY_FROM_SOURCE = os.environ.get("INSTALL_LIBRARY_FROM_SOURCE", False) in ("True", "true") # # Style Checks # From 1e5bd370e843c0d5458ef2246e5176470c4c995d Mon Sep 17 00:00:00 2001 From: "gcf-owl-bot[bot]" <78513119+gcf-owl-bot[bot]@users.noreply.github.com> Date: Fri, 13 Aug 2021 11:54:32 -0400 Subject: [PATCH 21/62] chore: drop mention of Python 2.7 from templates (#152) Source-Link: https://github.com/googleapis/synthtool/commit/facee4cc1ea096cd8bcc008bb85929daa7c414c0 Post-Processor: gcr.io/repo-automation-bots/owlbot-python:latest@sha256:9743664022bd63a8084be67f144898314c7ca12f0a03e422ac17c733c129d803 Co-authored-by: Owl Bot --- cloud-tasks/snippets/noxfile.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cloud-tasks/snippets/noxfile.py b/cloud-tasks/snippets/noxfile.py index 125bb619cc49..e73436a15626 100644 --- a/cloud-tasks/snippets/noxfile.py +++ b/cloud-tasks/snippets/noxfile.py @@ -39,7 +39,7 @@ TEST_CONFIG = { # You can opt out from the test for specific Python versions. - 'ignored_versions': ["2.7"], + 'ignored_versions': [], # Old samples are opted out of enforcing Python type hints # All new samples should feature them @@ -88,8 +88,8 @@ def get_pytest_env_vars() -> Dict[str, str]: # DO NOT EDIT - automatically generated. -# All versions used to tested samples. -ALL_VERSIONS = ["2.7", "3.6", "3.7", "3.8", "3.9"] +# All versions used to test samples. +ALL_VERSIONS = ["3.6", "3.7", "3.8", "3.9"] # Any default versions that should be ignored. IGNORED_VERSIONS = TEST_CONFIG['ignored_versions'] From f9e2cb14f7526b91e1afffdfb1444ed8616d92d3 Mon Sep 17 00:00:00 2001 From: WhiteSource Renovate Date: Tue, 31 Aug 2021 16:40:26 +0200 Subject: [PATCH 22/62] chore(deps): update dependency pytest to v6.2.5 (#155) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit [![WhiteSource Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com) This PR contains the following updates: | Package | Change | Age | Adoption | Passing | Confidence | |---|---|---|---|---|---| | [pytest](https://docs.pytest.org/en/latest/) ([source](https://togithub.com/pytest-dev/pytest), [changelog](https://docs.pytest.org/en/stable/changelog.html)) | `==6.2.4` -> `==6.2.5` | [![age](https://badges.renovateapi.com/packages/pypi/pytest/6.2.5/age-slim)](https://docs.renovatebot.com/merge-confidence/) | [![adoption](https://badges.renovateapi.com/packages/pypi/pytest/6.2.5/adoption-slim)](https://docs.renovatebot.com/merge-confidence/) | [![passing](https://badges.renovateapi.com/packages/pypi/pytest/6.2.5/compatibility-slim/6.2.4)](https://docs.renovatebot.com/merge-confidence/) | [![confidence](https://badges.renovateapi.com/packages/pypi/pytest/6.2.5/confidence-slim/6.2.4)](https://docs.renovatebot.com/merge-confidence/) | --- ### Release Notes
pytest-dev/pytest ### [`v6.2.5`](https://togithub.com/pytest-dev/pytest/releases/6.2.5) [Compare Source](https://togithub.com/pytest-dev/pytest/compare/6.2.4...6.2.5) # pytest 6.2.5 (2021-08-29) ## Trivial/Internal Changes - [#​8494](https://togithub.com/pytest-dev/pytest/issues/8494): Python 3.10 is now supported. - [#​9040](https://togithub.com/pytest-dev/pytest/issues/9040): Enable compatibility with `pluggy 1.0` or later.
--- ### Configuration 📅 **Schedule**: At any time (no schedule defined). 🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied. ♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox. 🔕 **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#github/googleapis/python-tasks). --- cloud-tasks/snippets/requirements-test.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cloud-tasks/snippets/requirements-test.txt b/cloud-tasks/snippets/requirements-test.txt index 95ea1e6a02b0..927094516e65 100644 --- a/cloud-tasks/snippets/requirements-test.txt +++ b/cloud-tasks/snippets/requirements-test.txt @@ -1 +1 @@ -pytest==6.2.4 +pytest==6.2.5 From b79a142fcb9cfdca6c0590f8bbf462978abc4235 Mon Sep 17 00:00:00 2001 From: "gcf-owl-bot[bot]" <78513119+gcf-owl-bot[bot]@users.noreply.github.com> Date: Fri, 17 Sep 2021 15:36:40 +0000 Subject: [PATCH 23/62] chore: blacken samples noxfile template (#162) --- cloud-tasks/snippets/noxfile.py | 44 +++++++++++++++++++-------------- 1 file changed, 25 insertions(+), 19 deletions(-) diff --git a/cloud-tasks/snippets/noxfile.py b/cloud-tasks/snippets/noxfile.py index e73436a15626..b008613f03ff 100644 --- a/cloud-tasks/snippets/noxfile.py +++ b/cloud-tasks/snippets/noxfile.py @@ -39,17 +39,15 @@ TEST_CONFIG = { # You can opt out from the test for specific Python versions. - 'ignored_versions': [], - + "ignored_versions": [], # Old samples are opted out of enforcing Python type hints # All new samples should feature them - 'enforce_type_hints': False, - + "enforce_type_hints": False, # 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": "GOOGLE_CLOUD_PROJECT", # 'gcloud_project_env': 'BUILD_SPECIFIC_GCLOUD_PROJECT', # If you need to use a specific version of pip, # change pip_version_override to the string representation @@ -57,13 +55,13 @@ "pip_version_override": None, # A dictionary you want to inject into your test. Don't put any # secrets here. These values will override predefined values. - 'envs': {}, + "envs": {}, } try: # Ensure we can import noxfile_config in the project's directory. - sys.path.append('.') + sys.path.append(".") from noxfile_config import TEST_CONFIG_OVERRIDE except ImportError as e: print("No user noxfile_config found: detail: {}".format(e)) @@ -78,12 +76,12 @@ def get_pytest_env_vars() -> Dict[str, str]: ret = {} # Override the GCLOUD_PROJECT and the alias. - env_key = TEST_CONFIG['gcloud_project_env'] + env_key = TEST_CONFIG["gcloud_project_env"] # This should error out if not set. - ret['GOOGLE_CLOUD_PROJECT'] = os.environ[env_key] + ret["GOOGLE_CLOUD_PROJECT"] = os.environ[env_key] # Apply user supplied envs. - ret.update(TEST_CONFIG['envs']) + ret.update(TEST_CONFIG["envs"]) return ret @@ -92,11 +90,14 @@ def get_pytest_env_vars() -> Dict[str, str]: ALL_VERSIONS = ["3.6", "3.7", "3.8", "3.9"] # Any default versions that should be ignored. -IGNORED_VERSIONS = TEST_CONFIG['ignored_versions'] +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 = os.environ.get("INSTALL_LIBRARY_FROM_SOURCE", False) in ("True", "true") +INSTALL_LIBRARY_FROM_SOURCE = os.environ.get("INSTALL_LIBRARY_FROM_SOURCE", False) in ( + "True", + "true", +) # # Style Checks # @@ -141,7 +142,7 @@ def _determine_local_import_names(start_dir: str) -> List[str]: @nox.session def lint(session: nox.sessions.Session) -> None: - if not TEST_CONFIG['enforce_type_hints']: + if not TEST_CONFIG["enforce_type_hints"]: session.install("flake8", "flake8-import-order") else: session.install("flake8", "flake8-import-order", "flake8-annotations") @@ -150,9 +151,11 @@ def lint(session: nox.sessions.Session) -> None: args = FLAKE8_COMMON_ARGS + [ "--application-import-names", ",".join(local_names), - "." + ".", ] session.run("flake8", *args) + + # # Black # @@ -165,6 +168,7 @@ def blacken(session: nox.sessions.Session) -> None: session.run("black", *python_files) + # # Sample Tests # @@ -173,7 +177,9 @@ def blacken(session: nox.sessions.Session) -> None: PYTEST_COMMON_ARGS = ["--junitxml=sponge_log.xml"] -def _session_tests(session: nox.sessions.Session, post_install: Callable = None) -> None: +def _session_tests( + session: nox.sessions.Session, post_install: Callable = None +) -> None: if TEST_CONFIG["pip_version_override"]: pip_version = TEST_CONFIG["pip_version_override"] session.install(f"pip=={pip_version}") @@ -203,7 +209,7 @@ def _session_tests(session: nox.sessions.Session, post_install: Callable = None) # 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() + env=get_pytest_env_vars(), ) @@ -213,9 +219,9 @@ def py(session: nox.sessions.Session) -> None: if session.python in TESTED_VERSIONS: _session_tests(session) else: - session.skip("SKIPPED: {} tests are disabled for this sample.".format( - session.python - )) + session.skip( + "SKIPPED: {} tests are disabled for this sample.".format(session.python) + ) # From 8a353ba7a90096387224f7d27f3857f9f5501840 Mon Sep 17 00:00:00 2001 From: WhiteSource Renovate Date: Fri, 24 Sep 2021 20:04:32 +0200 Subject: [PATCH 24/62] chore(deps): update dependency google-cloud-tasks to v2.5.2 (#167) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit [![WhiteSource Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com) This PR contains the following updates: | Package | Change | Age | Adoption | Passing | Confidence | |---|---|---|---|---|---| | [google-cloud-tasks](https://togithub.com/googleapis/python-tasks) | `==2.5.1` -> `==2.5.2` | [![age](https://badges.renovateapi.com/packages/pypi/google-cloud-tasks/2.5.2/age-slim)](https://docs.renovatebot.com/merge-confidence/) | [![adoption](https://badges.renovateapi.com/packages/pypi/google-cloud-tasks/2.5.2/adoption-slim)](https://docs.renovatebot.com/merge-confidence/) | [![passing](https://badges.renovateapi.com/packages/pypi/google-cloud-tasks/2.5.2/compatibility-slim/2.5.1)](https://docs.renovatebot.com/merge-confidence/) | [![confidence](https://badges.renovateapi.com/packages/pypi/google-cloud-tasks/2.5.2/confidence-slim/2.5.1)](https://docs.renovatebot.com/merge-confidence/) | --- ### Release Notes
googleapis/python-tasks ### [`v2.5.2`](https://togithub.com/googleapis/python-tasks/blob/master/CHANGELOG.md#​252-httpswwwgithubcomgoogleapispython-taskscomparev251v252-2021-09-24) [Compare Source](https://togithub.com/googleapis/python-tasks/compare/v2.5.1...v2.5.2)
--- ### Configuration 📅 **Schedule**: At any time (no schedule defined). 🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied. ♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox. 🔕 **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#github/googleapis/python-tasks). --- cloud-tasks/snippets/requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cloud-tasks/snippets/requirements.txt b/cloud-tasks/snippets/requirements.txt index ce0a9070a985..7a2a4e99fefd 100644 --- a/cloud-tasks/snippets/requirements.txt +++ b/cloud-tasks/snippets/requirements.txt @@ -1 +1 @@ -google-cloud-tasks==2.5.1 +google-cloud-tasks==2.5.2 From f6c8b1b8a7bfbf300b80bc5ba4399a9c4d2e678c Mon Sep 17 00:00:00 2001 From: "gcf-owl-bot[bot]" <78513119+gcf-owl-bot[bot]@users.noreply.github.com> Date: Thu, 30 Sep 2021 15:44:38 +0000 Subject: [PATCH 25/62] chore: fail samples nox session if python version is missing (#170) --- cloud-tasks/snippets/noxfile.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/cloud-tasks/snippets/noxfile.py b/cloud-tasks/snippets/noxfile.py index b008613f03ff..1fd8956fbf01 100644 --- a/cloud-tasks/snippets/noxfile.py +++ b/cloud-tasks/snippets/noxfile.py @@ -98,6 +98,10 @@ def get_pytest_env_vars() -> Dict[str, str]: "True", "true", ) + +# Error if a python version is missing +nox.options.error_on_missing_interpreters = True + # # Style Checks # From 28f909ab70ac1f80ba7577d9b84410b40acf542f Mon Sep 17 00:00:00 2001 From: WhiteSource Renovate Date: Thu, 7 Oct 2021 14:13:48 +0200 Subject: [PATCH 26/62] chore(deps): update dependency google-cloud-tasks to v2.6.0 (#175) --- cloud-tasks/snippets/requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cloud-tasks/snippets/requirements.txt b/cloud-tasks/snippets/requirements.txt index 7a2a4e99fefd..b9d3101c33ef 100644 --- a/cloud-tasks/snippets/requirements.txt +++ b/cloud-tasks/snippets/requirements.txt @@ -1 +1 @@ -google-cloud-tasks==2.5.2 +google-cloud-tasks==2.6.0 From cc50e86641ce3fdc6ddc28b249803487a3f6dc93 Mon Sep 17 00:00:00 2001 From: "gcf-owl-bot[bot]" <78513119+gcf-owl-bot[bot]@users.noreply.github.com> Date: Fri, 8 Oct 2021 17:16:42 +0000 Subject: [PATCH 27/62] chore(python): Add kokoro configs for python 3.10 samples testing (#179) --- cloud-tasks/snippets/noxfile.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cloud-tasks/snippets/noxfile.py b/cloud-tasks/snippets/noxfile.py index 1fd8956fbf01..93a9122cc457 100644 --- a/cloud-tasks/snippets/noxfile.py +++ b/cloud-tasks/snippets/noxfile.py @@ -87,7 +87,7 @@ def get_pytest_env_vars() -> Dict[str, str]: # DO NOT EDIT - automatically generated. # All versions used to test samples. -ALL_VERSIONS = ["3.6", "3.7", "3.8", "3.9"] +ALL_VERSIONS = ["3.6", "3.7", "3.8", "3.9", "3.10"] # Any default versions that should be ignored. IGNORED_VERSIONS = TEST_CONFIG["ignored_versions"] From 053acd602c932d51e8bbadd7476b9bf3908d3129 Mon Sep 17 00:00:00 2001 From: WhiteSource Renovate Date: Mon, 25 Oct 2021 15:54:44 +0200 Subject: [PATCH 28/62] chore(deps): update dependency google-cloud-tasks to v2.7.0 (#185) --- cloud-tasks/snippets/requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cloud-tasks/snippets/requirements.txt b/cloud-tasks/snippets/requirements.txt index b9d3101c33ef..dd1833fe83d4 100644 --- a/cloud-tasks/snippets/requirements.txt +++ b/cloud-tasks/snippets/requirements.txt @@ -1 +1 @@ -google-cloud-tasks==2.6.0 +google-cloud-tasks==2.7.0 From 6f90bd15969a57693b71d66e905e3f1f3403e3d1 Mon Sep 17 00:00:00 2001 From: WhiteSource Renovate Date: Tue, 2 Nov 2021 18:37:29 +0100 Subject: [PATCH 29/62] chore(deps): update dependency google-cloud-tasks to v2.7.1 (#189) --- cloud-tasks/snippets/requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cloud-tasks/snippets/requirements.txt b/cloud-tasks/snippets/requirements.txt index dd1833fe83d4..912c8ddab583 100644 --- a/cloud-tasks/snippets/requirements.txt +++ b/cloud-tasks/snippets/requirements.txt @@ -1 +1 @@ -google-cloud-tasks==2.7.0 +google-cloud-tasks==2.7.1 From dad3ee68607daa4cb8b969d4398e6336b92e0d95 Mon Sep 17 00:00:00 2001 From: Anthonios Partheniou Date: Mon, 22 Nov 2021 14:34:12 -0500 Subject: [PATCH 30/62] chore: delete owlbot.py (#184) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * chore: delete owlbot.py * 🦉 Updates from OwlBot See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md Co-authored-by: Owl Bot --- cloud-tasks/snippets/create_http_task_with_token.py | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/cloud-tasks/snippets/create_http_task_with_token.py b/cloud-tasks/snippets/create_http_task_with_token.py index f09e85382bec..88888bcdbf00 100644 --- a/cloud-tasks/snippets/create_http_task_with_token.py +++ b/cloud-tasks/snippets/create_http_task_with_token.py @@ -16,13 +16,7 @@ def create_http_task( - project, - queue, - location, - url, - service_account_email, - audience=None, - payload=None, + project, queue, location, url, service_account_email, audience=None, payload=None, ): # [START cloud_tasks_create_http_task_with_token] """Create a task for a given queue with an arbitrary payload.""" @@ -49,7 +43,10 @@ def create_http_task( "http_request": { # Specify the type of request. "http_method": tasks_v2.HttpMethod.POST, "url": url, # The full url path that the task will be sent to. - "oidc_token": {"service_account_email": service_account_email, "audience": audience}, + "oidc_token": { + "service_account_email": service_account_email, + "audience": audience, + }, } } From 76cf41c2362c78307958eac633660e4924f866c1 Mon Sep 17 00:00:00 2001 From: "gcf-owl-bot[bot]" <78513119+gcf-owl-bot[bot]@users.noreply.github.com> Date: Tue, 11 Jan 2022 07:47:26 -0500 Subject: [PATCH 31/62] chore(samples): Add check for tests in directory (#204) Source-Link: https://github.com/googleapis/synthtool/commit/52aef91f8d25223d9dbdb4aebd94ba8eea2101f3 Post-Processor: gcr.io/cloud-devrel-public-resources/owlbot-python:latest@sha256:36a95b8f494e4674dc9eee9af98961293b51b86b3649942aac800ae6c1f796d4 Co-authored-by: Owl Bot --- cloud-tasks/snippets/noxfile.py | 70 ++++++++++++++++++--------------- 1 file changed, 39 insertions(+), 31 deletions(-) diff --git a/cloud-tasks/snippets/noxfile.py b/cloud-tasks/snippets/noxfile.py index 93a9122cc457..3bbef5d54f44 100644 --- a/cloud-tasks/snippets/noxfile.py +++ b/cloud-tasks/snippets/noxfile.py @@ -14,6 +14,7 @@ from __future__ import print_function +import glob import os from pathlib import Path import sys @@ -184,37 +185,44 @@ def blacken(session: nox.sessions.Session) -> None: def _session_tests( session: nox.sessions.Session, post_install: Callable = None ) -> None: - if TEST_CONFIG["pip_version_override"]: - pip_version = TEST_CONFIG["pip_version_override"] - session.install(f"pip=={pip_version}") - """Runs py.test for a particular project.""" - if os.path.exists("requirements.txt"): - if os.path.exists("constraints.txt"): - session.install("-r", "requirements.txt", "-c", "constraints.txt") - else: - session.install("-r", "requirements.txt") - - if os.path.exists("requirements-test.txt"): - if os.path.exists("constraints-test.txt"): - session.install("-r", "requirements-test.txt", "-c", "constraints-test.txt") - else: - 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(), - ) + # check for presence of tests + test_list = glob.glob("*_test.py") + glob.glob("test_*.py") + if len(test_list) == 0: + print("No tests found, skipping directory.") + else: + if TEST_CONFIG["pip_version_override"]: + pip_version = TEST_CONFIG["pip_version_override"] + session.install(f"pip=={pip_version}") + """Runs py.test for a particular project.""" + if os.path.exists("requirements.txt"): + if os.path.exists("constraints.txt"): + session.install("-r", "requirements.txt", "-c", "constraints.txt") + else: + session.install("-r", "requirements.txt") + + if os.path.exists("requirements-test.txt"): + if os.path.exists("constraints-test.txt"): + session.install( + "-r", "requirements-test.txt", "-c", "constraints-test.txt" + ) + else: + 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) From 4b4614be87235d1342e17ae94989e66f65f5ca51 Mon Sep 17 00:00:00 2001 From: WhiteSource Renovate Date: Thu, 13 Jan 2022 20:19:36 +0100 Subject: [PATCH 32/62] chore(deps): update dependency google-cloud-tasks to v2.7.2 (#206) Co-authored-by: Leah E. Cole <6719667+leahecole@users.noreply.github.com> --- cloud-tasks/snippets/requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cloud-tasks/snippets/requirements.txt b/cloud-tasks/snippets/requirements.txt index 912c8ddab583..4128ab74be3b 100644 --- a/cloud-tasks/snippets/requirements.txt +++ b/cloud-tasks/snippets/requirements.txt @@ -1 +1 @@ -google-cloud-tasks==2.7.1 +google-cloud-tasks==2.7.2 From 1e56320af989bd7e42ab2cffdcfb6ba88bfd52b4 Mon Sep 17 00:00:00 2001 From: Averi Kitsch Date: Thu, 13 Jan 2022 15:20:08 -0800 Subject: [PATCH 33/62] chore: update samples (#207) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * chore: update samples * 🦉 Updates from OwlBot See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * Update create_http_task_test.py Co-authored-by: Owl Bot Co-authored-by: Charles Engelke --- cloud-tasks/snippets/create_http_task.py | 17 +++++++++++++++-- cloud-tasks/snippets/create_http_task_test.py | 12 ++++++++++++ 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/cloud-tasks/snippets/create_http_task.py b/cloud-tasks/snippets/create_http_task.py index e6d7435e1337..40e735b3cb1f 100644 --- a/cloud-tasks/snippets/create_http_task.py +++ b/cloud-tasks/snippets/create_http_task.py @@ -18,13 +18,20 @@ def create_http_task( - project, queue, location, url, payload=None, in_seconds=None, task_name=None + project, + queue, + location, + url, + payload=None, + in_seconds=None, + task_name=None, + deadline=None, ): # [START cloud_tasks_create_http_task] """Create a task for a given queue with an arbitrary payload.""" from google.cloud import tasks_v2 - from google.protobuf import timestamp_pb2 + from google.protobuf import timestamp_pb2, duration_pb2 import datetime import json @@ -39,6 +46,7 @@ def create_http_task( # payload = 'hello' or {'param': 'value'} for application/json # in_seconds = 180 # task_name = 'my-unique-task' + # deadline = 900 # Construct the fully qualified queue name. parent = client.queue_path(project, location, queue) @@ -78,6 +86,11 @@ def create_http_task( # Add the name to tasks. task["name"] = client.task_path(project, location, queue, task_name) + if deadline is not None: + # Add dispatch deadline for requests sent to the worker. + duration = duration_pb2.Duration() + task["dispatch_deadline"] = duration.FromSeconds(deadline) + # Use the client to build and send the task. response = client.create_task(request={"parent": parent, "task": task}) diff --git a/cloud-tasks/snippets/create_http_task_test.py b/cloud-tasks/snippets/create_http_task_test.py index 20cfced96b9c..a66f3287d1e1 100644 --- a/cloud-tasks/snippets/create_http_task_test.py +++ b/cloud-tasks/snippets/create_http_task_test.py @@ -46,3 +46,15 @@ def test_create_http_task(test_queue): TEST_PROJECT_ID, TEST_QUEUE_NAME, TEST_LOCATION, url ) assert TEST_QUEUE_NAME in result.name + + result = create_http_task.create_http_task( + TEST_PROJECT_ID, + TEST_QUEUE_NAME, + TEST_LOCATION, + url, + payload="hello", + in_seconds=180, + task_name=uuid.uuid4().hex, + deadline=900, + ) + assert TEST_QUEUE_NAME in result.name From 4665108b3cb7165ce4cfaefb01240f516b4d3cc6 Mon Sep 17 00:00:00 2001 From: "gcf-owl-bot[bot]" <78513119+gcf-owl-bot[bot]@users.noreply.github.com> Date: Tue, 18 Jan 2022 20:37:59 -0500 Subject: [PATCH 34/62] chore(python): Noxfile recognizes that tests can live in a folder (#210) Source-Link: https://github.com/googleapis/synthtool/commit/4760d8dce1351d93658cb11d02a1b7ceb23ae5d7 Post-Processor: gcr.io/cloud-devrel-public-resources/owlbot-python:latest@sha256:f0e4b51deef56bed74d3e2359c583fc104a8d6367da3984fc5c66938db738828 Co-authored-by: Owl Bot --- cloud-tasks/snippets/noxfile.py | 1 + 1 file changed, 1 insertion(+) diff --git a/cloud-tasks/snippets/noxfile.py b/cloud-tasks/snippets/noxfile.py index 3bbef5d54f44..20cdfc620138 100644 --- a/cloud-tasks/snippets/noxfile.py +++ b/cloud-tasks/snippets/noxfile.py @@ -187,6 +187,7 @@ def _session_tests( ) -> None: # check for presence of tests test_list = glob.glob("*_test.py") + glob.glob("test_*.py") + test_list.extend(glob.glob("tests")) if len(test_list) == 0: print("No tests found, skipping directory.") else: From 423a313dd946e001766fb4628d1857e87d85422b Mon Sep 17 00:00:00 2001 From: WhiteSource Renovate Date: Mon, 7 Feb 2022 17:15:31 +0100 Subject: [PATCH 35/62] chore(deps): update dependency pytest to v7 (#219) --- cloud-tasks/snippets/requirements-test.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cloud-tasks/snippets/requirements-test.txt b/cloud-tasks/snippets/requirements-test.txt index 927094516e65..4a46ff600804 100644 --- a/cloud-tasks/snippets/requirements-test.txt +++ b/cloud-tasks/snippets/requirements-test.txt @@ -1 +1 @@ -pytest==6.2.5 +pytest==7.0.0 From f4c8e64438e8994f10ce4cb8d0791878e0d45884 Mon Sep 17 00:00:00 2001 From: WhiteSource Renovate Date: Mon, 14 Feb 2022 17:08:55 +0100 Subject: [PATCH 36/62] chore(deps): update dependency pytest to v7.0.1 (#221) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit [![WhiteSource Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com) This PR contains the following updates: | Package | Change | Age | Adoption | Passing | Confidence | |---|---|---|---|---|---| | [pytest](https://docs.pytest.org/en/latest/) ([source](https://togithub.com/pytest-dev/pytest), [changelog](https://docs.pytest.org/en/stable/changelog.html)) | `==7.0.0` -> `==7.0.1` | [![age](https://badges.renovateapi.com/packages/pypi/pytest/7.0.1/age-slim)](https://docs.renovatebot.com/merge-confidence/) | [![adoption](https://badges.renovateapi.com/packages/pypi/pytest/7.0.1/adoption-slim)](https://docs.renovatebot.com/merge-confidence/) | [![passing](https://badges.renovateapi.com/packages/pypi/pytest/7.0.1/compatibility-slim/7.0.0)](https://docs.renovatebot.com/merge-confidence/) | [![confidence](https://badges.renovateapi.com/packages/pypi/pytest/7.0.1/confidence-slim/7.0.0)](https://docs.renovatebot.com/merge-confidence/) | --- ### Release Notes
pytest-dev/pytest ### [`v7.0.1`](https://togithub.com/pytest-dev/pytest/releases/7.0.1) [Compare Source](https://togithub.com/pytest-dev/pytest/compare/7.0.0...7.0.1) # pytest 7.0.1 (2022-02-11) ## Bug Fixes - [#​9608](https://togithub.com/pytest-dev/pytest/issues/9608): Fix invalid importing of `importlib.readers` in Python 3.9. - [#​9610](https://togithub.com/pytest-dev/pytest/issues/9610): Restore \[UnitTestFunction.obj]{.title-ref} to return unbound rather than bound method. Fixes a crash during a failed teardown in unittest TestCases with non-default \[\__init\_\_]{.title-ref}. Regressed in pytest 7.0.0. - [#​9636](https://togithub.com/pytest-dev/pytest/issues/9636): The `pythonpath` plugin was renamed to `python_path`. This avoids a conflict with the `pytest-pythonpath` plugin. - [#​9642](https://togithub.com/pytest-dev/pytest/issues/9642): Fix running tests by id with `::` in the parametrize portion. - [#​9643](https://togithub.com/pytest-dev/pytest/issues/9643): Delay issuing a `~pytest.PytestWarning`{.interpreted-text role="class"} about diamond inheritance involving `~pytest.Item`{.interpreted-text role="class"} and `~pytest.Collector`{.interpreted-text role="class"} so it can be filtered using `standard warning filters `{.interpreted-text role="ref"}.
--- ### Configuration 📅 **Schedule**: At any time (no schedule defined). 🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied. ♻ **Rebasing**: Renovate will not automatically rebase this PR, because other commits have been found. 🔕 **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] If you want to rebase/retry this PR, click this checkbox. --- This PR has been generated by [WhiteSource Renovate](https://renovate.whitesourcesoftware.com). View repository job log [here](https://app.renovatebot.com/dashboard#github/googleapis/python-tasks). --- cloud-tasks/snippets/requirements-test.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cloud-tasks/snippets/requirements-test.txt b/cloud-tasks/snippets/requirements-test.txt index 4a46ff600804..c2845bffbe89 100644 --- a/cloud-tasks/snippets/requirements-test.txt +++ b/cloud-tasks/snippets/requirements-test.txt @@ -1 +1 @@ -pytest==7.0.0 +pytest==7.0.1 From 63577c86ae5f73e37253f41579f30900833811f3 Mon Sep 17 00:00:00 2001 From: WhiteSource Renovate Date: Thu, 24 Feb 2022 16:51:38 +0100 Subject: [PATCH 37/62] chore(deps): update dependency google-cloud-tasks to v2.8.0 (#222) --- cloud-tasks/snippets/requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cloud-tasks/snippets/requirements.txt b/cloud-tasks/snippets/requirements.txt index 4128ab74be3b..d5240056c321 100644 --- a/cloud-tasks/snippets/requirements.txt +++ b/cloud-tasks/snippets/requirements.txt @@ -1 +1 @@ -google-cloud-tasks==2.7.2 +google-cloud-tasks==2.8.0 From 54e73a6d55fa4a7eed1399ac57517b6b46ee3a88 Mon Sep 17 00:00:00 2001 From: "gcf-owl-bot[bot]" <78513119+gcf-owl-bot[bot]@users.noreply.github.com> Date: Fri, 4 Mar 2022 13:20:29 -0500 Subject: [PATCH 38/62] chore: Adding support for pytest-xdist and pytest-parallel (#233) Source-Link: https://github.com/googleapis/synthtool/commit/82f5cb283efffe96e1b6cd634738e0e7de2cd90a Post-Processor: gcr.io/cloud-devrel-public-resources/owlbot-python:latest@sha256:5d8da01438ece4021d135433f2cf3227aa39ef0eaccc941d62aa35e6902832ae Co-authored-by: Owl Bot Co-authored-by: Anthonios Partheniou --- cloud-tasks/snippets/noxfile.py | 78 +++++++++++++++++++-------------- 1 file changed, 44 insertions(+), 34 deletions(-) diff --git a/cloud-tasks/snippets/noxfile.py b/cloud-tasks/snippets/noxfile.py index 20cdfc620138..85f5836dba3a 100644 --- a/cloud-tasks/snippets/noxfile.py +++ b/cloud-tasks/snippets/noxfile.py @@ -188,42 +188,52 @@ def _session_tests( # check for presence of tests test_list = glob.glob("*_test.py") + glob.glob("test_*.py") test_list.extend(glob.glob("tests")) + if len(test_list) == 0: print("No tests found, skipping directory.") - else: - if TEST_CONFIG["pip_version_override"]: - pip_version = TEST_CONFIG["pip_version_override"] - session.install(f"pip=={pip_version}") - """Runs py.test for a particular project.""" - if os.path.exists("requirements.txt"): - if os.path.exists("constraints.txt"): - session.install("-r", "requirements.txt", "-c", "constraints.txt") - else: - session.install("-r", "requirements.txt") - - if os.path.exists("requirements-test.txt"): - if os.path.exists("constraints-test.txt"): - session.install( - "-r", "requirements-test.txt", "-c", "constraints-test.txt" - ) - else: - 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(), - ) + return + + if TEST_CONFIG["pip_version_override"]: + pip_version = TEST_CONFIG["pip_version_override"] + session.install(f"pip=={pip_version}") + """Runs py.test for a particular project.""" + concurrent_args = [] + if os.path.exists("requirements.txt"): + if os.path.exists("constraints.txt"): + session.install("-r", "requirements.txt", "-c", "constraints.txt") + else: + session.install("-r", "requirements.txt") + with open("requirements.txt") as rfile: + packages = rfile.read() + + if os.path.exists("requirements-test.txt"): + if os.path.exists("constraints-test.txt"): + session.install("-r", "requirements-test.txt", "-c", "constraints-test.txt") + else: + session.install("-r", "requirements-test.txt") + with open("requirements-test.txt") as rtfile: + packages += rtfile.read() + + if INSTALL_LIBRARY_FROM_SOURCE: + session.install("-e", _get_repo_root()) + + if post_install: + post_install(session) + + if "pytest-parallel" in packages: + concurrent_args.extend(["--workers", "auto", "--tests-per-worker", "auto"]) + elif "pytest-xdist" in packages: + concurrent_args.extend(["-n", "auto"]) + + session.run( + "pytest", + *(PYTEST_COMMON_ARGS + session.posargs + concurrent_args), + # 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) From 95f8f52f3a186e18a08bf9adb356f88a10e452d0 Mon Sep 17 00:00:00 2001 From: WhiteSource Renovate Date: Mon, 7 Mar 2022 20:50:53 +0100 Subject: [PATCH 39/62] chore(deps): update dependency google-cloud-tasks to v2.8.1 (#236) --- cloud-tasks/snippets/requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cloud-tasks/snippets/requirements.txt b/cloud-tasks/snippets/requirements.txt index d5240056c321..f2b4ae7f8f8d 100644 --- a/cloud-tasks/snippets/requirements.txt +++ b/cloud-tasks/snippets/requirements.txt @@ -1 +1 @@ -google-cloud-tasks==2.8.0 +google-cloud-tasks==2.8.1 From d7278bdd4ddc36a90da4cd8b96276e31eb783d7c Mon Sep 17 00:00:00 2001 From: WhiteSource Renovate Date: Sun, 13 Mar 2022 17:08:35 +0100 Subject: [PATCH 40/62] chore(deps): update dependency pytest to v7.1.0 (#238) --- cloud-tasks/snippets/requirements-test.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cloud-tasks/snippets/requirements-test.txt b/cloud-tasks/snippets/requirements-test.txt index c2845bffbe89..824a8a7a0ce6 100644 --- a/cloud-tasks/snippets/requirements-test.txt +++ b/cloud-tasks/snippets/requirements-test.txt @@ -1 +1 @@ -pytest==7.0.1 +pytest==7.1.0 From f94cb215a542041a8124644720b48ebbd70ebf31 Mon Sep 17 00:00:00 2001 From: WhiteSource Renovate Date: Sat, 19 Mar 2022 11:56:57 +0100 Subject: [PATCH 41/62] chore(deps): update dependency pytest to v7.1.1 (#239) --- cloud-tasks/snippets/requirements-test.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cloud-tasks/snippets/requirements-test.txt b/cloud-tasks/snippets/requirements-test.txt index 824a8a7a0ce6..4f6bf643fc5e 100644 --- a/cloud-tasks/snippets/requirements-test.txt +++ b/cloud-tasks/snippets/requirements-test.txt @@ -1 +1 @@ -pytest==7.1.0 +pytest==7.1.1 From ea78cc06c24cc1b3f36160af8f1f68d9b139d18e Mon Sep 17 00:00:00 2001 From: "gcf-owl-bot[bot]" <78513119+gcf-owl-bot[bot]@users.noreply.github.com> Date: Tue, 29 Mar 2022 00:02:23 +0000 Subject: [PATCH 42/62] chore(python): use black==22.3.0 (#243) Source-Link: https://github.com/googleapis/synthtool/commit/6fab84af09f2cf89a031fd8671d1def6b2931b11 Post-Processor: gcr.io/cloud-devrel-public-resources/owlbot-python:latest@sha256:7cffbc10910c3ab1b852c05114a08d374c195a81cdec1d4a67a1d129331d0bfe --- cloud-tasks/snippets/create_http_task.py | 8 ++++++-- cloud-tasks/snippets/create_http_task_with_token.py | 8 +++++++- cloud-tasks/snippets/noxfile.py | 4 ++-- 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/cloud-tasks/snippets/create_http_task.py b/cloud-tasks/snippets/create_http_task.py index 40e735b3cb1f..7bf75d41d738 100644 --- a/cloud-tasks/snippets/create_http_task.py +++ b/cloud-tasks/snippets/create_http_task.py @@ -106,7 +106,9 @@ def create_http_task( ) parser.add_argument( - "--project", help="Project of the queue to add the task to.", required=True, + "--project", + help="Project of the queue to add the task to.", + required=True, ) parser.add_argument( @@ -116,7 +118,9 @@ def create_http_task( ) parser.add_argument( - "--location", help="Location of the queue to add the task to.", required=True, + "--location", + help="Location of the queue to add the task to.", + required=True, ) parser.add_argument( diff --git a/cloud-tasks/snippets/create_http_task_with_token.py b/cloud-tasks/snippets/create_http_task_with_token.py index 88888bcdbf00..0e157eb9fa8d 100644 --- a/cloud-tasks/snippets/create_http_task_with_token.py +++ b/cloud-tasks/snippets/create_http_task_with_token.py @@ -16,7 +16,13 @@ def create_http_task( - project, queue, location, url, service_account_email, audience=None, payload=None, + project, + queue, + location, + url, + service_account_email, + audience=None, + payload=None, ): # [START cloud_tasks_create_http_task_with_token] """Create a task for a given queue with an arbitrary payload.""" diff --git a/cloud-tasks/snippets/noxfile.py b/cloud-tasks/snippets/noxfile.py index 85f5836dba3a..25f87a215d4c 100644 --- a/cloud-tasks/snippets/noxfile.py +++ b/cloud-tasks/snippets/noxfile.py @@ -29,7 +29,7 @@ # WARNING - WARNING - WARNING - WARNING - WARNING # WARNING - WARNING - WARNING - WARNING - WARNING -BLACK_VERSION = "black==19.10b0" +BLACK_VERSION = "black==22.3.0" # Copy `noxfile_config.py` to your directory and modify it instead. @@ -253,7 +253,7 @@ def py(session: nox.sessions.Session) -> None: def _get_repo_root() -> Optional[str]: - """ Returns the root folder of the project. """ + """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): From f5c55ef5b77c58540f509d8dbd40340edcab0d1b Mon Sep 17 00:00:00 2001 From: "gcf-owl-bot[bot]" <78513119+gcf-owl-bot[bot]@users.noreply.github.com> Date: Wed, 20 Apr 2022 21:11:32 -0400 Subject: [PATCH 43/62] chore(python): add nox session to sort python imports (#254) Source-Link: https://github.com/googleapis/synthtool/commit/1b71c10e20de7ed3f97f692f99a0e3399b67049f Post-Processor: gcr.io/cloud-devrel-public-resources/owlbot-python:latest@sha256:00c9d764fd1cd56265f12a5ef4b99a0c9e87cf261018099141e2ca5158890416 Co-authored-by: Owl Bot --- cloud-tasks/snippets/create_http_task.py | 5 +++-- cloud-tasks/snippets/noxfile.py | 23 ++++++++++++++++++++++- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/cloud-tasks/snippets/create_http_task.py b/cloud-tasks/snippets/create_http_task.py index 7bf75d41d738..13057fa8c5ea 100644 --- a/cloud-tasks/snippets/create_http_task.py +++ b/cloud-tasks/snippets/create_http_task.py @@ -30,11 +30,12 @@ def create_http_task( # [START cloud_tasks_create_http_task] """Create a task for a given queue with an arbitrary payload.""" - from google.cloud import tasks_v2 - from google.protobuf import timestamp_pb2, duration_pb2 import datetime import json + from google.cloud import tasks_v2 + from google.protobuf import duration_pb2, timestamp_pb2 + # Create a client. client = tasks_v2.CloudTasksClient() diff --git a/cloud-tasks/snippets/noxfile.py b/cloud-tasks/snippets/noxfile.py index 25f87a215d4c..3b3ffa5d2b0f 100644 --- a/cloud-tasks/snippets/noxfile.py +++ b/cloud-tasks/snippets/noxfile.py @@ -22,7 +22,6 @@ import nox - # WARNING - WARNING - WARNING - WARNING - WARNING # WARNING - WARNING - WARNING - WARNING - WARNING # DO NOT EDIT THIS FILE EVER! @@ -30,6 +29,7 @@ # WARNING - WARNING - WARNING - WARNING - WARNING BLACK_VERSION = "black==22.3.0" +ISORT_VERSION = "isort==5.10.1" # Copy `noxfile_config.py` to your directory and modify it instead. @@ -168,12 +168,33 @@ def lint(session: nox.sessions.Session) -> None: @nox.session def blacken(session: nox.sessions.Session) -> None: + """Run black. Format code to uniform standard.""" session.install(BLACK_VERSION) python_files = [path for path in os.listdir(".") if path.endswith(".py")] session.run("black", *python_files) +# +# format = isort + black +# + + +@nox.session +def format(session: nox.sessions.Session) -> None: + """ + Run isort to sort imports. Then run black + to format code to uniform standard. + """ + session.install(BLACK_VERSION, ISORT_VERSION) + python_files = [path for path in os.listdir(".") if path.endswith(".py")] + + # Use the --fss option to sort imports using strict alphabetical order. + # See https://pycqa.github.io/isort/docs/configuration/options.html#force-sort-within-sections + session.run("isort", "--fss", *python_files) + session.run("black", *python_files) + + # # Sample Tests # From 353a8b6666b1179238b209de0d26b94505c34b5a Mon Sep 17 00:00:00 2001 From: WhiteSource Renovate Date: Mon, 25 Apr 2022 17:04:27 +0200 Subject: [PATCH 44/62] chore(deps): update dependency pytest to v7.1.2 (#257) --- cloud-tasks/snippets/requirements-test.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cloud-tasks/snippets/requirements-test.txt b/cloud-tasks/snippets/requirements-test.txt index 4f6bf643fc5e..d00689e0623a 100644 --- a/cloud-tasks/snippets/requirements-test.txt +++ b/cloud-tasks/snippets/requirements-test.txt @@ -1 +1 @@ -pytest==7.1.1 +pytest==7.1.2 From f71f1a26436976f039deb893e5d72d85aa90aa76 Mon Sep 17 00:00:00 2001 From: WhiteSource Renovate Date: Sat, 7 May 2022 15:16:05 +0200 Subject: [PATCH 45/62] chore(deps): update dependency google-cloud-tasks to v2.9.0 (#260) --- cloud-tasks/snippets/requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cloud-tasks/snippets/requirements.txt b/cloud-tasks/snippets/requirements.txt index f2b4ae7f8f8d..55dd827e125d 100644 --- a/cloud-tasks/snippets/requirements.txt +++ b/cloud-tasks/snippets/requirements.txt @@ -1 +1 @@ -google-cloud-tasks==2.8.1 +google-cloud-tasks==2.9.0 From c75fc596b302a2a72b60d9a8fa80da2be05a6f36 Mon Sep 17 00:00:00 2001 From: "gcf-owl-bot[bot]" <78513119+gcf-owl-bot[bot]@users.noreply.github.com> Date: Sat, 9 Jul 2022 06:45:56 -0400 Subject: [PATCH 46/62] fix: require python 3.7+ (#275) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * chore(python): drop python 3.6 Source-Link: https://github.com/googleapis/synthtool/commit/4f89b13af10d086458f9b379e56a614f9d6dab7b Post-Processor: gcr.io/cloud-devrel-public-resources/owlbot-python:latest@sha256:e7bb19d47c13839fe8c147e50e02e8b6cf5da8edd1af8b82208cd6f66cc2829c * add api_description to .repo-metadata.json * require python 3.7+ in setup.py * remove python 3.6 sample configs * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md Co-authored-by: Owl Bot Co-authored-by: Anthonios Partheniou --- cloud-tasks/snippets/noxfile.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cloud-tasks/snippets/noxfile.py b/cloud-tasks/snippets/noxfile.py index 3b3ffa5d2b0f..e9eb1cbfa5db 100644 --- a/cloud-tasks/snippets/noxfile.py +++ b/cloud-tasks/snippets/noxfile.py @@ -88,7 +88,7 @@ def get_pytest_env_vars() -> Dict[str, str]: # DO NOT EDIT - automatically generated. # All versions used to test samples. -ALL_VERSIONS = ["3.6", "3.7", "3.8", "3.9", "3.10"] +ALL_VERSIONS = ["3.7", "3.8", "3.9", "3.10"] # Any default versions that should be ignored. IGNORED_VERSIONS = TEST_CONFIG["ignored_versions"] From b6523f97ac9d6e69a73c050d35ec04891ea25a37 Mon Sep 17 00:00:00 2001 From: WhiteSource Renovate Date: Sat, 16 Jul 2022 17:20:46 +0200 Subject: [PATCH 47/62] chore(deps): update all dependencies (#267) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * chore(deps): update all dependencies * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * revert Co-authored-by: Owl Bot Co-authored-by: Anthonios Partheniou --- cloud-tasks/snippets/requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cloud-tasks/snippets/requirements.txt b/cloud-tasks/snippets/requirements.txt index 55dd827e125d..87fd43f70211 100644 --- a/cloud-tasks/snippets/requirements.txt +++ b/cloud-tasks/snippets/requirements.txt @@ -1 +1 @@ -google-cloud-tasks==2.9.0 +google-cloud-tasks==2.9.1 From 9a993ef2b61555273821583fedb5ccfb16b1b581 Mon Sep 17 00:00:00 2001 From: WhiteSource Renovate Date: Tue, 2 Aug 2022 16:20:12 +0200 Subject: [PATCH 48/62] chore(deps): update all dependencies (#281) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * chore(deps): update all dependencies * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * revert * revert Co-authored-by: Owl Bot Co-authored-by: Anthonios Partheniou --- cloud-tasks/snippets/requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cloud-tasks/snippets/requirements.txt b/cloud-tasks/snippets/requirements.txt index 87fd43f70211..12ac0bc0b268 100644 --- a/cloud-tasks/snippets/requirements.txt +++ b/cloud-tasks/snippets/requirements.txt @@ -1 +1 @@ -google-cloud-tasks==2.9.1 +google-cloud-tasks==2.10.0 From 4a3afe88ea18854b0b2817c0b1a8237f4f224a88 Mon Sep 17 00:00:00 2001 From: Averi Kitsch Date: Tue, 9 Aug 2022 04:12:17 -0700 Subject: [PATCH 49/62] docs(sample): update protobuf in create_http_task.py (#283) --- cloud-tasks/snippets/create_http_task.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/cloud-tasks/snippets/create_http_task.py b/cloud-tasks/snippets/create_http_task.py index 13057fa8c5ea..a789c4eeece7 100644 --- a/cloud-tasks/snippets/create_http_task.py +++ b/cloud-tasks/snippets/create_http_task.py @@ -90,7 +90,8 @@ def create_http_task( if deadline is not None: # Add dispatch deadline for requests sent to the worker. duration = duration_pb2.Duration() - task["dispatch_deadline"] = duration.FromSeconds(deadline) + duration.FromSeconds(deadline) + task["dispatch_deadline"] = duration # Use the client to build and send the task. response = client.create_task(request={"parent": parent, "task": task}) From 750ff9c3f3d29af07ed60e4e4acac8dceefb78f1 Mon Sep 17 00:00:00 2001 From: WhiteSource Renovate Date: Tue, 9 Aug 2022 17:29:01 +0200 Subject: [PATCH 50/62] chore(deps): update all dependencies (#286) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * chore(deps): update all dependencies * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * revert Co-authored-by: Owl Bot Co-authored-by: Anthonios Partheniou --- cloud-tasks/snippets/requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cloud-tasks/snippets/requirements.txt b/cloud-tasks/snippets/requirements.txt index 12ac0bc0b268..45118533ea25 100644 --- a/cloud-tasks/snippets/requirements.txt +++ b/cloud-tasks/snippets/requirements.txt @@ -1 +1 @@ -google-cloud-tasks==2.10.0 +google-cloud-tasks==2.10.1 From c8655e09cfdd1e974d441dd5eaf61472819496bd Mon Sep 17 00:00:00 2001 From: WhiteSource Renovate Date: Tue, 16 Aug 2022 16:40:42 +0200 Subject: [PATCH 51/62] chore(deps): update dependency google-cloud-tasks to v2.10.2 (#291) --- cloud-tasks/snippets/requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cloud-tasks/snippets/requirements.txt b/cloud-tasks/snippets/requirements.txt index 45118533ea25..c9757fa8bdf6 100644 --- a/cloud-tasks/snippets/requirements.txt +++ b/cloud-tasks/snippets/requirements.txt @@ -1 +1 @@ -google-cloud-tasks==2.10.1 +google-cloud-tasks==2.10.2 From 6529c49002d8393f7345bd410a89d0fd1991d76d Mon Sep 17 00:00:00 2001 From: WhiteSource Renovate Date: Tue, 6 Sep 2022 18:36:51 +0200 Subject: [PATCH 52/62] chore(deps): update dependency pytest to v7.1.3 (#299) * chore(deps): update all dependencies * revert Co-authored-by: Anthonios Partheniou --- cloud-tasks/snippets/requirements-test.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cloud-tasks/snippets/requirements-test.txt b/cloud-tasks/snippets/requirements-test.txt index d00689e0623a..e07168502ea9 100644 --- a/cloud-tasks/snippets/requirements-test.txt +++ b/cloud-tasks/snippets/requirements-test.txt @@ -1 +1 @@ -pytest==7.1.2 +pytest==7.1.3 From be9c48ee1c07100c339d8c5d7e4158b1ede3e993 Mon Sep 17 00:00:00 2001 From: "gcf-owl-bot[bot]" <78513119+gcf-owl-bot[bot]@users.noreply.github.com> Date: Tue, 13 Sep 2022 12:20:22 -0400 Subject: [PATCH 53/62] chore: detect samples tests in nested directories (#304) Source-Link: https://github.com/googleapis/synthtool/commit/50db768f450a50d7c1fd62513c113c9bb96fd434 Post-Processor: gcr.io/cloud-devrel-public-resources/owlbot-python:latest@sha256:e09366bdf0fd9c8976592988390b24d53583dd9f002d476934da43725adbb978 Co-authored-by: Owl Bot --- cloud-tasks/snippets/noxfile.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/cloud-tasks/snippets/noxfile.py b/cloud-tasks/snippets/noxfile.py index e9eb1cbfa5db..c1715136d645 100644 --- a/cloud-tasks/snippets/noxfile.py +++ b/cloud-tasks/snippets/noxfile.py @@ -207,8 +207,10 @@ def _session_tests( session: nox.sessions.Session, post_install: Callable = None ) -> None: # check for presence of tests - test_list = glob.glob("*_test.py") + glob.glob("test_*.py") - test_list.extend(glob.glob("tests")) + test_list = glob.glob("**/*_test.py", recursive=True) + glob.glob( + "**/test_*.py", recursive=True + ) + test_list.extend(glob.glob("**/tests", recursive=True)) if len(test_list) == 0: print("No tests found, skipping directory.") From 58066c943bbd5a806809fca8f43958162e7d68ac Mon Sep 17 00:00:00 2001 From: WhiteSource Renovate Date: Tue, 4 Oct 2022 03:30:59 +0200 Subject: [PATCH 54/62] chore(deps): update dependency google-cloud-tasks to v2.10.3 (#308) --- cloud-tasks/snippets/requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cloud-tasks/snippets/requirements.txt b/cloud-tasks/snippets/requirements.txt index c9757fa8bdf6..a120d6cc7d86 100644 --- a/cloud-tasks/snippets/requirements.txt +++ b/cloud-tasks/snippets/requirements.txt @@ -1 +1 @@ -google-cloud-tasks==2.10.2 +google-cloud-tasks==2.10.3 From d30253e1e0677d14421f54123783ebe027440295 Mon Sep 17 00:00:00 2001 From: WhiteSource Renovate Date: Tue, 18 Oct 2022 15:23:53 +0200 Subject: [PATCH 55/62] chore(deps): update dependency google-cloud-tasks to v2.10.4 (#311) --- cloud-tasks/snippets/requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cloud-tasks/snippets/requirements.txt b/cloud-tasks/snippets/requirements.txt index a120d6cc7d86..1bbf5163c064 100644 --- a/cloud-tasks/snippets/requirements.txt +++ b/cloud-tasks/snippets/requirements.txt @@ -1 +1 @@ -google-cloud-tasks==2.10.3 +google-cloud-tasks==2.10.4 From 6327b4cc12b033f4fcd773e8b18fe8f0134febf2 Mon Sep 17 00:00:00 2001 From: WhiteSource Renovate Date: Wed, 26 Oct 2022 12:56:35 +0200 Subject: [PATCH 56/62] chore(deps): update dependency pytest to v7.2.0 (#312) --- cloud-tasks/snippets/requirements-test.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cloud-tasks/snippets/requirements-test.txt b/cloud-tasks/snippets/requirements-test.txt index e07168502ea9..49780e035690 100644 --- a/cloud-tasks/snippets/requirements-test.txt +++ b/cloud-tasks/snippets/requirements-test.txt @@ -1 +1 @@ -pytest==7.1.3 +pytest==7.2.0 From f23a03d89f43fa21927e3826208ab479ade748e3 Mon Sep 17 00:00:00 2001 From: Sampath M Date: Wed, 9 Nov 2022 15:15:41 +0100 Subject: [PATCH 57/62] Update folder name to use underscore. --- cloud-tasks/snippets/noxfile.py | 312 ------------------ .../snippets/create_http_task.py | 0 .../snippets/create_http_task_test.py | 0 .../snippets/create_http_task_with_token.py | 0 .../create_http_task_with_token_test.py | 0 .../snippets/requirements-test.txt | 0 .../snippets/requirements.txt | 0 7 files changed, 312 deletions(-) delete mode 100644 cloud-tasks/snippets/noxfile.py rename {cloud-tasks => cloud_tasks}/snippets/create_http_task.py (100%) rename {cloud-tasks => cloud_tasks}/snippets/create_http_task_test.py (100%) rename {cloud-tasks => cloud_tasks}/snippets/create_http_task_with_token.py (100%) rename {cloud-tasks => cloud_tasks}/snippets/create_http_task_with_token_test.py (100%) rename {cloud-tasks => cloud_tasks}/snippets/requirements-test.txt (100%) rename {cloud-tasks => cloud_tasks}/snippets/requirements.txt (100%) diff --git a/cloud-tasks/snippets/noxfile.py b/cloud-tasks/snippets/noxfile.py deleted file mode 100644 index c1715136d645..000000000000 --- a/cloud-tasks/snippets/noxfile.py +++ /dev/null @@ -1,312 +0,0 @@ -# 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 glob -import os -from pathlib import Path -import sys -from typing import Callable, Dict, List, Optional - -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 - -BLACK_VERSION = "black==22.3.0" -ISORT_VERSION = "isort==5.10.1" - -# 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": [], - # Old samples are opted out of enforcing Python type hints - # All new samples should feature them - "enforce_type_hints": False, - # 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', - # If you need to use a specific version of pip, - # change pip_version_override to the string representation - # of the version number, for example, "20.2.4" - "pip_version_override": None, - # 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() -> Dict[str, str]: - """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 test samples. -ALL_VERSIONS = ["3.7", "3.8", "3.9", "3.10"] - -# 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 = os.environ.get("INSTALL_LIBRARY_FROM_SOURCE", False) in ( - "True", - "true", -) - -# Error if a python version is missing -nox.options.error_on_missing_interpreters = True - -# -# Style Checks -# - - -def _determine_local_import_names(start_dir: str) -> List[str]: - """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: nox.sessions.Session) -> None: - if not TEST_CONFIG["enforce_type_hints"]: - session.install("flake8", "flake8-import-order") - else: - session.install("flake8", "flake8-import-order", "flake8-annotations") - - local_names = _determine_local_import_names(".") - args = FLAKE8_COMMON_ARGS + [ - "--application-import-names", - ",".join(local_names), - ".", - ] - session.run("flake8", *args) - - -# -# Black -# - - -@nox.session -def blacken(session: nox.sessions.Session) -> None: - """Run black. Format code to uniform standard.""" - session.install(BLACK_VERSION) - python_files = [path for path in os.listdir(".") if path.endswith(".py")] - - session.run("black", *python_files) - - -# -# format = isort + black -# - - -@nox.session -def format(session: nox.sessions.Session) -> None: - """ - Run isort to sort imports. Then run black - to format code to uniform standard. - """ - session.install(BLACK_VERSION, ISORT_VERSION) - python_files = [path for path in os.listdir(".") if path.endswith(".py")] - - # Use the --fss option to sort imports using strict alphabetical order. - # See https://pycqa.github.io/isort/docs/configuration/options.html#force-sort-within-sections - session.run("isort", "--fss", *python_files) - session.run("black", *python_files) - - -# -# Sample Tests -# - - -PYTEST_COMMON_ARGS = ["--junitxml=sponge_log.xml"] - - -def _session_tests( - session: nox.sessions.Session, post_install: Callable = None -) -> None: - # check for presence of tests - test_list = glob.glob("**/*_test.py", recursive=True) + glob.glob( - "**/test_*.py", recursive=True - ) - test_list.extend(glob.glob("**/tests", recursive=True)) - - if len(test_list) == 0: - print("No tests found, skipping directory.") - return - - if TEST_CONFIG["pip_version_override"]: - pip_version = TEST_CONFIG["pip_version_override"] - session.install(f"pip=={pip_version}") - """Runs py.test for a particular project.""" - concurrent_args = [] - if os.path.exists("requirements.txt"): - if os.path.exists("constraints.txt"): - session.install("-r", "requirements.txt", "-c", "constraints.txt") - else: - session.install("-r", "requirements.txt") - with open("requirements.txt") as rfile: - packages = rfile.read() - - if os.path.exists("requirements-test.txt"): - if os.path.exists("constraints-test.txt"): - session.install("-r", "requirements-test.txt", "-c", "constraints-test.txt") - else: - session.install("-r", "requirements-test.txt") - with open("requirements-test.txt") as rtfile: - packages += rtfile.read() - - if INSTALL_LIBRARY_FROM_SOURCE: - session.install("-e", _get_repo_root()) - - if post_install: - post_install(session) - - if "pytest-parallel" in packages: - concurrent_args.extend(["--workers", "auto", "--tests-per-worker", "auto"]) - elif "pytest-xdist" in packages: - concurrent_args.extend(["-n", "auto"]) - - session.run( - "pytest", - *(PYTEST_COMMON_ARGS + session.posargs + concurrent_args), - # 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: nox.sessions.Session) -> None: - """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() -> Optional[str]: - """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) - # .git is not available in repos cloned via Cloud Build - # setup.py is always in the library's root, so use that instead - # https://github.com/googleapis/synthtool/issues/792 - if Path(p / "setup.py").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: nox.sessions.Session, path: str) -> None: - """(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/cloud-tasks/snippets/create_http_task.py b/cloud_tasks/snippets/create_http_task.py similarity index 100% rename from cloud-tasks/snippets/create_http_task.py rename to cloud_tasks/snippets/create_http_task.py diff --git a/cloud-tasks/snippets/create_http_task_test.py b/cloud_tasks/snippets/create_http_task_test.py similarity index 100% rename from cloud-tasks/snippets/create_http_task_test.py rename to cloud_tasks/snippets/create_http_task_test.py diff --git a/cloud-tasks/snippets/create_http_task_with_token.py b/cloud_tasks/snippets/create_http_task_with_token.py similarity index 100% rename from cloud-tasks/snippets/create_http_task_with_token.py rename to cloud_tasks/snippets/create_http_task_with_token.py diff --git a/cloud-tasks/snippets/create_http_task_with_token_test.py b/cloud_tasks/snippets/create_http_task_with_token_test.py similarity index 100% rename from cloud-tasks/snippets/create_http_task_with_token_test.py rename to cloud_tasks/snippets/create_http_task_with_token_test.py diff --git a/cloud-tasks/snippets/requirements-test.txt b/cloud_tasks/snippets/requirements-test.txt similarity index 100% rename from cloud-tasks/snippets/requirements-test.txt rename to cloud_tasks/snippets/requirements-test.txt diff --git a/cloud-tasks/snippets/requirements.txt b/cloud_tasks/snippets/requirements.txt similarity index 100% rename from cloud-tasks/snippets/requirements.txt rename to cloud_tasks/snippets/requirements.txt From d5ed303c18d8172a0a4dace2d90944b4bcaaf2e7 Mon Sep 17 00:00:00 2001 From: Sampath M Date: Wed, 9 Nov 2022 15:46:44 +0100 Subject: [PATCH 58/62] Update code owners for cloud_tasks --- .github/CODEOWNERS | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index 9e8dbe5e1e1a..6f6381533277 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -27,6 +27,7 @@ /cdn/**/* @mpwarres @GoogleCloudPlatform/python-samples-reviewers /cloudbuild/**/* @GoogleCloudPlatform/torus-dpe @GoogleCloudPlatform/python-samples-reviewers /cloud-sql/**/* @GoogleCloudPlatform/infra-db-dpes @GoogleCloudPlatform/python-samples-reviewers +/cloud_tasks/**/* @GoogleCloudPlatform/infra-db-dpes @GoogleCloudPlatform/python-samples-reviewers /codelabs/**/* @GoogleCloudPlatform/python-samples-reviewers /composer/**/* @leahecole @rachael-ds @rafalbiegacz @GoogleCloudPlatform/python-samples-reviewers /compute/**/* @m-strzelczyk @GoogleCloudPlatform/python-samples-reviewers From 21d39b4e4cdae7ac77770a77a66f15845a11bc14 Mon Sep 17 00:00:00 2001 From: Sampath M Date: Wed, 9 Nov 2022 15:57:06 +0100 Subject: [PATCH 59/62] Add shebang & update licence header! --- cloud_tasks/snippets/create_http_task.py | 6 ++++-- cloud_tasks/snippets/create_http_task_test.py | 6 ++++-- cloud_tasks/snippets/create_http_task_with_token.py | 6 ++++-- cloud_tasks/snippets/create_http_task_with_token_test.py | 6 ++++-- 4 files changed, 16 insertions(+), 8 deletions(-) diff --git a/cloud_tasks/snippets/create_http_task.py b/cloud_tasks/snippets/create_http_task.py index a789c4eeece7..fb035f62c508 100644 --- a/cloud_tasks/snippets/create_http_task.py +++ b/cloud_tasks/snippets/create_http_task.py @@ -1,10 +1,12 @@ -# Copyright 2019 Google LLC All Rights Reserved. +#!/usr/bin/env python +# +# Copyright 2022 Google, Inc. # # 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 +# 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, diff --git a/cloud_tasks/snippets/create_http_task_test.py b/cloud_tasks/snippets/create_http_task_test.py index a66f3287d1e1..ce86c988b608 100644 --- a/cloud_tasks/snippets/create_http_task_test.py +++ b/cloud_tasks/snippets/create_http_task_test.py @@ -1,10 +1,12 @@ -# Copyright 2019 Google LLC All Rights Reserved. +#!/usr/bin/env python +# +# Copyright 2022 Google, Inc. # # 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 +# 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, diff --git a/cloud_tasks/snippets/create_http_task_with_token.py b/cloud_tasks/snippets/create_http_task_with_token.py index 0e157eb9fa8d..eb98f758302b 100644 --- a/cloud_tasks/snippets/create_http_task_with_token.py +++ b/cloud_tasks/snippets/create_http_task_with_token.py @@ -1,10 +1,12 @@ -# Copyright 2019 Google LLC All Rights Reserved. +#!/usr/bin/env python +# +# Copyright 2022 Google, Inc. # # 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 +# 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, diff --git a/cloud_tasks/snippets/create_http_task_with_token_test.py b/cloud_tasks/snippets/create_http_task_with_token_test.py index b93c343740d5..39028881a83b 100644 --- a/cloud_tasks/snippets/create_http_task_with_token_test.py +++ b/cloud_tasks/snippets/create_http_task_with_token_test.py @@ -1,10 +1,12 @@ -# Copyright 2019 Google LLC All Rights Reserved. +#!/usr/bin/env python +# +# Copyright 2022 Google, Inc. # # 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 +# 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, From 94f2fe1308e413beca13681fd0476ea75bc833e2 Mon Sep 17 00:00:00 2001 From: Sampath M Date: Wed, 9 Nov 2022 16:29:55 +0100 Subject: [PATCH 60/62] Remove readme files - No longer required! --- tasks/README.md | 3 --- 1 file changed, 3 deletions(-) delete mode 100644 tasks/README.md diff --git a/tasks/README.md b/tasks/README.md deleted file mode 100644 index 045b12d8e5f0..000000000000 --- a/tasks/README.md +++ /dev/null @@ -1,3 +0,0 @@ -These samples have been moved. - -https://github.com/googleapis/python-tasks/tree/main/samples From 5603ae261404c1ebbfef76edf6fce9cc25626f6e Mon Sep 17 00:00:00 2001 From: Sampath M Date: Tue, 15 Nov 2022 16:59:35 +0100 Subject: [PATCH 61/62] Update blunderbuss.yml --- .github/blunderbuss.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/blunderbuss.yml b/.github/blunderbuss.yml index 5a26676163b6..e874ec2796e6 100644 --- a/.github/blunderbuss.yml +++ b/.github/blunderbuss.yml @@ -154,6 +154,7 @@ assign_prs_by: - GoogleCloudPlatform/api-iot - labels: - 'api: talent' + - 'api: cloudtasks' to: - GoogleCloudPlatform/python-samples-reviewers From 71dcebee4ef488e9898afe329a37933f272b7b05 Mon Sep 17 00:00:00 2001 From: Sampath M Date: Tue, 15 Nov 2022 17:14:48 +0100 Subject: [PATCH 62/62] Update blunderbuss.yml --- .github/blunderbuss.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/blunderbuss.yml b/.github/blunderbuss.yml index e874ec2796e6..a6e9620b0c3b 100644 --- a/.github/blunderbuss.yml +++ b/.github/blunderbuss.yml @@ -154,9 +154,12 @@ assign_prs_by: - GoogleCloudPlatform/api-iot - labels: - 'api: talent' - - 'api: cloudtasks' to: - GoogleCloudPlatform/python-samples-reviewers +- labels: + - 'api: cloudtasks' + to: + - GoogleCloudPlatform/infra-db-dpes assign_issues: - GoogleCloudPlatform/python-samples-owners