Skip to content

Commit 8f7674e

Browse files
authored
docs: update AUTHORING_GUIDE (#5872)
Update the Authoring Guide with more information from the internal doc, and added a FAQs section. Paired with cl/375155564.
1 parent 9e5cd39 commit 8f7674e

File tree

1 file changed

+98
-20
lines changed

1 file changed

+98
-20
lines changed

AUTHORING_GUIDE.md

+98-20
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,52 @@ interacting with Google Cloud libraries, APIs, or services.
1515
* **Idiomatic.** Each sample should follow widely accepted Python best
1616
practices as covered below.
1717

18+
19+
## FAQs
20+
21+
### Are there any canonical samples?
22+
23+
We recommend referencing the following samples and sample tests:
24+
25+
* [Storage client samples](https://github.com/GoogleCloudPlatform/python-docs-samples/tree/master/storage/cloud-client)
26+
27+
### Where should I put my samples?
28+
29+
See [Folder Location](#folder-location). Samples live in this repository, **python-docs-samples**,
30+
or in a library repository.
31+
32+
### Where are the client libraries?
33+
34+
Python libraries repositories live in https://github.com/googleapis/ in repositories named **python-API**.
35+
Each repository contains _one_ library. For example, https://github.com/googleapis/python-bigquery
36+
contains the `google-cloud-bigquery` library.
37+
38+
### Who reviews my PR?
39+
40+
This is a work in progress - in **python-docs-samples**, your PR will
41+
automatically be assigned to one of the owners in [@GoogleCloudPlatform/python-samples-owners](https://github.com/orgs/GoogleCloudPlatform/teams/python-samples-owners).
42+
You can assign a new person using the `blunderbuss:assign` label if your assignee is OOO or busy.
43+
You can (and probably should) also assign a teammate in addition to the auto-assigned
44+
owner to review your code for product-specific needs.
45+
46+
In **library repositories** with pre-existing samples GitHub will automatically assign a reviewer
47+
from python-samples-owners. If no reviewer is automatically assigned, contact [@googleapis/python-samples-owners](https://github.com/orgs/googleapis/teams/python-samples-owners).
48+
49+
Feel free to reach out to your assigned reviewer if it's been a few days and you haven't gotten a response!
50+
51+
### How do I set up my environment?
52+
53+
You should install the latest patch version of each minor version listed in [Python Versions](#python-versions).
54+
55+
We recommend using the Python version management tool [Pyenv](https://github.com/pyenv/pyenv) if you are using MacOS or Linux.
56+
57+
**Googlers:** See [the internal Python policies doc](https://g3doc.corp.google.com/company/teams/cloud-devrel/dpe/samples/python.md?cl=head).
58+
59+
**Using MacOS?:** See [Setting up a Mac development environment with pyenv and pyenv-virtualenv](MAC_SETUP.md).
60+
61+
Afterwards, see [Test Environment Setup](#test-environment-setup).
62+
63+
1864
## Sample Guidelines
1965

2066
This section covers guidelines for Python samples. Note that
@@ -23,7 +69,7 @@ This section covers guidelines for Python samples. Note that
2369
### Folder Location
2470

2571
Samples that primarily show the use of one client library should be placed in the
26-
client library repository. Other samples should be placed in this repository
72+
client library repository `googleapis/python-{api}`. Other samples should be placed in this repository
2773
`python-docs-samples`.
2874

2975
**Library repositories:** Each sample should be in the top-level samples folder `samples`
@@ -54,7 +100,7 @@ folder.
54100
If your sample is a quickstart — intended to demonstrate how to quickly get
55101
started with using a service or API — it should be in a _quickstart_ folder.
56102

57-
### Python Version
103+
### Python Versions
58104

59105
Samples should support Python 3.6, 3.7, and 3.8.
60106

@@ -227,7 +273,7 @@ def adder(a: int, b: int) -> int:
227273
return a+b
228274
```
229275

230-
Type hinting is enforced using [`flake8-annotations`](https://pypi.org/project/flake8-annotations/), which is enabled by setting the `enforce_type_hints` variable to `True` in the appropriate `noxfile_config.py`. Type hinting is expected in all new samples, and will gradually be added to all compatible existing samples.
276+
Type hinting is enforced using [`flake8-annotations`](https://pypi.org/project/flake8-annotations/), which is enabled by setting the `enforce_type_hints` variable to `True` in the appropriate `noxfile_config.py`. Type hinting is expected in all new samples, and will gradually be added to all compatible existing samples.
231277

232278
If there is an `Args` section within the function's docstring, consider
233279
documenting the argument types there as well. For example:
@@ -269,6 +315,24 @@ If a sample has testing requirements that differ from its runtime requirements
269315
testing libraries), the testing requirements may be listed in a separate
270316
`requirements-test.txt` file instead of the main `requirements.txt` file.
271317

318+
#### Developing samples for un-released changes
319+
320+
Pip has [VCS support](https://pip.pypa.io/en/stable/cli/pip_install/#vcs-support). Use the branch name or commit hash instead of the package name.
321+
322+
323+
**pip install**:
324+
```
325+
pip install git+https://github.com/googleapis/python-firestore.git@ee518b741eb5d7167393c23baa1e29ace861b253
326+
```
327+
328+
**requirements.txt**:
329+
```
330+
Flask==1.1.1
331+
PyMySQL==0.9.3
332+
git+https://github.com/googleapis/python-firestore.git@ee518b741eb5d7167393c23baa1e29ace861b253
333+
```
334+
335+
272336
### Region Tags
273337

274338
Sample code may be integrated into Google Cloud Documentation through the use
@@ -548,23 +612,9 @@ This repository supports two ways to run tests locally.
548612
549613
This is another way of running the tests. Setup is easier because
550614
you only need to instal Docker. The test execution will be bit
551-
slower than the first one.
615+
slower than the first one. This option is also useful if you need
616+
to simulate the CI system.
552617
553-
#### nox setup
554-
555-
Please read the [MAC Setup Guide](https://github.com/GoogleCloudPlatform/python-docs-samples/blob/master/MAC_SETUP.md).
556-
557-
#### `noxfile_config.py`
558-
559-
The [`noxfile_config.py`](noxfile_config.py) allows for customization
560-
of some options:
561-
562-
* Ignore specific Python versions.
563-
* Enforce type hints.
564-
* Specify a different Google Cloud Project.
565-
* Add additional environment variables. Also see [Environment Variables](#environment-variables).
566-
567-
Options are documented inside the [noxfile_config.py](noxfile_config.py).
568618
569619
### Running tests with nox
570620
@@ -573,6 +623,9 @@ Automated testing for samples is managed by
573623
including the flake8 linter, Python 2.7, Python 3.x, and App Engine tests,
574624
as well as automated README generation.
575625
626+
Sample tests are run through [pytest](https://pytest.org). Do not use
627+
[unittest](https://docs.python.org/3/library/unittest.html).
628+
576629
__Note:__
577630
578631
**Library repositories:** If you are working on an existing project, a `noxfile.py` will already exist.
@@ -617,6 +670,20 @@ To run a specific test from a specific following:
617670
nox -s py-3.7 -- snippets_test.py:test_list_blobs
618671
```
619672
673+
#### `noxfile_config.py`
674+
675+
The [`noxfile_config.py`](noxfile_config.py) allows for customization
676+
of some options:
677+
678+
* Ignore specific Python versions.
679+
* Enforce type hints.
680+
* Specify a different Google Cloud Project.
681+
* Add additional environment variables. Also see [Environment Variables](#environment-variables).
682+
* Override the version of `pip` used by nox
683+
684+
Options are documented inside the [noxfile_config.py](noxfile_config.py).
685+
686+
620687
### Running tests with Docker
621688
622689
__Note__: This is currently only available for samples in `python-docs-samples`.
@@ -705,11 +772,22 @@ samples, configure your GCS bucket name via the `CLOUD_STORAGE_BUCKET`
705772
environment variable.
706773
707774
The resources required by tests can usually be found in the `./resources`
708-
folder inside the `samples/snippets` directory in client libraries, as in
775+
folder inside the `samples/snippets` directory in client libraries, as in
709776
[this example](https://github.com/googleapis/python-automl/tree/master/samples/snippets/resources).
710777
You can upload those resources to your own GCS bucket to run the tests with
711778
[gsutil](https://cloud.google.com/storage/docs/gsutil). For example:
712779
713780
```console
714781
gsutil cp ./samples/snippets/resources/* gs://{$CLOUD_STORAGE_BUCKET}/
715782
```
783+
784+
## Debugging
785+
786+
### Can I use a debugger for samples?
787+
788+
Yes, you can use `pdb` or any Python debugger. For pdb, use `import pdb; pdb.set_trace()` (<3.7) or `breakpoint` (3.7+).
789+
See https://docs.python.org/3/library/pdb.html.
790+
791+
### How do I do that in IntelliJ, VSCode, etc.?
792+
793+
These IDEs just inject the breakpoint above into the code, so it should work.

0 commit comments

Comments
 (0)