Skip to content

Commit

Permalink
chore(python): add nox session to sort python imports (#218)
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

* revert change to region tag

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 e259d72 commit 814c401
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 9 deletions.
1 change: 0 additions & 1 deletion privateca/snippets/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import uuid

import google.auth

import pytest

from create_ca_pool import create_ca_pool
Expand Down
23 changes: 22 additions & 1 deletion privateca/snippets/noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@

import nox


# WARNING - WARNING - WARNING - WARNING - WARNING
# WARNING - WARNING - WARNING - WARNING - WARNING
# DO NOT EDIT THIS FILE EVER!
# WARNING - WARNING - WARNING - WARNING - WARNING
# WARNING - WARNING - WARNING - WARNING - WARNING

BLACK_VERSION = "black==22.3.0"
ISORT_VERSION = "isort==5.10.1"

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

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

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

session.run("black", *python_files)


#
# format = isort + black
#


@nox.session
def format(session: nox.sessions.Session) -> None:
"""
Run isort to sort imports. Then run black
to format code to uniform standard.
"""
session.install(BLACK_VERSION, ISORT_VERSION)
python_files = [path for path in os.listdir(".") if path.endswith(".py")]

# 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", *python_files)
session.run("black", *python_files)


#
# Sample Tests
#
Expand Down
1 change: 1 addition & 0 deletions privateca/snippets/revoke_certificate.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

import sys

# isort: split
# [START privateca_revoke_certificate]

import google.cloud.security.privateca_v1 as privateca_v1
Expand Down
1 change: 0 additions & 1 deletion privateca/snippets/test_certificate_authorities.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
from undelete_certificate_authority import undelete_certificate_authority
from update_certificate_authority import update_ca_label


PROJECT = google.auth.default()[1]
LOCATION = "europe-west1"
COMMON_NAME = "COMMON_NAME"
Expand Down
6 changes: 1 addition & 5 deletions privateca/snippets/test_certificates.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,7 @@

from cryptography.hazmat.backends.openssl.backend import backend
from cryptography.hazmat.primitives.asymmetric import rsa

from cryptography.hazmat.primitives.serialization import Encoding
from cryptography.hazmat.primitives.serialization import PublicFormat

from cryptography.hazmat.primitives.serialization import Encoding, PublicFormat
import google.auth

from create_certificate import create_certificate
Expand All @@ -32,7 +29,6 @@
from filter_certificates import filter_certificates
from revoke_certificate import revoke_certificate


PROJECT = google.auth.default()[1]
LOCATION = "europe-west1"
COMMON_NAME = "COMMON_NAME"
Expand Down
1 change: 0 additions & 1 deletion privateca/snippets/test_crud_certificate_templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
from list_certificate_templates import list_certificate_templates
from update_certificate_template import update_certificate_template


PROJECT = google.auth.default()[1]
LOCATION = "europe-west1"
COMMON_NAME = "COMMON_NAME"
Expand Down

0 comments on commit 814c401

Please sign in to comment.