-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(samples): Snippet Generating System (part 1) (#199)
* chore(samples): Snippet Generating System Preparing the SGS (Snippet Generating System) script to handle the burden of duplicated code in the samples. Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com> Co-authored-by: Anthonios Partheniou <[email protected]>
- Loading branch information
1 parent
3c1c56e
commit 7446464
Showing
14 changed files
with
598 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
# Code samples for the Compute Engine library | ||
|
||
In this folder you can find the source code for the code samples used throughout the | ||
[public documentation](https://cloud.google.com/compute/docs/) of Google Compute Engine. | ||
|
||
The samples can be found in the `snippets` folder, where they are organized to mimic the | ||
structure of the public documentation. Files that are saved there are generated by the `sgs.py` | ||
script from pieces found in `ingredients` and `recipes`. This way, one piece of code can be easily | ||
included in multiple snippets and updating the code requires less work. | ||
|
||
## Working with the SGS | ||
|
||
SGS (Snippet Generating System) works by scanning the `recipes` folder, finding all files | ||
and filling them with pieces of code found in `ingredients`. The folder structure of `recipes` is | ||
reconstructed in the `snippets` folder. | ||
|
||
### Adding new sample | ||
|
||
To create a new sample, just prepare a new file in one of the `recipes` subfolders. The SGS will pick it up | ||
automatically when you run it, by executing `python3 sgs.py generate` in this (`samples/`) directory. | ||
|
||
### Removing/moving a sample | ||
|
||
To remove or move a sample, you need to simply modify the `recipes` folder to match your desired structure, then delete | ||
the generated snippet from the `snippets` directory. The SGS script will create the snippet in the new location next | ||
time you run `python3 sgs.py generate`. | ||
|
||
### Interacting with GIT | ||
|
||
SGS will not interact with Git repository in any way. All changes made by the script need to be committed manually - | ||
preferably in the same commit as the update to the source files. | ||
|
||
## Preparing an ingredient | ||
To add a new ingredient, create a new `.py` file with the code you want to later use in the snippets. Mark the beginning | ||
of the code you want to include with `# <INGREDIENT name>` and the end with `# </INGREDIENT>`. | ||
|
||
Please leave the imports required by this ingredient **OUTSIDE** the area marked with ingredient comments. The SGS | ||
script will automatically collect all the required imports and put them in the final snippet in the right place and in | ||
right order. | ||
|
||
## Preparing a recipe | ||
Each recipe is a file located in the `recipes` folder. It should have the `.py` extension and should be a valid Python | ||
script. Each recipe has to have an `# <IMPORTS/>` line and at least one `# <INGREDIENT name/>` line. | ||
Apart from those restrictions, the contents of the file can be whatever you want. | ||
|
||
The SGS will copy the recipe file to the destination folder in `snippets` and replace the `# <IMPORTS/>` and | ||
`# <INGREDIENT name/>` lines with the `import` statements required by the used ingredients and with the ingredient | ||
body. | ||
|
||
### Regions | ||
You should use `# <REGION region_name>` and `# </REGION region_name>` lines to indicate where start and end | ||
of a region should be placed in the generated snippet. Those lines will be simply replaced with the proper | ||
`START region_name` and `END region_name` lines. |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# Copyright 2022 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. | ||
|
||
TEST_CONFIG_OVERRIDE = { | ||
# Tests in test_sample_default_values.py require separate projects to not interfere with each other. | ||
"gcloud_project_env": "BUILD_SPECIFIC_GCLOUD_PROJECT", | ||
} |
2 changes: 1 addition & 1 deletion
2
...te/samples/snippets/requirements-test.txt → ...oud-compute/samples/requirements-test.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
pytest==7.0.1 | ||
flaky==3.7.0 | ||
google-cloud-storage==2.1.0; python_version == '3.6' | ||
google-cloud-storage==2.1.0; python_version >= '3.7' | ||
google-cloud-storage==2.1.0; python_version >= '3.7' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
isort==5.10.1 | ||
black==22.1.0 | ||
google-cloud-compute==1.0.0 |
Oops, something went wrong.