Skip to content

Commit ccba8af

Browse files
iennaeglasnt
andauthored
fix: minor improvements to python contributing guidelines (#13545)
* fix: minor improvements to python contributing guidelines * fix: eliminate duplicate snippetbot warnings * ci(snippet-bot): ignore AUTHORING_GUIDE.md (it contains example region tags) * minor: correct format of ignoreFiles --------- Co-authored-by: Katie McLaughlin <[email protected]>
1 parent c71ebf5 commit ccba8af

File tree

2 files changed

+35
-27
lines changed

2 files changed

+35
-27
lines changed

.github/snippet-bot.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
aggregateChecks: true
22
alwaysCreateStatusCheck: true
33
ignoreFiles:
4-
- README.md
4+
- "README.md"
5+
- "AUTHORING_GUIDE.md"

AUTHORING_GUIDE.md

Lines changed: 33 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,6 @@ Guidelines](#testing-guidelines) are covered separately below.
8282

8383
### Folder Location
8484

85-
Samples that primarily show the use of one client library should be placed in
86-
the client library repository `googleapis/python-{api}`. Other samples should be
87-
placed in this repository `python-docs-samples`.
88-
8985
**Library repositories:** Each sample should be in a folder under the top-level
9086
samples folder `samples` in the client library repository. See the
9187
[Text-to-Speech
@@ -108,12 +104,6 @@ folder, and App Engine Flex samples are under the
108104
[appengine/flexible](https://github.com/GoogleCloudPlatform/python-docs-samples/tree/main/appengine/flexible)
109105
folder.
110106

111-
If your sample is a set of discrete code snippets that each demonstrate a single
112-
operation, these should be grouped into a `snippets` folder. For example, see
113-
the snippets in the
114-
[bigtable/snippets/writes](https://github.com/googleapis/python-bigtable/tree/main/samples/snippets/writes)
115-
folder.
116-
117107
If your sample is a quickstart — intended to demonstrate how to quickly get
118108
started with using a service or API — it should be in a _quickstart_ folder.
119109

@@ -274,11 +264,12 @@ task_from_dict = {
274264

275265
### Functions and Classes
276266

277-
Very few samples will require authoring classes. Prefer functions whenever
278-
possible. See [this video](https://www.youtube.com/watch?v=o9pEzgHorH0) for some
279-
insight into why classes aren't as necessary as you might think in Python.
280-
Classes also introduce cognitive load. If you do write a class in a sample, be
281-
prepared to justify its existence during code review.
267+
Prefer functions over classes whenever possible.
268+
269+
See [this video](https://www.youtube.com/watch?v=o9pEzgHorH0) for some
270+
hints into practical refactoring examples where simpler functions lead to more
271+
readable and maintainable code.
272+
282273

283274
#### Descriptive function names
284275

@@ -456,17 +447,33 @@ git+https://github.com/googleapis/python-firestore.git@ee518b741eb5d7167393c23ba
456447

457448
### Region Tags
458449

459-
Sample code may be integrated into Google Cloud Documentation through the use of
460-
region tags, which are comments added to the source code to identify code blocks
461-
that correspond to specific topics covered in the documentation. For example,
462-
see [this
463-
sample](https://github.com/GoogleCloudPlatform/python-docs-samples/blob/main/cloud-sql/mysql/sqlalchemy/main.py)
464-
— the region tags are the comments that begin with `[START` or `[END`.
465-
466-
The use of region tags is beyond the scope of this document, but if you’re using
467-
region tags they should start after the source code header (license/copyright
468-
information), but before imports and global configuration such as initializing
469-
constants.
450+
Region tags are comments added to the source code that begin with
451+
`[START region_tag]` and end with `[END region_tag]`. They enclose
452+
the core sample logic that can be easily copied into a REPL and run.
453+
454+
This allows us to integrate this copy-paste callable code into
455+
documentation directly. Region tags should be placed after the
456+
license header but before imports that are crucial to the
457+
sample running.
458+
459+
Example:
460+
```python
461+
# This import is not included within the region tag as
462+
# it is used to make the sample command-line runnable
463+
import sys
464+
465+
# [START example_storage_control_create_folder]
466+
# This import is included within the region tag
467+
# as it is critical to understanding the sample
468+
from google.cloud import storage_control_v2
469+
470+
471+
def create_folder(bucket_name: str, folder_name: str) -> None:
472+
print(f"Created folder: {response.name}")
473+
474+
475+
# [END example_storage_control_create_folder]
476+
```
470477

471478
### Exception Handling
472479

0 commit comments

Comments
 (0)