Skip to content

Commit 9342564

Browse files
chore(python): add nox session to sort python imports (#195)
* chore(python): add nox session to sort python imports Source-Link: googleapis/synthtool@1b71c10 Post-Processor: gcr.io/cloud-devrel-public-resources/owlbot-python:latest@sha256:00c9d764fd1cd56265f12a5ef4b99a0c9e87cf261018099141e2ca5158890416 * ci: update replacement in owlbot.py * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com> Co-authored-by: Anthonios Partheniou <[email protected]>
1 parent 5d7dd15 commit 9342564

File tree

3 files changed

+30
-12
lines changed

3 files changed

+30
-12
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: 25 additions & 4 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_auth_oauthlib", "tests", "noxfile.py", "setup.py"]
28+
ISORT_VERSION = "isort==5.10.1"
29+
LINT_PATHS = ["docs", "google_auth_oauthlib", "tests", "noxfile.py", "setup.py"]
2930

3031
DEFAULT_PYTHON_VERSION = "3.8"
3132

@@ -85,9 +86,9 @@ def lint(session):
8586
session.run(
8687
"black",
8788
"--check",
88-
*BLACK_PATHS,
89+
*LINT_PATHS,
8990
)
90-
session.run("flake8", *BLACK_PATHS)
91+
session.run("flake8", *LINT_PATHS)
9192

9293

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

102123

owlbot.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,15 @@
1818
# Change black paths
1919
s.replace(
2020
"noxfile.py",
21-
"""BLACK_PATHS =.*""",
22-
"""BLACK_PATHS = ["docs", "google_auth_oauthlib", "tests", "noxfile.py", "setup.py"]""",
21+
"""LINT_PATHS =.*""",
22+
"""LINT_PATHS = ["docs", "google_auth_oauthlib", "tests", "noxfile.py", "setup.py"]""",
2323
)
2424

2525
# Change flake8 paths
2626
s.replace(
2727
"noxfile.py",
2828
'session.run\("flake8", "google", "tests"\)',
29-
'session.run("flake8", *BLACK_PATHS)',
29+
'session.run("flake8", *LINT_PATHS)',
3030
)
3131

3232
s.replace(
@@ -35,7 +35,4 @@
3535
'"--cov=google_auth_oauthlib",',
3636
)
3737

38-
# Work around bug in templates https://github.com/googleapis/synthtool/pull/1335
39-
s.replace(".github/workflows/unittest.yml", "--fail-under=100", "--fail-under=99")
40-
4138
s.shell.run(["nox", "-s", "blacken"], hide_output=False)

0 commit comments

Comments
 (0)