Skip to content

Commit 9a35d35

Browse files
committed
chore: updates noxfile to incorporate ruff
1 parent 4687922 commit 9a35d35

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

packages/google-cloud-spanner/noxfile.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
FLAKE8_VERSION = "flake8==6.1.0"
3535
BLACK_VERSION = "black[jupyter]==23.7.0"
3636
ISORT_VERSION = "isort==5.11.0"
37+
RUFF_VERSION = "ruff==0.14.14"
3738
LINT_PATHS = ["google", "tests", "noxfile.py", "setup.py"]
3839

3940
DEFAULT_PYTHON_VERSION = "3.14"
@@ -655,3 +656,34 @@ def core_deps_from_source(session):
655656
# TODO(https://github.com/googleapis/google-cloud-python/issues/16014):
656657
# Add core deps from source tests
657658
session.skip("Core deps from source tests are not yet supported")
659+
660+
@nox.session
661+
def format(session: nox.sessions.Session) -> None:
662+
"""
663+
Run ruff to sort imports and format code.
664+
"""
665+
# 1. Install ruff (skipped automatically if you run with --no-venv)
666+
session.install(RUFF_VERSION)
667+
668+
# 2. Run Ruff to fix imports
669+
# check --select I: Enables strict import sorting
670+
# --fix: Applies the changes automatically
671+
session.run(
672+
"ruff",
673+
"check",
674+
"--select",
675+
"I",
676+
"--fix",
677+
f"--target-version=py{ALL_PYTHON[0].replace('.', '')}",
678+
"--line-length=88", # Standard Black line length
679+
*LINT_PATHS,
680+
)
681+
682+
# 3. Run Ruff to format code
683+
session.run(
684+
"ruff",
685+
"format",
686+
f"--target-version=py{ALL_PYTHON[0].replace('.', '')}",
687+
"--line-length=88", # Standard Black line length
688+
*LINT_PATHS,
689+
)

0 commit comments

Comments
 (0)