From 596e1c778c66cd85f1fef5511a9c483c0b2a1eb1 Mon Sep 17 00:00:00 2001 From: Holt Skinner Date: Mon, 12 Jun 2023 14:13:35 -0500 Subject: [PATCH 1/8] chore: Add owlbot.py --- owlbot.py | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 owlbot.py diff --git a/owlbot.py b/owlbot.py new file mode 100644 index 00000000000..f2ec256a68e --- /dev/null +++ b/owlbot.py @@ -0,0 +1,34 @@ +# Copyright 2023 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. + +import synthtool as s +import synthtool.gcp as gcp + +templated_files = gcp.CommonTemplates().py_library() + +# Copy the standard noxfile from templated_files +s.move(templated_files / "noxfile.py") + +# Update BLACK_PATHS in order to run black on all files +s.replace( + "noxfile.py", + r"""BLACK_PATHS = \["docs", "google", "tests", "noxfile.py", "setup.py"\]""", + r"""BLACK_PATHS = ["."]""", +) + +# ---------------------------------------------------------------------------- +# Run blacken session +# ---------------------------------------------------------------------------- + +s.shell.run(["nox", "-s", "blacken"], hide_output=False) From b64337353a031ec9f79b0a40c69023af3f61f895 Mon Sep 17 00:00:00 2001 From: Holt Skinner Date: Mon, 12 Jun 2023 14:29:15 -0500 Subject: [PATCH 2/8] Add owlbot files - Owlbot.yaml - Owlbot.lock.yaml - repo-metadata.json --- .github/.OwlBot.lock.yaml | 17 +++++++++++++++++ .github/.OwlBot.yaml | 16 ++++++++++++++++ .repo-metadata.json | 7 +++++++ 3 files changed, 40 insertions(+) create mode 100644 .github/.OwlBot.lock.yaml create mode 100644 .github/.OwlBot.yaml create mode 100644 .repo-metadata.json diff --git a/.github/.OwlBot.lock.yaml b/.github/.OwlBot.lock.yaml new file mode 100644 index 00000000000..9b5c60df3b1 --- /dev/null +++ b/.github/.OwlBot.lock.yaml @@ -0,0 +1,17 @@ +# Copyright 2023 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. + +docker: + image: gcr.io/cloud-devrel-public-resources/owlbot-python:latest + digest: sha256:240b5bcc2bafd450912d2da2be15e62bc6de2cf839823ae4bf94d4f392b451dc diff --git a/.github/.OwlBot.yaml b/.github/.OwlBot.yaml new file mode 100644 index 00000000000..96ccf69a991 --- /dev/null +++ b/.github/.OwlBot.yaml @@ -0,0 +1,16 @@ +# Copyright 2023 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. + +docker: + image: gcr.io/cloud-devrel-public-resources/owlbot-python:latest diff --git a/.repo-metadata.json b/.repo-metadata.json new file mode 100644 index 00000000000..492bf5eb2bc --- /dev/null +++ b/.repo-metadata.json @@ -0,0 +1,7 @@ +{ + "name": "python-docs-samples", + "name_pretty": "Google Cloud Python Samples", + "issue_tracker": "https://github.com/GoogleCloudPlatform/python-docs-samples/issues", + "language": "python", + "repo": "GoogleCloudPlatform/python-docs-samples" +} From 6bacf1de2cb072381fbeba555b0a8c8105caec9d Mon Sep 17 00:00:00 2001 From: Holt Skinner Date: Tue, 13 Jun 2023 09:23:39 -0500 Subject: [PATCH 3/8] Fixed owlbot.py after local testing. --- .repo-metadata.json | 1 + AUTHORING_GUIDE.md | 8 ++++++-- owlbot.py | 4 ++-- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/.repo-metadata.json b/.repo-metadata.json index 492bf5eb2bc..285ae31b72a 100644 --- a/.repo-metadata.json +++ b/.repo-metadata.json @@ -1,4 +1,5 @@ { + "default_version": "v1", "name": "python-docs-samples", "name_pretty": "Google Cloud Python Samples", "issue_tracker": "https://github.com/GoogleCloudPlatform/python-docs-samples/issues", diff --git a/AUTHORING_GUIDE.md b/AUTHORING_GUIDE.md index b8711b6a654..d876b620136 100644 --- a/AUTHORING_GUIDE.md +++ b/AUTHORING_GUIDE.md @@ -151,22 +151,26 @@ outside the scope of PEP 8, such as the “too many arguments” or “too many local variables” warnings. The use of [Black](https://pypi.org/project/black/) to standardize code -formatting and simplify diffs is recommended, but optional. +formatting and simplify diffs is recommended. The default noxfile has `blacken` session for convenience. Here are some examples. If you have pyenv configured: + ```sh nox -s blacken ``` If you only have docker: -``` + +```sh cd proj_directory ../scripts/run_tests_local.sh . blacken ``` +Owlbot is an automated tool that will run the `blacken` session automatically on new pull requests. + In addition to the syntax guidelines covered in PEP 8, samples should strive to follow the Pythonic philosophy outlined in the [PEP 20 - Zen of Python](https://www.python.org/dev/peps/pep-0020/) as well diff --git a/owlbot.py b/owlbot.py index f2ec256a68e..6cd5bbad0d9 100644 --- a/owlbot.py +++ b/owlbot.py @@ -23,8 +23,8 @@ # Update BLACK_PATHS in order to run black on all files s.replace( "noxfile.py", - r"""BLACK_PATHS = \["docs", "google", "tests", "noxfile.py", "setup.py"\]""", - r"""BLACK_PATHS = ["."]""", + r"""LINT_PATHS = \["docs", "google", "tests", "noxfile.py", "setup.py"\]""", + r"""LINT_PATHS = ["."]""", ) # ---------------------------------------------------------------------------- From b2f5a7d0ab4c6990a150cfe612694d593457c594 Mon Sep 17 00:00:00 2001 From: Holt Skinner Date: Tue, 13 Jun 2023 09:37:19 -0500 Subject: [PATCH 4/8] Changed owlbot.py to run `format` instead of `blacken` (Also runs isort) --- owlbot.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/owlbot.py b/owlbot.py index 6cd5bbad0d9..fd381955dfe 100644 --- a/owlbot.py +++ b/owlbot.py @@ -31,4 +31,4 @@ # Run blacken session # ---------------------------------------------------------------------------- -s.shell.run(["nox", "-s", "blacken"], hide_output=False) +s.shell.run(["nox", "-s", "format"], hide_output=False) From 396e1c9ac37f48183489ea6dd5c0274be9193ec4 Mon Sep 17 00:00:00 2001 From: Holt Skinner Date: Tue, 13 Jun 2023 10:11:43 -0500 Subject: [PATCH 5/8] Update owlbot.py to add google profile to isort options - Temporary until https://github.com/googleapis/synthtool/pull/1811 is added to synthtool --- owlbot.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/owlbot.py b/owlbot.py index fd381955dfe..93c291391f5 100644 --- a/owlbot.py +++ b/owlbot.py @@ -27,6 +27,14 @@ r"""LINT_PATHS = ["."]""", ) +# TODO: Remove once https://github.com/googleapis/synthtool/pull/1811 is merged. +# Update isort configuration to use Google profile. +s.replace( + "noxfile.py", + r"""("isort",\n\s+"--fss",\n\s+\*LINT_PATHS,)""", + r""""isort",\n\t\t"--profile=google",\n\t\t"--fss",\n\t\t*LINT_PATHS,""", +) + # ---------------------------------------------------------------------------- # Run blacken session # ---------------------------------------------------------------------------- From 6273be65eba5d848b300ed4fb883d36307b1b169 Mon Sep 17 00:00:00 2001 From: Holt Skinner Date: Tue, 13 Jun 2023 11:25:24 -0500 Subject: [PATCH 6/8] Add isort override for "main" --- owlbot.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/owlbot.py b/owlbot.py index 93c291391f5..eea55e8666f 100644 --- a/owlbot.py +++ b/owlbot.py @@ -32,7 +32,7 @@ s.replace( "noxfile.py", r"""("isort",\n\s+"--fss",\n\s+\*LINT_PATHS,)""", - r""""isort",\n\t\t"--profile=google",\n\t\t"--fss",\n\t\t*LINT_PATHS,""", + r""""isort",\n\t\t"--profile=google",\n\t\t"--fss",\n\t\t"--known-local-folder=main",\n\t\t*LINT_PATHS,""", ) # ---------------------------------------------------------------------------- From f161c437b6420fed40246cd55f382700c6d9f60d Mon Sep 17 00:00:00 2001 From: Holt Skinner Date: Tue, 13 Jun 2023 14:03:44 -0500 Subject: [PATCH 7/8] revert owlbot back to blacken --- owlbot.py | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/owlbot.py b/owlbot.py index eea55e8666f..6cd5bbad0d9 100644 --- a/owlbot.py +++ b/owlbot.py @@ -27,16 +27,8 @@ r"""LINT_PATHS = ["."]""", ) -# TODO: Remove once https://github.com/googleapis/synthtool/pull/1811 is merged. -# Update isort configuration to use Google profile. -s.replace( - "noxfile.py", - r"""("isort",\n\s+"--fss",\n\s+\*LINT_PATHS,)""", - r""""isort",\n\t\t"--profile=google",\n\t\t"--fss",\n\t\t"--known-local-folder=main",\n\t\t*LINT_PATHS,""", -) - # ---------------------------------------------------------------------------- # Run blacken session # ---------------------------------------------------------------------------- -s.shell.run(["nox", "-s", "format"], hide_output=False) +s.shell.run(["nox", "-s", "blacken"], hide_output=False) From 9fdf9062dc08b02448ef46929239cd0a53cc3694 Mon Sep 17 00:00:00 2001 From: Holt Skinner Date: Tue, 13 Jun 2023 14:24:49 -0500 Subject: [PATCH 8/8] Add update to black and isort versions --- owlbot.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/owlbot.py b/owlbot.py index 6cd5bbad0d9..b1eb507fa26 100644 --- a/owlbot.py +++ b/owlbot.py @@ -27,6 +27,13 @@ r"""LINT_PATHS = ["."]""", ) +# TODO: Remove once https://github.com/googleapis/synthtool/pull/1811 is merged. +s.replace( + "noxfile.py", + r"""BLACK_VERSION = "black==22.3.0"\nISORT_VERSION = "isort==5.10.1""", + r"""BLACK_VERSION = "black[jupyter]==23.3.0"\nISORT_VERSION = "isort==5.11.0""", +) + # ---------------------------------------------------------------------------- # Run blacken session # ----------------------------------------------------------------------------