Skip to content

Commit 814c401

Browse files
chore(python): add nox session to sort python imports (#218)
* 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 * revert change to region tag Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com> Co-authored-by: Anthonios Partheniou <[email protected]>
1 parent e259d72 commit 814c401

6 files changed

+24
-9
lines changed

privateca/snippets/conftest.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
import uuid
1616

1717
import google.auth
18-
1918
import pytest
2019

2120
from create_ca_pool import create_ca_pool

privateca/snippets/noxfile.py

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,14 @@
2222

2323
import nox
2424

25-
2625
# WARNING - WARNING - WARNING - WARNING - WARNING
2726
# WARNING - WARNING - WARNING - WARNING - WARNING
2827
# DO NOT EDIT THIS FILE EVER!
2928
# WARNING - WARNING - WARNING - WARNING - WARNING
3029
# WARNING - WARNING - WARNING - WARNING - WARNING
3130

3231
BLACK_VERSION = "black==22.3.0"
32+
ISORT_VERSION = "isort==5.10.1"
3333

3434
# Copy `noxfile_config.py` to your directory and modify it instead.
3535

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

169169
@nox.session
170170
def blacken(session: nox.sessions.Session) -> None:
171+
"""Run black. Format code to uniform standard."""
171172
session.install(BLACK_VERSION)
172173
python_files = [path for path in os.listdir(".") if path.endswith(".py")]
173174

174175
session.run("black", *python_files)
175176

176177

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

privateca/snippets/revoke_certificate.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
import sys
1818

19+
# isort: split
1920
# [START privateca_revoke_certificate]
2021

2122
import google.cloud.security.privateca_v1 as privateca_v1

privateca/snippets/test_certificate_authorities.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
from undelete_certificate_authority import undelete_certificate_authority
2929
from update_certificate_authority import update_ca_label
3030

31-
3231
PROJECT = google.auth.default()[1]
3332
LOCATION = "europe-west1"
3433
COMMON_NAME = "COMMON_NAME"

privateca/snippets/test_certificates.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,7 @@
2020

2121
from cryptography.hazmat.backends.openssl.backend import backend
2222
from cryptography.hazmat.primitives.asymmetric import rsa
23-
24-
from cryptography.hazmat.primitives.serialization import Encoding
25-
from cryptography.hazmat.primitives.serialization import PublicFormat
26-
23+
from cryptography.hazmat.primitives.serialization import Encoding, PublicFormat
2724
import google.auth
2825

2926
from create_certificate import create_certificate
@@ -32,7 +29,6 @@
3229
from filter_certificates import filter_certificates
3330
from revoke_certificate import revoke_certificate
3431

35-
3632
PROJECT = google.auth.default()[1]
3733
LOCATION = "europe-west1"
3834
COMMON_NAME = "COMMON_NAME"

privateca/snippets/test_crud_certificate_templates.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
from list_certificate_templates import list_certificate_templates
2424
from update_certificate_template import update_certificate_template
2525

26-
2726
PROJECT = google.auth.default()[1]
2827
LOCATION = "europe-west1"
2928
COMMON_NAME = "COMMON_NAME"

0 commit comments

Comments
 (0)