Skip to content

Commit 14cc012

Browse files
committed
chore: automatically format code using isort and black
1 parent 52af91c commit 14cc012

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

noxfile.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@
1616
import nox
1717
import shutil
1818

19+
BLACK_VERSION = "black==22.3.0"
20+
ISORT_VERSION = "isort==5.10.1"
21+
BLACK_PATHS = ["apiclient", "scripts", "tests", "describe.py", "owlbot.py", "noxfile.py", "setup.py"]
22+
1923
test_dependencies = [
2024
"django>=2.0.0",
2125
"google-auth",
@@ -44,6 +48,24 @@ def lint(session):
4448
"--statistics",
4549
)
4650

51+
@nox.session(python="3.8")
52+
def format(session):
53+
"""
54+
Run isort to sort imports. Then run black
55+
to format code to uniform standard.
56+
"""
57+
session.install(BLACK_VERSION, ISORT_VERSION)
58+
# Use the --fss option to sort imports using strict alphabetical order.
59+
# See https://pycqa.github.io/isort/docs/configuration/options.html#force-sort-within-sections
60+
session.run(
61+
"isort",
62+
"--fss",
63+
*BLACK_PATHS,
64+
)
65+
session.run(
66+
"black",
67+
*BLACK_PATHS,
68+
)
4769

4870
@nox.session(python=["3.6", "3.7", "3.8", "3.9", "3.10"])
4971
@nox.parametrize(

owlbot.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
import synthtool as s
1616
from synthtool import gcp
17-
17+
from pathlib import Path
1818
from synthtool.languages import python
1919

2020
common = gcp.CommonTemplates()
@@ -43,3 +43,7 @@
4343
# ----------------------------------------------------------------------------
4444

4545
python.py_samples(skip_readmes=True)
46+
47+
for noxfile in Path(".").glob("**/noxfile.py"):
48+
s.shell.run(["nox", "-s", "format"], cwd=noxfile.parent, hide_output=False)
49+

0 commit comments

Comments
 (0)