|
| 1 | +# Code samples for the Compute Engine library |
| 2 | + |
| 3 | +In this folder you can find the source code for the code samples used throughout the |
| 4 | +[public documentation](https://cloud.google.com/compute/docs/) of Google Compute Engine. |
| 5 | + |
| 6 | +The samples can be found in the `snippets` folder, where they are organized to mimic the |
| 7 | +structure of the public documentation. Files that are saved there are generated by the `sgs.py` |
| 8 | +script from pieces found in `ingredients` and `recipes`. This way, one piece of code can be easily |
| 9 | +included in multiple snippets and updating the code requires less work. |
| 10 | + |
| 11 | +## Working with the SGS |
| 12 | + |
| 13 | +SGS (Snippet Generating System) works by scanning the `recipes` folder, finding all files |
| 14 | +and filling them with pieces of code found in `ingredients`. The folder structure of `recipes` is |
| 15 | +reconstructed in the `snippets` folder. |
| 16 | + |
| 17 | +### Adding new sample |
| 18 | + |
| 19 | +To create a new sample, just prepare a new file in one of the `recipes` subfolders. The SGS will pick it up |
| 20 | +automatically when you run it, by executing `python3 sgs.py generate` in this (`samples/`) directory. |
| 21 | + |
| 22 | +### Removing/moving a sample |
| 23 | + |
| 24 | +To remove or move a sample, you need to simply modify the `recipes` folder to match your desired structure, then delete |
| 25 | +the generated snippet from the `snippets` directory. The SGS script will create the snippet in the new location next |
| 26 | +time you run `python3 sgs.py generate`. |
| 27 | + |
| 28 | +### Interacting with GIT |
| 29 | + |
| 30 | +SGS will not interact with Git repository in any way. All changes made by the script need to be committed manually - |
| 31 | +preferably in the same commit as the update to the source files. |
| 32 | + |
| 33 | +## Preparing an ingredient |
| 34 | +To add a new ingredient, create a new `.py` file with the code you want to later use in the snippets. Mark the beginning |
| 35 | +of the code you want to include with `# <INGREDIENT name>` and the end with `# </INGREDIENT>`. |
| 36 | + |
| 37 | +Please leave the imports required by this ingredient **OUTSIDE** the area marked with ingredient comments. The SGS |
| 38 | +script will automatically collect all the required imports and put them in the final snippet in the right place and in |
| 39 | +right order. |
| 40 | + |
| 41 | +## Preparing a recipe |
| 42 | +Each recipe is a file located in the `recipes` folder. It should have the `.py` extension and should be a valid Python |
| 43 | +script. Each recipe has to have an `# <IMPORTS/>` line and at least one `# <INGREDIENT name/>` line. |
| 44 | +Apart from those restrictions, the contents of the file can be whatever you want. |
| 45 | + |
| 46 | +The SGS will copy the recipe file to the destination folder in `snippets` and replace the `# <IMPORTS/>` and |
| 47 | +`# <INGREDIENT name/>` lines with the `import` statements required by the used ingredients and with the ingredient |
| 48 | +body. |
| 49 | + |
| 50 | +### Regions |
| 51 | +You should use `# <REGION region_name>` and `# </REGION region_name>` lines to indicate where start and end |
| 52 | +of a region should be placed in the generated snippet. Those lines will be simply replaced with the proper |
| 53 | +`START region_name` and `END region_name` lines. |
0 commit comments