Skip to content

Commit d3c2753

Browse files
committed
chore(nox): standardize format session to use Ruff across multiple packages
1 parent 064df21 commit d3c2753

File tree

12 files changed

+254
-57
lines changed

12 files changed

+254
-57
lines changed

packages/bigquery-magics/noxfile.py

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929

3030
FLAKE8_VERSION = "flake8==6.1.0"
3131
BLACK_VERSION = "black[jupyter]==23.7.0"
32+
RUFF_VERSION = "ruff==0.14.14"
3233
ISORT_VERSION = "isort==5.11.0"
3334
LINT_PATHS = ["docs", "bigquery_magics", "tests", "noxfile.py", "setup.py"]
3435

@@ -170,19 +171,26 @@ def blacken(session):
170171
@nox.session(python=DEFAULT_PYTHON_VERSION)
171172
def format(session):
172173
"""
173-
Run isort to sort imports. Then run black
174-
to format code to uniform standard.
174+
Run ruff to sort imports and format code.
175175
"""
176-
session.install(BLACK_VERSION, ISORT_VERSION)
177-
# Use the --fss option to sort imports using strict alphabetical order.
178-
# See https://pycqa.github.io/isort/docs/configuration/options.html#force-sort-within-sections
176+
# 1. Install ruff (skipped automatically if you run with --no-venv)
177+
session.install(RUFF_VERSION)
178+
179+
# 2. Run Ruff to fix imports
179180
session.run(
180-
"isort",
181-
"--fss",
181+
"ruff", "check",
182+
"--select", "I",
183+
"--fix",
184+
f"--target-version=py{UNIT_TEST_PYTHON_VERSIONS[0].replace('.', '')}",
185+
"--line-length=88",
182186
*LINT_PATHS,
183187
)
188+
189+
# 3. Run Ruff to format code
184190
session.run(
185-
"black",
191+
"ruff", "format",
192+
f"--target-version=py{UNIT_TEST_PYTHON_VERSIONS[0].replace('.', '')}",
193+
"--line-length=88",
186194
*LINT_PATHS,
187195
)
188196

packages/db-dtypes/noxfile.py

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929

3030
FLAKE8_VERSION = "flake8==6.1.0"
3131
BLACK_VERSION = "black[jupyter]==23.7.0"
32+
RUFF_VERSION = "ruff==0.14.14"
3233
ISORT_VERSION = "isort==5.11.0"
3334
LINT_PATHS = ["docs", "db_dtypes", "tests", "noxfile.py", "setup.py"]
3435

@@ -122,20 +123,26 @@ def blacken(session):
122123
@nox.session(python=DEFAULT_PYTHON_VERSION)
123124
def format(session):
124125
"""
125-
Run isort to sort imports. Then run black
126-
to format code to uniform standard.
126+
Run ruff to sort imports and format code.
127127
"""
128-
session.install(BLACK_VERSION, ISORT_VERSION)
129-
# Use the --fss option to sort imports using strict alphabetical order.
130-
# See https://pycqa.github.io/isort/docs/configuration/options.html#force-sort-within-sections
131-
session.run("python", "-m", "pip", "freeze")
128+
# 1. Install ruff (skipped automatically if you run with --no-venv)
129+
session.install(RUFF_VERSION)
130+
131+
# 2. Run Ruff to fix imports
132132
session.run(
133-
"isort",
134-
"--fss",
133+
"ruff", "check",
134+
"--select", "I",
135+
"--fix",
136+
f"--target-version=py{UNIT_TEST_PYTHON_VERSIONS[0].replace('.', '')}",
137+
"--line-length=88",
135138
*LINT_PATHS,
136139
)
140+
141+
# 3. Run Ruff to format code
137142
session.run(
138-
"black",
143+
"ruff", "format",
144+
f"--target-version=py{UNIT_TEST_PYTHON_VERSIONS[0].replace('.', '')}",
145+
"--line-length=88",
139146
*LINT_PATHS,
140147
)
141148

packages/google-api-core/noxfile.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929

3030

3131
BLACK_VERSION = "black==23.7.0"
32+
RUFF_VERSION = "ruff==0.14.14"
3233
BLACK_PATHS = ["docs", "google", "tests", "noxfile.py", "setup.py"]
3334
# Black and flake8 clash on the syntax for ignoring flake8's F401 in this file.
3435
BLACK_EXCLUDES = ["--exclude", "^/google/api_core/operations_v1/__init__.py"]
@@ -72,6 +73,33 @@ def blacken(session):
7273
session.run("black", *BLACK_EXCLUDES, *BLACK_PATHS)
7374

7475

76+
@nox.session(python=DEFAULT_PYTHON_VERSION)
77+
def format(session):
78+
"""
79+
Run ruff to sort imports and format code.
80+
"""
81+
# 1. Install ruff (skipped automatically if you run with --no-venv)
82+
session.install(RUFF_VERSION)
83+
84+
# 2. Run Ruff to fix imports
85+
session.run(
86+
"ruff", "check",
87+
"--select", "I",
88+
"--fix",
89+
f"--target-version=py{ALL_PYTHON[0].replace('.', '')}",
90+
"--line-length=88",
91+
*BLACK_PATHS,
92+
)
93+
94+
# 3. Run Ruff to format code
95+
session.run(
96+
"ruff", "format",
97+
f"--target-version=py{ALL_PYTHON[0].replace('.', '')}",
98+
"--line-length=88",
99+
*BLACK_PATHS,
100+
)
101+
102+
75103
def install_prerelease_dependencies(session, constraints_path):
76104
with open(constraints_path, encoding="utf-8") as constraints_file:
77105
constraints_text = constraints_file.read()

packages/google-auth-httplib2/noxfile.py

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727

2828
FLAKE8_VERSION = "flake8==6.1.0"
2929
BLACK_VERSION = "black[jupyter]==23.7.0"
30+
RUFF_VERSION = "ruff==0.14.14"
3031
ISORT_VERSION = "isort==5.11.0"
3132
LINT_PATHS = ["docs", "google_auth_httplib2.py", "tests", "noxfile.py", "setup.py"]
3233

@@ -118,19 +119,26 @@ def blacken(session):
118119
@nox.session(python=DEFAULT_PYTHON_VERSION)
119120
def format(session):
120121
"""
121-
Run isort to sort imports. Then run black
122-
to format code to uniform standard.
122+
Run ruff to sort imports and format code.
123123
"""
124-
session.install(BLACK_VERSION, ISORT_VERSION)
125-
# Use the --fss option to sort imports using strict alphabetical order.
126-
# See https://pycqa.github.io/isort/docs/configuration/options.html#force-sort-within-sections
124+
# 1. Install ruff (skipped automatically if you run with --no-venv)
125+
session.install(RUFF_VERSION)
126+
127+
# 2. Run Ruff to fix imports
127128
session.run(
128-
"isort",
129-
"--fss",
129+
"ruff", "check",
130+
"--select", "I",
131+
"--fix",
132+
f"--target-version=py{UNIT_TEST_PYTHON_VERSIONS[0].replace('.', '')}",
133+
"--line-length=88",
130134
*LINT_PATHS,
131135
)
136+
137+
# 3. Run Ruff to format code
132138
session.run(
133-
"black",
139+
"ruff", "format",
140+
f"--target-version=py{UNIT_TEST_PYTHON_VERSIONS[0].replace('.', '')}",
141+
"--line-length=88",
134142
*LINT_PATHS,
135143
)
136144

packages/google-auth-oauthlib/noxfile.py

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929

3030
FLAKE8_VERSION = "flake8==6.1.0"
3131
BLACK_VERSION = "black[jupyter]==23.7.0"
32+
RUFF_VERSION = "ruff==0.14.14"
3233
ISORT_VERSION = "isort==5.11.0"
3334
LINT_PATHS = ["docs", "google_auth_oauthlib", "tests", "noxfile.py", "setup.py"]
3435

@@ -103,19 +104,26 @@ def blacken(session):
103104
@nox.session(python=DEFAULT_PYTHON_VERSION)
104105
def format(session):
105106
"""
106-
Run isort to sort imports. Then run black
107-
to format code to uniform standard.
107+
Run ruff to sort imports and format code.
108108
"""
109-
session.install(BLACK_VERSION, ISORT_VERSION)
110-
# Use the --fss option to sort imports using strict alphabetical order.
111-
# See https://pycqa.github.io/isort/docs/configuration/options.html#force-sort-within-sections
109+
# 1. Install ruff (skipped automatically if you run with --no-venv)
110+
session.install(RUFF_VERSION)
111+
112+
# 2. Run Ruff to fix imports
112113
session.run(
113-
"isort",
114-
"--fss",
114+
"ruff", "check",
115+
"--select", "I",
116+
"--fix",
117+
f"--target-version=py{UNIT_TEST_PYTHON_VERSIONS[0].replace('.', '')}",
118+
"--line-length=88",
115119
*LINT_PATHS,
116120
)
121+
122+
# 3. Run Ruff to format code
117123
session.run(
118-
"black",
124+
"ruff", "format",
125+
f"--target-version=py{UNIT_TEST_PYTHON_VERSIONS[0].replace('.', '')}",
126+
"--line-length=88",
119127
*LINT_PATHS,
120128
)
121129

packages/google-auth/noxfile.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
CLICK_VERSION = "click"
2424
BLACK_VERSION = "black==23.7.0"
25+
RUFF_VERSION = "ruff==0.14.14"
2526
BLACK_PATHS = [
2627
"google",
2728
"tests",
@@ -51,6 +52,7 @@
5152
nox.options.sessions = [
5253
"lint",
5354
"blacken",
55+
"format",
5456
"mypy",
5557
# cover must be last to avoid error `No data to report`
5658
"docs",
@@ -97,6 +99,33 @@ def blacken(session):
9799
session.run("black", *BLACK_PATHS)
98100

99101

102+
@nox.session(python=DEFAULT_PYTHON_VERSION)
103+
def format(session):
104+
"""
105+
Run ruff to sort imports and format code.
106+
"""
107+
# 1. Install ruff (skipped automatically if you run with --no-venv)
108+
session.install(RUFF_VERSION)
109+
110+
# 2. Run Ruff to fix imports
111+
session.run(
112+
"ruff", "check",
113+
"--select", "I",
114+
"--fix",
115+
f"--target-version=py{ALL_PYTHON[0].replace('.', '')}",
116+
"--line-length=88",
117+
*BLACK_PATHS,
118+
)
119+
120+
# 3. Run Ruff to format code
121+
session.run(
122+
"ruff", "format",
123+
f"--target-version=py{ALL_PYTHON[0].replace('.', '')}",
124+
"--line-length=88",
125+
*BLACK_PATHS,
126+
)
127+
128+
100129
@nox.session(python=DEFAULT_PYTHON_VERSION)
101130
def mypy(session):
102131
"""Verify type hints are mypy compatible."""

packages/google-cloud-core/noxfile.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222

2323
BLACK_VERSION = "black==23.7.0"
24+
RUFF_VERSION = "ruff==0.14.14"
2425
BLACK_PATHS = ["docs", "google", "tests", "noxfile.py", "setup.py"]
2526

2627
DEFAULT_PYTHON_VERSION = "3.14"
@@ -75,6 +76,33 @@ def blacken(session):
7576
session.run("black", *BLACK_PATHS)
7677

7778

79+
@nox.session(python=DEFAULT_PYTHON_VERSION)
80+
def format(session):
81+
"""
82+
Run ruff to sort imports and format code.
83+
"""
84+
# 1. Install ruff (skipped automatically if you run with --no-venv)
85+
session.install(RUFF_VERSION)
86+
87+
# 2. Run Ruff to fix imports
88+
session.run(
89+
"ruff", "check",
90+
"--select", "I",
91+
"--fix",
92+
f"--target-version=py{UNIT_TEST_PYTHON_VERSIONS[0].replace('.', '')}",
93+
"--line-length=88",
94+
*BLACK_PATHS,
95+
)
96+
97+
# 3. Run Ruff to format code
98+
session.run(
99+
"ruff", "format",
100+
f"--target-version=py{UNIT_TEST_PYTHON_VERSIONS[0].replace('.', '')}",
101+
"--line-length=88",
102+
*BLACK_PATHS,
103+
)
104+
105+
78106
def default(session):
79107
"""Default unit test session.
80108
This is intended to be run **without** an interpreter set, so

packages/google-cloud-dns/noxfile.py

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929

3030
FLAKE8_VERSION = "flake8==6.1.0"
3131
BLACK_VERSION = "black[jupyter]==23.7.0"
32+
RUFF_VERSION = "ruff==0.14.14"
3233
ISORT_VERSION = "isort==5.11.0"
3334
LINT_PATHS = ["docs", "google", "tests", "noxfile.py", "setup.py"]
3435

@@ -118,19 +119,26 @@ def blacken(session):
118119
@nox.session(python=DEFAULT_PYTHON_VERSION)
119120
def format(session):
120121
"""
121-
Run isort to sort imports. Then run black
122-
to format code to uniform standard.
122+
Run ruff to sort imports and format code.
123123
"""
124-
session.install(BLACK_VERSION, ISORT_VERSION)
125-
# Use the --fss option to sort imports using strict alphabetical order.
126-
# See https://pycqa.github.io/isort/docs/configuration/options.html#force-sort-within-sections
124+
# 1. Install ruff (skipped automatically if you run with --no-venv)
125+
session.install(RUFF_VERSION)
126+
127+
# 2. Run Ruff to fix imports
127128
session.run(
128-
"isort",
129-
"--fss",
129+
"ruff", "check",
130+
"--select", "I",
131+
"--fix",
132+
f"--target-version=py{ALL_PYTHON[0].replace('.', '')}",
133+
"--line-length=88",
130134
*LINT_PATHS,
131135
)
136+
137+
# 3. Run Ruff to format code
132138
session.run(
133-
"black",
139+
"ruff", "format",
140+
f"--target-version=py{ALL_PYTHON[0].replace('.', '')}",
141+
"--line-length=88",
134142
*LINT_PATHS,
135143
)
136144

packages/google-cloud-documentai-toolbox/noxfile.py

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929

3030
FLAKE8_VERSION = "flake8==6.1.0"
3131
BLACK_VERSION = "black[jupyter]==23.7.0"
32+
RUFF_VERSION = "ruff==0.14.14"
3233
ISORT_VERSION = "isort==5.11.0"
3334
LINT_PATHS = ["docs", "google", "tests", "noxfile.py", "setup.py"]
3435

@@ -120,19 +121,26 @@ def blacken(session):
120121
@nox.session(python=DEFAULT_PYTHON_VERSION)
121122
def format(session):
122123
"""
123-
Run isort to sort imports. Then run black
124-
to format code to uniform standard.
124+
Run ruff to sort imports and format code.
125125
"""
126-
session.install(BLACK_VERSION, ISORT_VERSION)
127-
# Use the --fss option to sort imports using strict alphabetical order.
128-
# See https://pycqa.github.io/isort/docs/configuration/options.html#force-sort-within-sections
126+
# 1. Install ruff (skipped automatically if you run with --no-venv)
127+
session.install(RUFF_VERSION)
128+
129+
# 2. Run Ruff to fix imports
129130
session.run(
130-
"isort",
131-
"--fss",
131+
"ruff", "check",
132+
"--select", "I",
133+
"--fix",
134+
f"--target-version=py{UNIT_TEST_PYTHON_VERSIONS[0].replace('.', '')}",
135+
"--line-length=88",
132136
*LINT_PATHS,
133137
)
138+
139+
# 3. Run Ruff to format code
134140
session.run(
135-
"black",
141+
"ruff", "format",
142+
f"--target-version=py{UNIT_TEST_PYTHON_VERSIONS[0].replace('.', '')}",
143+
"--line-length=88",
136144
*LINT_PATHS,
137145
)
138146

0 commit comments

Comments
 (0)