@@ -18,18 +18,18 @@ No matter what, all samples must:
18
18
1 . Have a license header.
19
19
1 . Pass lint.
20
20
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
23
24
only supports 2.7. Our default version is currently Python 3.5.
24
25
1 . Have tests.
25
- 1 . Declare all dependencies in a ` requirements.txt ` . All requirements must
26
- be pinned.
27
26
28
27
## Style & linting
29
28
30
29
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:
33
33
34
34
1 . 4 spaces.
35
35
1 . ` CamelCase ` only for classes, ` snake_case ` elsewhere.
@@ -75,7 +75,7 @@ Beyond PEP8, there are several idioms and style nits we prefer.
75
75
```
76
76
77
77
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
79
79
destructuring assignment (`one, two = some_function()` ).
80
80
2 . Prefer not to do hanging indents if possible. If you break at the first
81
81
logical grouping, it shouldn' t be necessary. For example:
@@ -114,15 +114,15 @@ Beyond PEP8, there are several idioms and style nits we prefer.
114
114
115
115
In general our sample format follows ideas borrowed from
116
116
[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
119
119
and docstrings only as needed to further explain. Always introduce functions and
120
120
variables before they are used. Prefer less indirection. Prefer imperative
121
121
programming as it is easier to understand.
122
122
123
123
# ## Shebang
124
124
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
126
126
include a shebang as the first line. Separate the shebang from the rest of
127
127
the application with a blank line. The shebang should always be:
128
128
@@ -137,7 +137,7 @@ Don't include shebangs in web applications or test files.
137
137
All samples should start with the following (modulo shebang line):
138
138
139
139
```
140
- # Copyright 2019 Google, LLC.
140
+ # Copyright 2020 Google, LLC.
141
141
#
142
142
# Licensed under the Apache License, Version 2.0 (the "License");
143
143
# 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):
156
156
157
157
All samples should contain a module- level docstring. For command- line
158
158
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
160
160
available in readmes or documentation.
161
161
162
162
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.
206
206
Very few samples will require authoring classes. Prefer functions whenever
207
207
possible. See [ this video] ( https://www.youtube.com/watch?v=o9pEzgHorH0 ) for
208
208
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
210
210
prepared to justify its existence during code review.
211
211
212
- Always prefer descriptive function names even if they are long.
212
+ Always prefer descriptive function names, even if they are long.
213
213
For example ` upload_file ` , ` upload_encrypted_file ` , and ` list_resource_records ` .
214
214
Similarly, prefer long and descriptive parameter names. For example
215
215
` 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).
233
233
234
234
This particular function is intended to be the "top of the stack" - the function
235
235
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
237
237
functions in command-line applications should print, but use your best
238
238
judgment.
239
239
@@ -286,7 +286,7 @@ as having to resort to this kind of docstring might be extremely accurate but
286
286
it comes at the cost of high redundancy, signal-to-noise ratio, and increased
287
287
cognitive load.
288
288
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
290
290
parameters, for example:
291
291
292
292
```
@@ -301,7 +301,7 @@ of constraints, for example `A base64-encoded string` or `Must be between 0 and
301
301
302
302
### Request handlers
303
303
304
- In general these follow the same rules as top-level functions.
304
+ In general, these follow the same rules as top-level functions.
305
305
Here's a sample function from a web application:
306
306
307
307
``` python
@@ -403,24 +403,27 @@ if __name__ == '__main__':
403
403
## Writing tests
404
404
405
405
* 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.
409
409
* 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
411
411
should pass.
412
412
* 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.
414
414
* Samples that use App Engine Standard should use the App Engine testbed for
415
415
system testing. See existing App Engine tests for how to use this.
416
416
* 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.
418
419
419
420
## Running tests and automated tools
420
421
421
422
### Installing interpreters
422
423
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.
424
427
425
428
For example, to install with apt you'd use:
426
429
` apt-get install python2.7 python2.7-dev python3.6 python3.6-dev `
0 commit comments