Skip to content

Commit bff166f

Browse files
chalmerloweparthea
authored andcommitted
chore: updates noxfile to incorporate ruff
1 parent 8eaaaf1 commit bff166f

1 file changed

Lines changed: 32 additions & 0 deletions

File tree

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"
@@ -702,3 +703,34 @@ def core_deps_from_source(session):
702703
# TODO(https://github.com/googleapis/google-cloud-python/issues/16014):
703704
# Add core deps from source tests
704705
session.skip("Core deps from source tests are not yet supported")
706+
707+
@nox.session
708+
def format(session: nox.sessions.Session) -> None:
709+
"""
710+
Run ruff to sort imports and format code.
711+
"""
712+
# 1. Install ruff (skipped automatically if you run with --no-venv)
713+
session.install(RUFF_VERSION)
714+
715+
# 2. Run Ruff to fix imports
716+
# check --select I: Enables strict import sorting
717+
# --fix: Applies the changes automatically
718+
session.run(
719+
"ruff",
720+
"check",
721+
"--select",
722+
"I",
723+
"--fix",
724+
f"--target-version=py{ALL_PYTHON[0].replace('.', '')}",
725+
"--line-length=88", # Standard Black line length
726+
*LINT_PATHS,
727+
)
728+
729+
# 3. Run Ruff to format code
730+
session.run(
731+
"ruff",
732+
"format",
733+
f"--target-version=py{ALL_PYTHON[0].replace('.', '')}",
734+
"--line-length=88", # Standard Black line length
735+
*LINT_PATHS,
736+
)

0 commit comments

Comments
 (0)