Skip to content

Commit 5614d1b

Browse files
author
Takashi Matsuo
authored
feat: add blacken nox session (#4378)
* feat: add blacken nox session fixes #4377 * add blacken session to existing noxfiles
1 parent 00ea19d commit 5614d1b

File tree

9 files changed

+112
-2
lines changed

9 files changed

+112
-2
lines changed

AUTHORING_GUIDE.md

+16-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ This section covers guidelines for Python samples. Note that
2222

2323
### Folder Location
2424

25-
Samples that primarily show the use of one client library should be placed in the
25+
Samples that primarily show the use of one client library should be placed in the
2626
client library repository. Other samples should be placed in this repository
2727
`python-docs-samples`.
2828

@@ -100,6 +100,20 @@ local variables” warnings.
100100
The use of [Black](https://pypi.org/project/black/) to standardize code
101101
formatting and simplify diffs is recommended, but optional.
102102

103+
The default noxfile has `blacken` session for convenience. Here are
104+
some examples.
105+
106+
If you have pyenv configured:
107+
```sh
108+
nox -s blacken
109+
```
110+
111+
If you only have docker:
112+
```
113+
cd proj_directory
114+
../scripts/run_tests_local.sh . blacken
115+
```
116+
103117
In addition to the syntax guidelines covered in PEP 8, samples should strive
104118
to follow the Pythonic philosophy outlined in the
105119
[PEP 20 - Zen of Python](https://www.python.org/dev/peps/pep-0020/) as well
@@ -485,7 +499,7 @@ Automated testing for samples is managed by
485499
including the flake8 linter, Python 2.7, Python 3.x, and App Engine tests,
486500
as well as automated README generation.
487501
488-
__Note:__
502+
__Note:__
489503
490504
**Library repositories:** If you are working on an existing project, a `noxfile.py` will already exist.
491505
For new samples, create a new `noxfile.py` and paste the contents of

appengine/flexible/memcache/noxfile.py

+12
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,18 @@ def lint(session):
8484
session.run("flake8", *args)
8585

8686

87+
#
88+
# Black
89+
#
90+
91+
@nox.session
92+
def blacken(session):
93+
session.install("black")
94+
python_files = [path for path in os.listdir(".") if path.endswith(".py")]
95+
96+
session.run("black", *python_files)
97+
98+
8799
#
88100
# Sample Tests
89101
#

dataflow/encryption-keys/noxfile.py

+12
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,18 @@ def lint(session):
8484
session.run("flake8", *args)
8585

8686

87+
#
88+
# Black
89+
#
90+
91+
@nox.session
92+
def blacken(session):
93+
session.install("black")
94+
python_files = [path for path in os.listdir(".") if path.endswith(".py")]
95+
96+
session.run("black", *python_files)
97+
98+
8799
#
88100
# Sample Tests
89101
#

dataflow/flex-templates/streaming_beam/noxfile.py

+12
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,18 @@ def lint(session):
8484
session.run("flake8", *args)
8585

8686

87+
#
88+
# Black
89+
#
90+
91+
@nox.session
92+
def blacken(session):
93+
session.install("black")
94+
python_files = [path for path in os.listdir(".") if path.endswith(".py")]
95+
96+
session.run("black", *python_files)
97+
98+
8799
#
88100
# Sample Tests
89101
#

ml_engine/online_prediction/noxfile.py

+12
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,18 @@ def lint(session):
8484
session.run("flake8", *args)
8585

8686

87+
#
88+
# Black
89+
#
90+
91+
@nox.session
92+
def blacken(session):
93+
session.install("black")
94+
python_files = [path for path in os.listdir(".") if path.endswith(".py")]
95+
96+
session.run("black", *python_files)
97+
98+
8799
#
88100
# Sample Tests
89101
#

noxfile-template.py

+12
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,18 @@ def lint(session):
144144
session.run("flake8", *args)
145145

146146

147+
#
148+
# Black
149+
#
150+
151+
@nox.session
152+
def blacken(session):
153+
session.install("black")
154+
python_files = [path for path in os.listdir(".") if path.endswith(".py")]
155+
156+
session.run("black", *python_files)
157+
158+
147159
#
148160
# Sample Tests
149161
#

pubsub/streaming-analytics/noxfile.py

+12
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,18 @@ def lint(session):
8484
session.run("flake8", *args)
8585

8686

87+
#
88+
# Black
89+
#
90+
91+
@nox.session
92+
def blacken(session):
93+
session.install("black")
94+
python_files = [path for path in os.listdir(".") if path.endswith(".py")]
95+
96+
session.run("black", *python_files)
97+
98+
8799
#
88100
# Sample Tests
89101
#

run/markdown-preview/editor/noxfile.py

+12
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,18 @@ def lint(session):
144144
session.run("flake8", *args)
145145

146146

147+
#
148+
# Black
149+
#
150+
151+
@nox.session
152+
def blacken(session):
153+
session.install("black")
154+
python_files = [path for path in os.listdir(".") if path.endswith(".py")]
155+
156+
session.run("black", *python_files)
157+
158+
147159
#
148160
# Sample Tests
149161
#

run/markdown-preview/renderer/noxfile.py

+12
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,18 @@ def lint(session):
144144
session.run("flake8", *args)
145145

146146

147+
#
148+
# Black
149+
#
150+
151+
@nox.session
152+
def blacken(session):
153+
session.install("black")
154+
python_files = [path for path in os.listdir(".") if path.endswith(".py")]
155+
156+
session.run("black", *python_files)
157+
158+
147159
#
148160
# Sample Tests
149161
#

0 commit comments

Comments
 (0)