Skip to content

Commit efbc18e

Browse files
chore(python): add nox session to sort python imports (#10)
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 58efdc1 commit efbc18e

File tree

2 files changed

+26
-5
lines changed

2 files changed

+26
-5
lines changed

packages/google-cloud-run/.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

packages/google-cloud-run/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)