From 0bd46ef34f2010f0902f39b87489a64b443e2001 Mon Sep 17 00:00:00 2001 From: "gcf-owl-bot[bot]" <78513119+gcf-owl-bot[bot]@users.noreply.github.com> Date: Thu, 21 Apr 2022 20:41:59 -0400 Subject: [PATCH] chore(python): add nox session to sort python imports (#312) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * chore(python): add nox session to sort python imports Source-Link: https://github.com/googleapis/synthtool/commit/1b71c10e20de7ed3f97f692f99a0e3399b67049f Post-Processor: gcr.io/cloud-devrel-public-resources/owlbot-python:latest@sha256:00c9d764fd1cd56265f12a5ef4b99a0c9e87cf261018099141e2ca5158890416 * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * revert change to region tag Co-authored-by: Owl Bot Co-authored-by: Anthonios Partheniou --- .../samples/analyze/analyze_test.py | 1 - .../samples/analyze/beta_snippets_test.py | 1 - videointelligence/samples/analyze/noxfile.py | 23 ++++++++++++++++++- .../samples/analyze/video_detect_logo.py | 3 ++- videointelligence/samples/labels/noxfile.py | 23 ++++++++++++++++++- .../samples/quickstart/noxfile.py | 23 ++++++++++++++++++- .../samples/shotchange/noxfile.py | 23 ++++++++++++++++++- 7 files changed, 90 insertions(+), 7 deletions(-) diff --git a/videointelligence/samples/analyze/analyze_test.py b/videointelligence/samples/analyze/analyze_test.py index 34c1a4dcfa37..10bb97fa3c05 100644 --- a/videointelligence/samples/analyze/analyze_test.py +++ b/videointelligence/samples/analyze/analyze_test.py @@ -17,7 +17,6 @@ import time from google.api_core.exceptions import ServiceUnavailable - import pytest import analyze diff --git a/videointelligence/samples/analyze/beta_snippets_test.py b/videointelligence/samples/analyze/beta_snippets_test.py index 061b643a5393..f4d71d23e9b2 100644 --- a/videointelligence/samples/analyze/beta_snippets_test.py +++ b/videointelligence/samples/analyze/beta_snippets_test.py @@ -25,7 +25,6 @@ import beta_snippets - POSSIBLE_TEXTS = [ "Google", "SUR", diff --git a/videointelligence/samples/analyze/noxfile.py b/videointelligence/samples/analyze/noxfile.py index 25f87a215d4c..3b3ffa5d2b0f 100644 --- a/videointelligence/samples/analyze/noxfile.py +++ b/videointelligence/samples/analyze/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/videointelligence/samples/analyze/video_detect_logo.py b/videointelligence/samples/analyze/video_detect_logo.py index b781fda90b0e..b87c71d17158 100644 --- a/videointelligence/samples/analyze/video_detect_logo.py +++ b/videointelligence/samples/analyze/video_detect_logo.py @@ -12,9 +12,10 @@ # See the License for the specific language governing permissions and # limitations under the License. -import io +# isort: split # [START video_detect_logo] +import io from google.cloud import videointelligence diff --git a/videointelligence/samples/labels/noxfile.py b/videointelligence/samples/labels/noxfile.py index 25f87a215d4c..3b3ffa5d2b0f 100644 --- a/videointelligence/samples/labels/noxfile.py +++ b/videointelligence/samples/labels/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/videointelligence/samples/quickstart/noxfile.py b/videointelligence/samples/quickstart/noxfile.py index 25f87a215d4c..3b3ffa5d2b0f 100644 --- a/videointelligence/samples/quickstart/noxfile.py +++ b/videointelligence/samples/quickstart/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/videointelligence/samples/shotchange/noxfile.py b/videointelligence/samples/shotchange/noxfile.py index 25f87a215d4c..3b3ffa5d2b0f 100644 --- a/videointelligence/samples/shotchange/noxfile.py +++ b/videointelligence/samples/shotchange/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 #