Skip to content

Commit eaa6169

Browse files
committed
updated noxfile to use ruff
1 parent a7cab6f commit eaa6169

1 file changed

Lines changed: 24 additions & 16 deletions

File tree

packages/google-api-core/noxfile.py

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,8 @@
2828
# https://github.com/google/importlab/issues/25
2929
import nox
3030

31-
BLACK_VERSION = "black==23.7.0"
3231
RUFF_VERSION = "ruff==0.14.14"
33-
BLACK_PATHS = ["docs", "google", "tests", "noxfile.py", "setup.py"]
34-
# Black and flake8 clash on the syntax for ignoring flake8's F401 in this file.
35-
BLACK_EXCLUDES = ["--exclude", "^/google/api_core/operations_v1/__init__.py"]
32+
LINT_PATHS = ["docs", "google", "tests", "noxfile.py", "setup.py"]
3633

3734
ALL_PYTHON = ["3.10", "3.11", "3.12", "3.13", "3.14"]
3835
SUPPORTED_PYTHON_VERSIONS = ["3.10", "3.11", "3.12", "3.13", "3.14"]
@@ -52,25 +49,36 @@ def lint(session):
5249
Returns a failure if the linters find linting errors or sufficiently
5350
serious code quality issues.
5451
"""
55-
session.install("flake8", BLACK_VERSION)
56-
session.install(".")
52+
session.install("flake8", RUFF_VERSION)
53+
5754
session.run(
58-
"black",
55+
"ruff",
56+
"format",
5957
"--check",
60-
*BLACK_EXCLUDES,
61-
*BLACK_PATHS,
58+
f"--target-version=py{ALL_PYTHON[0].replace('.', '')}",
59+
"--line-length=88",
60+
*LINT_PATHS,
6261
)
62+
6363
session.run("flake8", "google", "tests")
6464

6565

6666
@nox.session(python=DEFAULT_PYTHON_VERSION)
6767
def blacken(session):
68-
"""Run black.
68+
"""(Deprecated) Legacy session. Please use 'nox -s format'."""
69+
session.log(
70+
"WARNING: The 'blacken' session is deprecated and will be removed in a future release. Please use 'nox -s format' in the future."
71+
)
6972

70-
Format code to uniform standard.
71-
"""
72-
session.install(BLACK_VERSION)
73-
session.run("black", *BLACK_EXCLUDES, *BLACK_PATHS)
73+
# Just run the ruff formatter (keeping legacy behavior of only formatting, not sorting imports)
74+
session.install(RUFF_VERSION)
75+
session.run(
76+
"ruff",
77+
"format",
78+
f"--target-version=py{ALL_PYTHON[0].replace('.', '')}",
79+
"--line-length=88",
80+
*LINT_PATHS,
81+
)
7482

7583

7684
@nox.session(python=DEFAULT_PYTHON_VERSION)
@@ -90,7 +98,7 @@ def format(session):
9098
"--fix",
9199
f"--target-version=py{ALL_PYTHON[0].replace('.', '')}",
92100
"--line-length=88",
93-
*BLACK_PATHS,
101+
*LINT_PATHS,
94102
)
95103

96104
# 3. Run Ruff to format code
@@ -99,7 +107,7 @@ def format(session):
99107
"format",
100108
f"--target-version=py{ALL_PYTHON[0].replace('.', '')}",
101109
"--line-length=88",
102-
*BLACK_PATHS,
110+
*LINT_PATHS,
103111
)
104112

105113

0 commit comments

Comments
 (0)