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..285ae31b72a --- /dev/null +++ b/.repo-metadata.json @@ -0,0 +1,8 @@ +{ + "default_version": "v1", + "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" +} 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 new file mode 100644 index 00000000000..b1eb507fa26 --- /dev/null +++ b/owlbot.py @@ -0,0 +1,41 @@ +# 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"""LINT_PATHS = \["docs", "google", "tests", "noxfile.py", "setup.py"\]""", + 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 +# ---------------------------------------------------------------------------- + +s.shell.run(["nox", "-s", "blacken"], hide_output=False)