Skip to content

Commit 276f10f

Browse files
chore(python): add nox session to sort python imports (#362)
Source-Link: googleapis/synthtool@1b71c10 Post-Processor: gcr.io/cloud-devrel-public-resources/owlbot-python:latest@sha256:00c9d764fd1cd56265f12a5ef4b99a0c9e87cf261018099141e2ca5158890416 Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
1 parent b74af26 commit 276f10f

File tree

1 file changed

+24
-3
lines changed

1 file changed

+24
-3
lines changed

packages/google-cloud-python-speech/noxfile.py

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@
2525
import nox
2626

2727
BLACK_VERSION = "black==22.3.0"
28-
BLACK_PATHS = ["docs", "google", "tests", "noxfile.py", "setup.py"]
28+
ISORT_VERSION = "isort==5.10.1"
29+
LINT_PATHS = ["docs", "google", "tests", "noxfile.py", "setup.py"]
2930

3031
DEFAULT_PYTHON_VERSION = "3.8"
3132

@@ -83,7 +84,7 @@ def lint(session):
8384
session.run(
8485
"black",
8586
"--check",
86-
*BLACK_PATHS,
87+
*LINT_PATHS,
8788
)
8889
session.run("flake8", "google", "tests")
8990

@@ -94,7 +95,27 @@ def blacken(session):
9495
session.install(BLACK_VERSION)
9596
session.run(
9697
"black",
97-
*BLACK_PATHS,
98+
*LINT_PATHS,
99+
)
100+
101+
102+
@nox.session(python=DEFAULT_PYTHON_VERSION)
103+
def format(session):
104+
"""
105+
Run isort to sort imports. Then run black
106+
to format code to uniform standard.
107+
"""
108+
session.install(BLACK_VERSION, ISORT_VERSION)
109+
# Use the --fss option to sort imports using strict alphabetical order.
110+
# See https://pycqa.github.io/isort/docs/configuration/options.html#force-sort-within-sections
111+
session.run(
112+
"isort",
113+
"--fss",
114+
*LINT_PATHS,
115+
)
116+
session.run(
117+
"black",
118+
*LINT_PATHS,
98119
)
99120

100121

0 commit comments

Comments
 (0)