Skip to content

Commit 7312370

Browse files
Minor polishing of authoring guide (GoogleCloudPlatform#2720)
Add 3.7 as a test requirement. Remove redundant requirement for requirements.txt. Small grammatical fixes. Update copyright year to 2020. Add a link to MAC_SETUP.md. Co-authored-by: Kurtis Van Gent <[email protected]>
1 parent 07603ac commit 7312370

File tree

1 file changed

+27
-24
lines changed

1 file changed

+27
-24
lines changed

AUTHORING_GUIDE.md

+27-24
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,18 @@ No matter what, all samples must:
1818
1. Have a license header.
1919
1. Pass lint.
2020
1. Be either a web application or a runnable console application.
21-
1. Have a `requirements.txt` containing all of its third-party dependencies.
22-
1. Work in Python 2.7, 3.5, & 3.6. App Engine Standard is exempt as it
21+
1. Have a `requirements.txt` containing all of its third-party dependencies. All
22+
requirements must be pinned.
23+
1. Work in Python 2.7, 3.5, 3.6, and 3.7. App Engine Standard is exempt as it
2324
only supports 2.7. Our default version is currently Python 3.5.
2425
1. Have tests.
25-
1. Declare all dependencies in a `requirements.txt`. All requirements must
26-
be pinned.
2726

2827
## Style & linting
2928

3029
We follow [pep8](https://www.python.org/dev/peps/pep-0008/) and the
31-
*external* [Google Python Style Guide](https://google.github.io/styleguide/pyguide.html)
32-
we verify this with [flake8](https://pypi.python.org/pypi/flake8). In general:
30+
*external* [Google Python Style
31+
Guide](https://google.github.io/styleguide/pyguide.html), which we verify with
32+
[flake8](https://pypi.python.org/pypi/flake8). In general:
3333

3434
1. 4 spaces.
3535
1. `CamelCase` only for classes, `snake_case` elsewhere.
@@ -75,7 +75,7 @@ Beyond PEP8, there are several idioms and style nits we prefer.
7575
```
7676

7777
This rule can be relaxed for counter or accumulation variables used in loops.
78-
1. Don't use parenthesis on multiple return values (`return one, two`) or in
78+
1. Don't use parentheses on multiple return values (`return one, two`) or in
7979
destructuring assignment (`one, two = some_function()`).
8080
2. Prefer not to do hanging indents if possible. If you break at the first
8181
logical grouping, it shouldn't be necessary. For example:
@@ -114,15 +114,15 @@ Beyond PEP8, there are several idioms and style nits we prefer.
114114

115115
In general our sample format follows ideas borrowed from
116116
[Literate Programming](https://en.wikipedia.org/wiki/Literate_programming).
117-
Notably, your sample program should self-contained, readable from top to bottom,
118-
and should be fairly self-documenting. Prefer descriptive names. Use comments
117+
Notably, your sample program should be self-contained, readable from top to bottom,
118+
and fairly self-documenting. Prefer descriptive names. Use comments
119119
and docstrings only as needed to further explain. Always introduce functions and
120120
variables before they are used. Prefer less indirection. Prefer imperative
121121
programming as it is easier to understand.
122122

123123
### Shebang
124124

125-
If, and only if, your sample application is a command-line application then
125+
If, and only if, your sample application is a command-line application, then
126126
include a shebang as the first line. Separate the shebang from the rest of
127127
the application with a blank line. The shebang should always be:
128128

@@ -137,7 +137,7 @@ Don't include shebangs in web applications or test files.
137137
All samples should start with the following (modulo shebang line):
138138

139139
```
140-
# Copyright 2019 Google, LLC.
140+
# Copyright 2020 Google, LLC.
141141
#
142142
# Licensed under the Apache License, Version 2.0 (the "License");
143143
# you may not use this file except in compliance with the License.
@@ -156,7 +156,7 @@ All samples should start with the following (modulo shebang line):
156156

157157
All samples should contain a module-level docstring. For command-line
158158
applications, this docstring will be used as the summary when `-h` is passed.
159-
The docstring should be succinct and should avoid repeating information
159+
The docstring should be succinct and avoid repeating information
160160
available in readmes or documentation.
161161

162162
Here's a simple docstring for a command-line application with straightforward
@@ -206,10 +206,10 @@ documentation at https://cloud.google.com/appengine/docs/flexible.
206206
Very few samples will require authoring classes. Prefer functions whenever
207207
possible. See [this video](https://www.youtube.com/watch?v=o9pEzgHorH0) for
208208
some insight into why classes aren't as necessary as you might think in Python.
209-
Classes also introduce cognitive load. If you do write a class in a sample be
209+
Classes also introduce cognitive load. If you do write a class in a sample, be
210210
prepared to justify its existence during code review.
211211

212-
Always prefer descriptive function names even if they are long.
212+
Always prefer descriptive function names, even if they are long.
213213
For example `upload_file`, `upload_encrypted_file`, and `list_resource_records`.
214214
Similarly, prefer long and descriptive parameter names. For example
215215
`source_file_name`, `dns_zone_name`, and `base64_encryption_key`.
@@ -233,7 +233,7 @@ implying a string instead of just `bucket` which could imply a class instance).
233233

234234
This particular function is intended to be the "top of the stack" - the function
235235
executed when the command-line sample is run by the user. As such, notice that
236-
it prints the blobs instead of returning. In general top of the stack
236+
it prints the blobs instead of returning. In general, top of the stack
237237
functions in command-line applications should print, but use your best
238238
judgment.
239239

@@ -286,7 +286,7 @@ as having to resort to this kind of docstring might be extremely accurate but
286286
it comes at the cost of high redundancy, signal-to-noise ratio, and increased
287287
cognitive load.
288288

289-
Finally, if absolutely necessary feel free to document the type for the
289+
Finally, if absolutely necessary, feel free to document the type for the
290290
parameters, for example:
291291

292292
```
@@ -301,7 +301,7 @@ of constraints, for example `A base64-encoded string` or `Must be between 0 and
301301

302302
### Request handlers
303303

304-
In general these follow the same rules as top-level functions.
304+
In general, these follow the same rules as top-level functions.
305305
Here's a sample function from a web application:
306306

307307
```python
@@ -403,24 +403,27 @@ if __name__ == '__main__':
403403
## Writing tests
404404

405405
* Use [pytest](https://docs.pytest.org/en/latest/)-style tests and plain
406-
asserts. Don't use `unittest`-style tests or `assertX` mthods.
407-
* All tests in this repository are **system tests**. This means they hit real
408-
services and should use little to no mocking.
406+
asserts. Don't use `unittest`-style tests or `assertX` methods.
407+
* All tests in this repository are **system tests**. This means that they hit
408+
real services and should use little to no mocking.
409409
* Tests should avoid doing very strict assertions. The exact output format
410-
from an API call can change, but as long as sample still works assertions
410+
from an API call can change, but as long as samples still work, assertions
411411
should pass.
412412
* Tests will run against Python 2.7 and 3. The only exception is App Engine
413-
standard- these samples are only be tested against Python 2.7.
413+
standard- these samples are only tested against Python 2.7.
414414
* Samples that use App Engine Standard should use the App Engine testbed for
415415
system testing. See existing App Engine tests for how to use this.
416416
* All tests should be independent of one another and should create and tear
417-
down resources needed to execute. Using UUIDs to avoid resource collision is recommended.
417+
down the resources needed to execute. Using UUIDs to avoid resource
418+
collision is recommended.
418419

419420
## Running tests and automated tools
420421

421422
### Installing interpreters
422423

423-
You need python 2.7 and 3.6, and the dev packages for each.
424+
You need python 2.7, 3.5, 3.6, and 3.7 and the dev packages for each. See
425+
[MAC_SETUP.md](MAC_SETUP.md) for details on setting up your environment on
426+
a Mac.
424427

425428
For example, to install with apt you'd use:
426429
`apt-get install python2.7 python2.7-dev python3.6 python3.6-dev`

0 commit comments

Comments
 (0)