Skip to content

Commit 6ad8180

Browse files
committed
chore: updates noxfile with additional sessions, ruff, etc
1 parent e3c4c86 commit 6ad8180

1 file changed

Lines changed: 59 additions & 20 deletions

File tree

packages/google-cloud-storage/noxfile.py

Lines changed: 59 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828

2929
BLACK_VERSION = "black==23.7.0"
3030
ISORT_VERSION = "isort==5.12.0"
31+
RUFF_VERSION = "ruff==0.14.14"
3132
BLACK_PATHS = ["docs", "google", "tests", "noxfile.py", "setup.py"]
3233

3334
DEFAULT_PYTHON_VERSION = "3.14"
@@ -82,23 +83,30 @@ def lint(session):
8283
"""
8384
session.install("flake8", BLACK_VERSION)
8485
session.run(
85-
"black",
86+
"ruff",
87+
"format",
8688
"--check",
87-
*BLACK_PATHS,
89+
f"--target-version=py{ALL_PYTHON[0].replace('.', '')}",
90+
"--line-length=88",
91+
*LINT_PATHS,
8892
)
93+
8994
session.run("flake8", "google", "tests")
9095

9196

9297
@nox.session(python=DEFAULT_PYTHON_VERSION)
9398
def blacken(session):
94-
"""Run black.
95-
96-
Format code to uniform standard.
97-
"""
98-
session.install(BLACK_VERSION)
99+
"""(Deprecated) Legacy session. Please use 'nox -s format'."""
100+
session.log(
101+
"WARNING: The 'blacken' session is deprecated and will be removed in a future release. Please use 'nox -s format' in the future."
102+
)
103+
session.install(RUFF_VERSION)
99104
session.run(
100-
"black",
101-
*BLACK_PATHS,
105+
"ruff",
106+
"format",
107+
f"--target-version=py{ALL_PYTHON[0].replace('.', '')}",
108+
"--line-length=88",
109+
*LINT_PATHS,
102110
)
103111

104112

@@ -488,9 +496,23 @@ def prerelease_deps(session, protobuf_implementation):
488496
@nox.session(python=DEFAULT_PYTHON_VERSION)
489497
def mypy(session):
490498
"""Run the type checker."""
491-
# TODO(https://github.com/googleapis/google-cloud-python/issues/16014):
492-
# Add mypy tests
493-
session.skip("mypy tests are not yet supported")
499+
session.skip("Mypy is not yet supported")
500+
501+
# TODO(https://github.com/googleapis/gapic-generator-python/issues/2579):
502+
# use the latest version of mypy
503+
session.install(
504+
"mypy<1.16.0",
505+
"types-requests",
506+
"types-protobuf",
507+
)
508+
session.install(".")
509+
session.run(
510+
"mypy",
511+
"-p",
512+
"google",
513+
# "--check-untyped-defs",
514+
*session.posargs,
515+
)
494516

495517

496518
@nox.session(python=DEFAULT_PYTHON_VERSION)
@@ -506,13 +528,30 @@ def core_deps_from_source(session):
506528
@nox.session
507529
def format(session: nox.sessions.Session) -> None:
508530
"""
509-
Run isort to sort imports. Then run black
510-
to format code to uniform standard.
531+
Run ruff to sort imports and format code.
511532
"""
512-
session.install(BLACK_VERSION, ISORT_VERSION)
513-
python_files = [path for path in os.listdir(".") if path.endswith(".py")]
533+
# 1. Install ruff (skipped automatically if you run with --no-venv)
534+
session.install(RUFF_VERSION)
535+
536+
# 2. Run Ruff to fix imports
537+
# check --select I: Enables strict import sorting
538+
# --fix: Applies the changes automatically
539+
session.run(
540+
"ruff",
541+
"check",
542+
"--select",
543+
"I",
544+
"--fix",
545+
f"--target-version=py{ALL_PYTHON[0].replace('.', '')}",
546+
"--line-length=88", # Standard Black line length
547+
*LINT_PATHS,
548+
)
514549

515-
# Use the --fss option to sort imports using strict alphabetical order.
516-
# See https://pycqa.github.io/isort/docs/configuration/options.html#force-sort-within-sections
517-
session.run("isort", "--fss", *python_files)
518-
session.run("black", *python_files)
550+
# 3. Run Ruff to format code
551+
session.run(
552+
"ruff",
553+
"format",
554+
f"--target-version=py{ALL_PYTHON[0].replace('.', '')}",
555+
"--line-length=88", # Standard Black line length
556+
*LINT_PATHS,
557+
)

0 commit comments

Comments
 (0)