diff --git a/cloud-tasks/snippets/create_http_task.py b/cloud-tasks/snippets/create_http_task.py index 7bf75d41d738..13057fa8c5ea 100644 --- a/cloud-tasks/snippets/create_http_task.py +++ b/cloud-tasks/snippets/create_http_task.py @@ -30,11 +30,12 @@ def create_http_task( # [START cloud_tasks_create_http_task] """Create a task for a given queue with an arbitrary payload.""" - from google.cloud import tasks_v2 - from google.protobuf import timestamp_pb2, duration_pb2 import datetime import json + from google.cloud import tasks_v2 + from google.protobuf import duration_pb2, timestamp_pb2 + # Create a client. client = tasks_v2.CloudTasksClient() diff --git a/cloud-tasks/snippets/noxfile.py b/cloud-tasks/snippets/noxfile.py index 25f87a215d4c..3b3ffa5d2b0f 100644 --- a/cloud-tasks/snippets/noxfile.py +++ b/cloud-tasks/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 #