Skip to content

Commit de2fa19

Browse files
chore(python): add nox session to sort python imports (#266)
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> Co-authored-by: Anthonios Partheniou <[email protected]>
1 parent bff198a commit de2fa19

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

compute/compute/noxfile.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
# WARNING - WARNING - WARNING - WARNING - WARNING
3131

3232
BLACK_VERSION = "black==22.3.0"
33+
ISORT_VERSION = "isort==5.10.1"
3334

3435
# Copy `noxfile_config.py` to your directory and modify it instead.
3536

@@ -168,12 +169,33 @@ def lint(session: nox.sessions.Session) -> None:
168169

169170
@nox.session
170171
def blacken(session: nox.sessions.Session) -> None:
172+
"""Run black. Format code to uniform standard."""
171173
session.install(BLACK_VERSION)
172174
python_files = [path for path in os.listdir(".") if path.endswith(".py")]
173175

174176
session.run("black", *python_files)
175177

176178

179+
#
180+
# format = isort + black
181+
#
182+
183+
184+
@nox.session
185+
def format(session: nox.sessions.Session) -> None:
186+
"""
187+
Run isort to sort imports. Then run black
188+
to format code to uniform standard.
189+
"""
190+
session.install(BLACK_VERSION, ISORT_VERSION)
191+
python_files = [path for path in os.listdir(".") if path.endswith(".py")]
192+
193+
# Use the --fss option to sort imports using strict alphabetical order.
194+
# See https://pycqa.github.io/isort/docs/configuration/options.html#force-sort-within-sections
195+
session.run("isort", "--fss", *python_files)
196+
session.run("black", *python_files)
197+
198+
177199
#
178200
# Sample Tests
179201
#

0 commit comments

Comments
 (0)