Skip to content

Commit

Permalink
chore(python): add nox session to sort python imports (#195)
Browse files Browse the repository at this point in the history
* 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 <partheniou@google.com>
  • Loading branch information
3 people committed Apr 21, 2022
1 parent 5d7dd15 commit 9342564
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 12 deletions.
4 changes: 2 additions & 2 deletions .github/.OwlBot.lock.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@
# limitations under the License.
docker:
image: gcr.io/cloud-devrel-public-resources/owlbot-python:latest
digest: sha256:8a5d3f6a2e43ed8293f34e06a2f56931d1e88a2694c3bb11b15df4eb256ad163
# created: 2022-04-06T10:30:21.687684602Z
digest: sha256:00c9d764fd1cd56265f12a5ef4b99a0c9e87cf261018099141e2ca5158890416
# created: 2022-04-20T23:42:53.970438194Z
29 changes: 25 additions & 4 deletions noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
import nox

BLACK_VERSION = "black==22.3.0"
BLACK_PATHS = ["docs", "google_auth_oauthlib", "tests", "noxfile.py", "setup.py"]
ISORT_VERSION = "isort==5.10.1"
LINT_PATHS = ["docs", "google_auth_oauthlib", "tests", "noxfile.py", "setup.py"]

DEFAULT_PYTHON_VERSION = "3.8"

Expand Down Expand Up @@ -85,9 +86,9 @@ def lint(session):
session.run(
"black",
"--check",
*BLACK_PATHS,
*LINT_PATHS,
)
session.run("flake8", *BLACK_PATHS)
session.run("flake8", *LINT_PATHS)


@nox.session(python=DEFAULT_PYTHON_VERSION)
Expand All @@ -96,7 +97,27 @@ def blacken(session):
session.install(BLACK_VERSION)
session.run(
"black",
*BLACK_PATHS,
*LINT_PATHS,
)


@nox.session(python=DEFAULT_PYTHON_VERSION)
def format(session):
"""
Run isort to sort imports. Then run black
to format code to uniform standard.
"""
session.install(BLACK_VERSION, ISORT_VERSION)
# Use the --fss option to sort imports using strict alphabetical order.
# See https://pycqa.github.io/isort/docs/configuration/options.html#force-sort-within-sections
session.run(
"isort",
"--fss",
*LINT_PATHS,
)
session.run(
"black",
*LINT_PATHS,
)


Expand Down
9 changes: 3 additions & 6 deletions owlbot.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@
# Change black paths
s.replace(
"noxfile.py",
"""BLACK_PATHS =.*""",
"""BLACK_PATHS = ["docs", "google_auth_oauthlib", "tests", "noxfile.py", "setup.py"]""",
"""LINT_PATHS =.*""",
"""LINT_PATHS = ["docs", "google_auth_oauthlib", "tests", "noxfile.py", "setup.py"]""",
)

# Change flake8 paths
s.replace(
"noxfile.py",
'session.run\("flake8", "google", "tests"\)',
'session.run("flake8", *BLACK_PATHS)',
'session.run("flake8", *LINT_PATHS)',
)

s.replace(
Expand All @@ -35,7 +35,4 @@
'"--cov=google_auth_oauthlib",',
)

# Work around bug in templates https://github.com/googleapis/synthtool/pull/1335
s.replace(".github/workflows/unittest.yml", "--fail-under=100", "--fail-under=99")

s.shell.run(["nox", "-s", "blacken"], hide_output=False)

0 comments on commit 9342564

Please sign in to comment.