Skip to content

Commit 064df21

Browse files
committed
chore: updates noxfiles with RUFF version and format session
1 parent ef62df4 commit 064df21

File tree

9 files changed

+174
-43
lines changed

9 files changed

+174
-43
lines changed

packages/bigframes/noxfile.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,15 @@ def format(session):
191191
*LINT_PATHS,
192192
)
193193

194+
# 3. Run Ruff to format code
195+
session.run(
196+
"ruff",
197+
"format",
198+
f"--target-version=py{ALL_PYTHON[0].replace('.', '')}",
199+
"--line-length=88", # Standard Black line length
200+
*LINT_PATHS,
201+
)
202+
194203

195204
@nox.session(python=DEFAULT_PYTHON_VERSION)
196205
def lint_setup_py(session):

packages/google-cloud-bigquery/noxfile.py

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525

2626
MYPY_VERSION = "mypy==1.6.1"
2727
BLACK_VERSION = "black==23.7.0"
28+
RUFF_VERSION = "ruff==0.14.14"
2829
ISORT_VERSION = "isort==5.10.1"
2930
BLACK_PATHS = (
3031
"benchmark",
@@ -550,16 +551,28 @@ def core_deps_from_source(session):
550551
session.skip("Core deps from source tests are not yet supported")
551552

552553

553-
@nox.session
554-
def format(session: nox.sessions.Session) -> None:
554+
@nox.session(python=DEFAULT_PYTHON_VERSION)
555+
def format(session):
555556
"""
556-
Run isort to sort imports. Then run black
557-
to format code to uniform standard.
557+
Run ruff to sort imports and format code.
558558
"""
559-
session.install(BLACK_VERSION, ISORT_VERSION)
560-
python_files = [path for path in os.listdir(".") if path.endswith(".py")]
559+
# 1. Install ruff (skipped automatically if you run with --no-venv)
560+
session.install(RUFF_VERSION)
561+
562+
# 2. Run Ruff to fix imports
563+
session.run(
564+
"ruff", "check",
565+
"--select", "I",
566+
"--fix",
567+
f"--target-version=py{UNIT_TEST_PYTHON_VERSIONS[0].replace('.', '')}",
568+
"--line-length=88",
569+
*BLACK_PATHS,
570+
)
561571

562-
# Use the --fss option to sort imports using strict alphabetical order.
563-
# See https://pycqa.github.io/isort/docs/configuration/options.html#force-sort-within-sections
564-
session.run("isort", "--fss", *python_files)
565-
session.run("black", *python_files)
572+
# 3. Run Ruff to format code
573+
session.run(
574+
"ruff", "format",
575+
f"--target-version=py{UNIT_TEST_PYTHON_VERSIONS[0].replace('.', '')}",
576+
"--line-length=88",
577+
*BLACK_PATHS,
578+
)

packages/google-cloud-ndb/noxfile.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
CURRENT_DIRECTORY = pathlib.Path(__file__).parent.absolute()
3434

3535
BLACK_VERSION = "black[jupyter]==23.7.0"
36+
RUFF_VERSION = "ruff==0.14.14"
3637
UNIT_TEST_STANDARD_DEPENDENCIES = [
3738
"mock",
3839
"asyncmock",
@@ -58,6 +59,7 @@
5859
"emulator-system",
5960
"lint",
6061
"blacken",
62+
"format",
6163
"docs",
6264
"doctest",
6365
"system",
@@ -278,6 +280,33 @@ def blacken(session):
278280
run_black(session)
279281

280282

283+
@nox.session(py=DEFAULT_INTERPRETER)
284+
def format(session):
285+
"""
286+
Run ruff to sort imports and format code.
287+
"""
288+
# 1. Install ruff (skipped automatically if you run with --no-venv)
289+
session.install(RUFF_VERSION)
290+
291+
# 2. Run Ruff to fix imports
292+
session.run(
293+
"ruff", "check",
294+
"--select", "I",
295+
"--fix",
296+
f"--target-version=py{ALL_INTERPRETERS[0].replace('.', '')}",
297+
"--line-length=88",
298+
"docs", "noxfile.py", "google", "tests",
299+
)
300+
301+
# 3. Run Ruff to format code
302+
session.run(
303+
"ruff", "format",
304+
f"--target-version=py{ALL_INTERPRETERS[0].replace('.', '')}",
305+
"--line-length=88",
306+
"docs", "noxfile.py", "google", "tests",
307+
)
308+
309+
281310
@nox.session(py="3.10")
282311
def docs(session):
283312
"""Build the docs for this library."""

packages/google-cloud-storage/noxfile.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@
8989
"lint",
9090
"lint_setup_py",
9191
"blacken",
92+
"format",
9293
"docs",
9394
]
9495

packages/google-crc32c/noxfile.py

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

3232
FLAKE8_VERSION = "flake8==6.1.0"
3333
BLACK_VERSION = "black[jupyter]==23.7.0"
34+
RUFF_VERSION = "ruff==0.14.14"
3435
ISORT_VERSION = "isort==5.11.0"
3536
LINT_PATHS = ["src", "tests", "noxfile.py", "setup.py"]
3637

@@ -116,19 +117,26 @@ def blacken(session):
116117
@nox.session(python=DEFAULT_PYTHON_VERSION)
117118
def format(session):
118119
"""
119-
Run isort to sort imports. Then run black
120-
to format code to uniform standard.
120+
Run ruff to sort imports and format code.
121121
"""
122-
session.install(BLACK_VERSION, ISORT_VERSION)
123-
# Use the --fss option to sort imports using strict alphabetical order.
124-
# See https://pycqa.github.io/isort/docs/configuration/options.html#force-sort-within-sections
122+
# 1. Install ruff (skipped automatically if you run with --no-venv)
123+
session.install(RUFF_VERSION)
124+
125+
# 2. Run Ruff to fix imports
125126
session.run(
126-
"isort",
127-
"--fss",
127+
"ruff", "check",
128+
"--select", "I",
129+
"--fix",
130+
f"--target-version=py{ALL_PYTHON[0].replace('.', '')}",
131+
"--line-length=88",
128132
*LINT_PATHS,
129133
)
134+
135+
# 3. Run Ruff to format code
130136
session.run(
131-
"black",
137+
"ruff", "format",
138+
f"--target-version=py{ALL_PYTHON[0].replace('.', '')}",
139+
"--line-length=88",
132140
*LINT_PATHS,
133141
)
134142

packages/google-resumable-media/noxfile.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
"blacken",
3737
"mypy",
3838
"doctest",
39+
"format",
3940
]
4041

4142

@@ -240,6 +241,43 @@ def blacken(session):
240241
)
241242

242243

244+
@nox.session(python=DEFAULT_PYTHON_VERSION)
245+
def format(session):
246+
"""
247+
Run ruff to sort imports and format code.
248+
"""
249+
# 1. Install ruff (skipped automatically if you run with --no-venv)
250+
session.install(RUFF_VERSION)
251+
252+
# 2. Run Ruff to fix imports
253+
session.run(
254+
"ruff", "check",
255+
"--select", "I",
256+
"--fix",
257+
f"--target-version=py{UNIT_TEST_PYTHON_VERSIONS[0].replace('.', '')}",
258+
"--line-length=88",
259+
os.path.join("google", "resumable_media"),
260+
"tests",
261+
os.path.join("google", "_async_resumable_media"),
262+
"tests_async",
263+
"noxfile.py",
264+
"setup.py",
265+
)
266+
267+
# 3. Run Ruff to format code
268+
session.run(
269+
"ruff", "format",
270+
f"--target-version=py{UNIT_TEST_PYTHON_VERSIONS[0].replace('.', '')}",
271+
"--line-length=88",
272+
os.path.join("google", "resumable_media"),
273+
"tests",
274+
os.path.join("google", "_async_resumable_media"),
275+
"tests_async",
276+
"noxfile.py",
277+
"setup.py",
278+
)
279+
280+
243281
@nox.session(python=DEFAULT_PYTHON_VERSION)
244282
def mypy(session):
245283
"""Verify type hints are mypy compatible."""

packages/pandas-gbq/noxfile.py

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

3131
BLACK_VERSION = "black==23.7.0"
32+
RUFF_VERSION = "ruff==0.14.14"
3233
ISORT_VERSION = "isort==5.10.1"
3334
LINT_PATHS = ["docs", "pandas_gbq", "tests", "noxfile.py", "setup.py"]
3435

@@ -112,6 +113,7 @@ def wrapper(*args, **kwargs):
112113
"lint",
113114
"lint_setup_py",
114115
"blacken",
116+
"format",
115117
"docs",
116118
]
117119

@@ -151,19 +153,26 @@ def blacken(session):
151153
@_calculate_duration
152154
def format(session):
153155
"""
154-
Run isort to sort imports. Then run black
155-
to format code to uniform standard.
156+
Run ruff to sort imports and format code.
156157
"""
157-
session.install(BLACK_VERSION, ISORT_VERSION)
158-
# Use the --fss option to sort imports using strict alphabetical order.
159-
# See https://pycqa.github.io/isort/docs/configuration/options.html#force-sort-within-sections
158+
# 1. Install ruff (skipped automatically if you run with --no-venv)
159+
session.install(RUFF_VERSION)
160+
161+
# 2. Run Ruff to fix imports
160162
session.run(
161-
"isort",
162-
"--fss",
163+
"ruff", "check",
164+
"--select", "I",
165+
"--fix",
166+
f"--target-version=py{UNIT_TEST_PYTHON_VERSIONS[0].replace('.', '')}",
167+
"--line-length=88",
163168
*LINT_PATHS,
164169
)
170+
171+
# 3. Run Ruff to format code
165172
session.run(
166-
"black",
173+
"ruff", "format",
174+
f"--target-version=py{UNIT_TEST_PYTHON_VERSIONS[0].replace('.', '')}",
175+
"--line-length=88",
167176
*LINT_PATHS,
168177
)
169178

packages/sqlalchemy-bigquery/noxfile.py

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131

3232
FLAKE8_VERSION = "flake8==6.1.0"
3333
BLACK_VERSION = "black[jupyter]==23.7.0"
34+
RUFF_VERSION = "ruff==0.14.14"
3435
ISORT_VERSION = "isort==5.11.0"
3536
LINT_PATHS = [
3637
"third_party",
@@ -200,22 +201,26 @@ def blacken(session):
200201
@_calculate_duration
201202
def format(session):
202203
"""
203-
Run isort to sort imports. Then run black
204-
to format code to uniform standard.
204+
Run ruff to sort imports and format code.
205205
"""
206-
session.install(BLACK_VERSION, ISORT_VERSION)
206+
# 1. Install ruff (skipped automatically if you run with --no-venv)
207+
session.install(RUFF_VERSION)
207208

208-
session.run("python", "-m", "pip", "freeze")
209-
210-
# Use the --fss option to sort imports using strict alphabetical order.
211-
# See https://pycqa.github.io/isort/docs/configuration/options.html#force-sort-within-sections
209+
# 2. Run Ruff to fix imports
212210
session.run(
213-
"isort",
214-
"--fss",
211+
"ruff", "check",
212+
"--select", "I",
213+
"--fix",
214+
f"--target-version=py{UNIT_TEST_PYTHON_VERSIONS[0].replace('.', '')}",
215+
"--line-length=88",
215216
*LINT_PATHS,
216217
)
218+
219+
# 3. Run Ruff to format code
217220
session.run(
218-
"black",
221+
"ruff", "format",
222+
f"--target-version=py{UNIT_TEST_PYTHON_VERSIONS[0].replace('.', '')}",
223+
"--line-length=88",
219224
*LINT_PATHS,
220225
)
221226

packages/sqlalchemy-spanner/noxfile.py

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ class = StreamHandler
7878

7979

8080
BLACK_VERSION = "black==23.7.0"
81+
RUFF_VERSION = "ruff==0.14.14"
8182
ISORT_VERSION = "isort==5.11.0"
8283
BLACK_PATHS = ["google", "tests", "noxfile.py", "setup.py", "samples"]
8384
UNIT_TEST_PYTHON_VERSIONS = ["3.8", "3.9", "3.10", "3.11", "3.12", "3.13", "3.14"]
@@ -96,6 +97,7 @@ class = StreamHandler
9697
"migration_test",
9798
"_migration_test",
9899
"mockserver",
100+
"format",
99101
]
100102

101103

@@ -434,11 +436,28 @@ def docfx(session):
434436
session.skip("docfx builds are not yet supported")
435437

436438

437-
@nox.session
438-
def format(session: nox.sessions.Session) -> None:
439-
session.install(BLACK_VERSION, ISORT_VERSION)
440-
import os
439+
@nox.session(python=DEFAULT_PYTHON_VERSION)
440+
def format(session):
441+
"""
442+
Run ruff to sort imports and format code.
443+
"""
444+
# 1. Install ruff (skipped automatically if you run with --no-venv)
445+
session.install(RUFF_VERSION)
441446

442-
python_files = [path for path in os.listdir(".") if path.endswith(".py")]
443-
session.run("isort", "--fss", *python_files)
444-
session.run("black", *python_files)
447+
# 2. Run Ruff to fix imports
448+
session.run(
449+
"ruff", "check",
450+
"--select", "I",
451+
"--fix",
452+
f"--target-version=py{UNIT_TEST_PYTHON_VERSIONS[0].replace('.', '')}",
453+
"--line-length=88",
454+
*BLACK_PATHS,
455+
)
456+
457+
# 3. Run Ruff to format code
458+
session.run(
459+
"ruff", "format",
460+
f"--target-version=py{UNIT_TEST_PYTHON_VERSIONS[0].replace('.', '')}",
461+
"--line-length=88",
462+
*BLACK_PATHS,
463+
)

0 commit comments

Comments
 (0)