Skip to content

Commit ef90102

Browse files
chore(python): add nox session to sort python imports (#567)
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 4d054b0 commit ef90102

File tree

2 files changed

+26
-5
lines changed

2 files changed

+26
-5
lines changed

.github/.OwlBot.lock.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,5 @@
1313
# limitations under the License.
1414
docker:
1515
image: gcr.io/cloud-devrel-public-resources/owlbot-python:latest
16-
digest: sha256:8a5d3f6a2e43ed8293f34e06a2f56931d1e88a2694c3bb11b15df4eb256ad163
17-
# created: 2022-04-06T10:30:21.687684602Z
16+
digest: sha256:00c9d764fd1cd56265f12a5ef4b99a0c9e87cf261018099141e2ca5158890416
17+
# created: 2022-04-20T23:42:53.970438194Z

noxfile.py

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

2727
PYTYPE_VERSION = "pytype==2020.7.24"
2828
BLACK_VERSION = "black==22.3.0"
29-
BLACK_PATHS = ["docs", "google", "tests", "noxfile.py", "setup.py"]
29+
ISORT_VERSION = "isort==5.10.1"
30+
LINT_PATHS = ["docs", "google", "tests", "noxfile.py", "setup.py"]
3031

3132
DEFAULT_PYTHON_VERSION = "3.8"
3233

@@ -90,7 +91,7 @@ def lint(session):
9091
session.run(
9192
"black",
9293
"--check",
93-
*BLACK_PATHS,
94+
*LINT_PATHS,
9495
)
9596
session.run("flake8", "google", "tests")
9697

@@ -101,7 +102,27 @@ def blacken(session):
101102
session.install(BLACK_VERSION)
102103
session.run(
103104
"black",
104-
*BLACK_PATHS,
105+
*LINT_PATHS,
106+
)
107+
108+
109+
@nox.session(python=DEFAULT_PYTHON_VERSION)
110+
def format(session):
111+
"""
112+
Run isort to sort imports. Then run black
113+
to format code to uniform standard.
114+
"""
115+
session.install(BLACK_VERSION, ISORT_VERSION)
116+
# Use the --fss option to sort imports using strict alphabetical order.
117+
# See https://pycqa.github.io/isort/docs/configuration/options.html#force-sort-within-sections
118+
session.run(
119+
"isort",
120+
"--fss",
121+
*LINT_PATHS,
122+
)
123+
session.run(
124+
"black",
125+
*LINT_PATHS,
105126
)
106127

107128

0 commit comments

Comments
 (0)