From f6f8865b25b4352fb291d3e637591e18e172765d Mon Sep 17 00:00:00 2001 From: "gcf-owl-bot[bot]" <78513119+gcf-owl-bot[bot]@users.noreply.github.com> Date: Wed, 20 Apr 2022 20:54:04 -0400 Subject: [PATCH] chore(python): add nox session to sort python imports (#164) Source-Link: https://github.com/googleapis/synthtool/commit/1b71c10e20de7ed3f97f692f99a0e3399b67049f Post-Processor: gcr.io/cloud-devrel-public-resources/owlbot-python:latest@sha256:00c9d764fd1cd56265f12a5ef4b99a0c9e87cf261018099141e2ca5158890416 Co-authored-by: Owl Bot --- contact-center-insights/snippets/noxfile.py | 23 ++++++++++++++++++- .../snippets/test_create_analysis.py | 2 -- .../snippets/test_create_conversation.py | 2 -- .../test_create_conversation_with_ttl.py | 2 -- .../snippets/test_create_issue_model.py | 2 -- .../test_create_phrase_matcher_all_of.py | 2 -- .../test_create_phrase_matcher_any_of.py | 2 -- .../test_enable_pubsub_notifications.py | 5 +--- .../snippets/test_export_to_bigquery.py | 2 -- .../snippets/test_get_operation.py | 2 -- .../snippets/test_set_project_ttl.py | 2 -- 11 files changed, 23 insertions(+), 23 deletions(-) diff --git a/contact-center-insights/snippets/noxfile.py b/contact-center-insights/snippets/noxfile.py index 25f87a215d4c..3b3ffa5d2b0f 100644 --- a/contact-center-insights/snippets/noxfile.py +++ b/contact-center-insights/snippets/noxfile.py @@ -22,7 +22,6 @@ import nox - # WARNING - WARNING - WARNING - WARNING - WARNING # WARNING - WARNING - WARNING - WARNING - WARNING # DO NOT EDIT THIS FILE EVER! @@ -30,6 +29,7 @@ # 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. @@ -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 # diff --git a/contact-center-insights/snippets/test_create_analysis.py b/contact-center-insights/snippets/test_create_analysis.py index e78d925ee98d..0d660123dd2c 100644 --- a/contact-center-insights/snippets/test_create_analysis.py +++ b/contact-center-insights/snippets/test_create_analysis.py @@ -13,9 +13,7 @@ # limitations under the License. # import google.auth - from google.cloud import contact_center_insights_v1 - import pytest import create_analysis diff --git a/contact-center-insights/snippets/test_create_conversation.py b/contact-center-insights/snippets/test_create_conversation.py index 1553ff894bac..a3ca4c2c51b4 100644 --- a/contact-center-insights/snippets/test_create_conversation.py +++ b/contact-center-insights/snippets/test_create_conversation.py @@ -13,9 +13,7 @@ # limitations under the License. # import google.auth - from google.cloud import contact_center_insights_v1 - import pytest import create_conversation diff --git a/contact-center-insights/snippets/test_create_conversation_with_ttl.py b/contact-center-insights/snippets/test_create_conversation_with_ttl.py index ee493d4e3dc3..53ea32135728 100644 --- a/contact-center-insights/snippets/test_create_conversation_with_ttl.py +++ b/contact-center-insights/snippets/test_create_conversation_with_ttl.py @@ -13,9 +13,7 @@ # limitations under the License. # import google.auth - from google.cloud import contact_center_insights_v1 - import pytest import create_conversation_with_ttl diff --git a/contact-center-insights/snippets/test_create_issue_model.py b/contact-center-insights/snippets/test_create_issue_model.py index b978242cf5f7..2b5f128d635e 100644 --- a/contact-center-insights/snippets/test_create_issue_model.py +++ b/contact-center-insights/snippets/test_create_issue_model.py @@ -13,9 +13,7 @@ # limitations under the License. # import google.auth - from google.cloud import contact_center_insights_v1 - import pytest import create_issue_model diff --git a/contact-center-insights/snippets/test_create_phrase_matcher_all_of.py b/contact-center-insights/snippets/test_create_phrase_matcher_all_of.py index 888d959d42d2..6c9b217e67a1 100644 --- a/contact-center-insights/snippets/test_create_phrase_matcher_all_of.py +++ b/contact-center-insights/snippets/test_create_phrase_matcher_all_of.py @@ -13,9 +13,7 @@ # limitations under the License. # import google.auth - from google.cloud import contact_center_insights_v1 - import pytest import create_phrase_matcher_all_of diff --git a/contact-center-insights/snippets/test_create_phrase_matcher_any_of.py b/contact-center-insights/snippets/test_create_phrase_matcher_any_of.py index 0e0f199be5a8..62efcccfd7d4 100644 --- a/contact-center-insights/snippets/test_create_phrase_matcher_any_of.py +++ b/contact-center-insights/snippets/test_create_phrase_matcher_any_of.py @@ -13,9 +13,7 @@ # limitations under the License. # import google.auth - from google.cloud import contact_center_insights_v1 - import pytest import create_phrase_matcher_any_of diff --git a/contact-center-insights/snippets/test_enable_pubsub_notifications.py b/contact-center-insights/snippets/test_enable_pubsub_notifications.py index d7c0369616e1..d3ae6959dbe6 100644 --- a/contact-center-insights/snippets/test_enable_pubsub_notifications.py +++ b/contact-center-insights/snippets/test_enable_pubsub_notifications.py @@ -15,11 +15,8 @@ import uuid import google.auth - -from google.cloud import contact_center_insights_v1 -from google.cloud import pubsub_v1 +from google.cloud import contact_center_insights_v1, pubsub_v1 from google.protobuf import field_mask_pb2 - import pytest import enable_pubsub_notifications diff --git a/contact-center-insights/snippets/test_export_to_bigquery.py b/contact-center-insights/snippets/test_export_to_bigquery.py index 6f628605ce1d..c9ada15601ed 100644 --- a/contact-center-insights/snippets/test_export_to_bigquery.py +++ b/contact-center-insights/snippets/test_export_to_bigquery.py @@ -15,9 +15,7 @@ import uuid import google.auth - from google.cloud import bigquery - import pytest import export_to_bigquery diff --git a/contact-center-insights/snippets/test_get_operation.py b/contact-center-insights/snippets/test_get_operation.py index 4f6bc8b51eb4..087d6fa0ea2b 100644 --- a/contact-center-insights/snippets/test_get_operation.py +++ b/contact-center-insights/snippets/test_get_operation.py @@ -13,9 +13,7 @@ # limitations under the License. # import google.auth - from google.cloud import contact_center_insights_v1 - import pytest import get_operation diff --git a/contact-center-insights/snippets/test_set_project_ttl.py b/contact-center-insights/snippets/test_set_project_ttl.py index 34a657cc2972..6ddc3a024725 100644 --- a/contact-center-insights/snippets/test_set_project_ttl.py +++ b/contact-center-insights/snippets/test_set_project_ttl.py @@ -13,10 +13,8 @@ # limitations under the License. # import google.auth - from google.cloud import contact_center_insights_v1 from google.protobuf import field_mask_pb2 - import pytest import set_project_ttl