Skip to content

Commit

Permalink
chore(python): add nox session to sort python imports (#324)
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
2 people authored and telpirion committed Mar 13, 2023
1 parent 9d631d5 commit ba08782
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 7 deletions.
23 changes: 22 additions & 1 deletion securitycenter/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
7 changes: 5 additions & 2 deletions securitycenter/snippets/snippets_findings.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,9 +150,10 @@ def list_source(organization_id):
def create_finding(source_name, finding_id):
"""Creates a new finding."""
# [START securitycenter_create_finding]
import datetime

from google.cloud import securitycenter
from google.cloud.securitycenter_v1 import Finding
import datetime

# Create a new client.
client = securitycenter.SecurityCenterClient()
Expand Down Expand Up @@ -414,8 +415,9 @@ def list_filtered_findings(source_name):

def list_findings_at_time(source_name):
# [START securitycenter_list_findings_at_time]
from datetime import datetime, timedelta

from google.cloud import securitycenter
from datetime import timedelta, datetime

# Create a new client.
client = securitycenter.SecurityCenterClient()
Expand Down Expand Up @@ -524,6 +526,7 @@ def group_findings_at_time(source_name):
i = -1
# [START securitycenter_group_findings_at_time]
from datetime import datetime, timedelta

from google.cloud import securitycenter

# Create a client.
Expand Down
4 changes: 0 additions & 4 deletions securitycenter/snippets/snippets_mute_config_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,14 @@
import uuid

from _pytest.capture import CaptureFixture

from google.cloud import securitycenter
from google.cloud.securitycenter_v1.services.security_center.pagers import (
ListFindingsPager,
)

import pytest

import snippets_mute_config


# TODO(developer): Replace these variables before running the sample.
PROJECT_ID = os.environ["GOOGLE_CLOUD_PROJECT"]
ORGANIZATION_ID = os.environ["GCLOUD_ORGANIZATION"]
Expand All @@ -55,7 +52,6 @@ def mute_rule():
@pytest.fixture
def finding(capsys: CaptureFixture):
import snippets_findings

from snippets_findings import create_finding

snippets_findings.create_source(ORGANIZATION_ID)
Expand Down

0 comments on commit ba08782

Please sign in to comment.