Skip to content

Commit f6f8865

Browse files
chore(python): add nox session to sort python imports (#164)
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>
1 parent dbf7750 commit f6f8865

11 files changed

+23
-23
lines changed

contact-center-insights/snippets/noxfile.py

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,14 @@
2222

2323
import nox
2424

25-
2625
# WARNING - WARNING - WARNING - WARNING - WARNING
2726
# WARNING - WARNING - WARNING - WARNING - WARNING
2827
# DO NOT EDIT THIS FILE EVER!
2928
# WARNING - WARNING - WARNING - WARNING - WARNING
3029
# WARNING - WARNING - WARNING - WARNING - WARNING
3130

3231
BLACK_VERSION = "black==22.3.0"
32+
ISORT_VERSION = "isort==5.10.1"
3333

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

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

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

174175
session.run("black", *python_files)
175176

176177

178+
#
179+
# format = isort + black
180+
#
181+
182+
183+
@nox.session
184+
def format(session: nox.sessions.Session) -> None:
185+
"""
186+
Run isort to sort imports. Then run black
187+
to format code to uniform standard.
188+
"""
189+
session.install(BLACK_VERSION, ISORT_VERSION)
190+
python_files = [path for path in os.listdir(".") if path.endswith(".py")]
191+
192+
# Use the --fss option to sort imports using strict alphabetical order.
193+
# See https://pycqa.github.io/isort/docs/configuration/options.html#force-sort-within-sections
194+
session.run("isort", "--fss", *python_files)
195+
session.run("black", *python_files)
196+
197+
177198
#
178199
# Sample Tests
179200
#

contact-center-insights/snippets/test_create_analysis.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,7 @@
1313
# limitations under the License.
1414
#
1515
import google.auth
16-
1716
from google.cloud import contact_center_insights_v1
18-
1917
import pytest
2018

2119
import create_analysis

contact-center-insights/snippets/test_create_conversation.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,7 @@
1313
# limitations under the License.
1414
#
1515
import google.auth
16-
1716
from google.cloud import contact_center_insights_v1
18-
1917
import pytest
2018

2119
import create_conversation

contact-center-insights/snippets/test_create_conversation_with_ttl.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,7 @@
1313
# limitations under the License.
1414
#
1515
import google.auth
16-
1716
from google.cloud import contact_center_insights_v1
18-
1917
import pytest
2018

2119
import create_conversation_with_ttl

contact-center-insights/snippets/test_create_issue_model.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,7 @@
1313
# limitations under the License.
1414
#
1515
import google.auth
16-
1716
from google.cloud import contact_center_insights_v1
18-
1917
import pytest
2018

2119
import create_issue_model

contact-center-insights/snippets/test_create_phrase_matcher_all_of.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,7 @@
1313
# limitations under the License.
1414
#
1515
import google.auth
16-
1716
from google.cloud import contact_center_insights_v1
18-
1917
import pytest
2018

2119
import create_phrase_matcher_all_of

contact-center-insights/snippets/test_create_phrase_matcher_any_of.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,7 @@
1313
# limitations under the License.
1414
#
1515
import google.auth
16-
1716
from google.cloud import contact_center_insights_v1
18-
1917
import pytest
2018

2119
import create_phrase_matcher_any_of

contact-center-insights/snippets/test_enable_pubsub_notifications.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,8 @@
1515
import uuid
1616

1717
import google.auth
18-
19-
from google.cloud import contact_center_insights_v1
20-
from google.cloud import pubsub_v1
18+
from google.cloud import contact_center_insights_v1, pubsub_v1
2119
from google.protobuf import field_mask_pb2
22-
2320
import pytest
2421

2522
import enable_pubsub_notifications

contact-center-insights/snippets/test_export_to_bigquery.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,7 @@
1515
import uuid
1616

1717
import google.auth
18-
1918
from google.cloud import bigquery
20-
2119
import pytest
2220

2321
import export_to_bigquery

contact-center-insights/snippets/test_get_operation.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,7 @@
1313
# limitations under the License.
1414
#
1515
import google.auth
16-
1716
from google.cloud import contact_center_insights_v1
18-
1917
import pytest
2018

2119
import get_operation

contact-center-insights/snippets/test_set_project_ttl.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,8 @@
1313
# limitations under the License.
1414
#
1515
import google.auth
16-
1716
from google.cloud import contact_center_insights_v1
1817
from google.protobuf import field_mask_pb2
19-
2018
import pytest
2119

2220
import set_project_ttl

0 commit comments

Comments
 (0)