Skip to content

Commit 2207b2b

Browse files
committed
chore: updates noxfile with additional sessions, ruff, etc
1 parent 4c65156 commit 2207b2b

File tree

1 file changed

+61
-23
lines changed

1 file changed

+61
-23
lines changed

packages/google-cloud-storage/noxfile.py

Lines changed: 61 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

2525
BLACK_VERSION = "black==23.7.0"
2626
ISORT_VERSION = "isort==5.12.0"
27+
RUFF_VERSION = "ruff==0.14.14"
2728
BLACK_PATHS = ["docs", "google", "tests", "noxfile.py", "setup.py"]
2829

2930
DEFAULT_PYTHON_VERSION = "3.14"
@@ -72,27 +73,33 @@ def lint(session):
7273
Returns a failure if the linters find linting errors or sufficiently
7374
serious code quality issues.
7475
"""
75-
# Pin flake8 to 6.0.0
76-
# See https://github.com/googleapis/google-cloud-python/issues/1102
77-
session.install("flake8", BLACK_VERSION)
76+
session.install(FLAKE8_VERSION, RUFF_VERSION)
77+
# Check formatting
7878
session.run(
79-
"black",
79+
"ruff",
80+
"format",
8081
"--check",
81-
*BLACK_PATHS,
82+
f"--target-version=py{ALL_PYTHON[0].replace('.', '')}",
83+
"--line-length=88",
84+
*LINT_PATHS,
8285
)
86+
8387
session.run("flake8", "google", "tests")
8488

8589

8690
@nox.session(python=DEFAULT_PYTHON_VERSION)
8791
def blacken(session):
88-
"""Run black.
89-
90-
Format code to uniform standard.
91-
"""
92-
session.install(BLACK_VERSION)
92+
"""(Deprecated) Legacy session. Please use 'nox -s format'."""
93+
session.log(
94+
"WARNING: The 'blacken' session is deprecated and will be removed in a future release. Please use 'nox -s format' in the future."
95+
)
96+
session.install(RUFF_VERSION)
9397
session.run(
94-
"black",
95-
*BLACK_PATHS,
98+
"ruff",
99+
"format",
100+
f"--target-version=py{ALL_PYTHON[0].replace('.', '')}",
101+
"--line-length=88",
102+
*LINT_PATHS,
96103
)
97104

98105

@@ -449,9 +456,23 @@ def prerelease_deps(session, protobuf_implementation):
449456
@nox.session(python=DEFAULT_PYTHON_VERSION)
450457
def mypy(session):
451458
"""Run the type checker."""
452-
# TODO(https://github.com/googleapis/google-cloud-python/issues/16014):
453-
# Add mypy tests
454-
session.skip("mypy tests are not yet supported")
459+
session.skip("Mypy is not yet supported")
460+
461+
# TODO(https://github.com/googleapis/gapic-generator-python/issues/2579):
462+
# use the latest version of mypy
463+
session.install(
464+
"mypy<1.16.0",
465+
"types-requests",
466+
"types-protobuf",
467+
)
468+
session.install(".")
469+
session.run(
470+
"mypy",
471+
"-p",
472+
"google",
473+
# "--check-untyped-defs",
474+
*session.posargs,
475+
)
455476

456477

457478
@nox.session(python=DEFAULT_PYTHON_VERSION)
@@ -467,13 +488,30 @@ def core_deps_from_source(session):
467488
@nox.session
468489
def format(session: nox.sessions.Session) -> None:
469490
"""
470-
Run isort to sort imports. Then run black
471-
to format code to uniform standard.
491+
Run ruff to sort imports and format code.
472492
"""
473-
session.install(BLACK_VERSION, ISORT_VERSION)
474-
python_files = [path for path in os.listdir(".") if path.endswith(".py")]
493+
# 1. Install ruff (skipped automatically if you run with --no-venv)
494+
session.install(RUFF_VERSION)
495+
496+
# 2. Run Ruff to fix imports
497+
# check --select I: Enables strict import sorting
498+
# --fix: Applies the changes automatically
499+
session.run(
500+
"ruff",
501+
"check",
502+
"--select",
503+
"I",
504+
"--fix",
505+
f"--target-version=py{ALL_PYTHON[0].replace('.', '')}",
506+
"--line-length=88", # Standard Black line length
507+
*LINT_PATHS,
508+
)
475509

476-
# Use the --fss option to sort imports using strict alphabetical order.
477-
# See https://pycqa.github.io/isort/docs/configuration/options.html#force-sort-within-sections
478-
session.run("isort", "--fss", *python_files)
479-
session.run("black", *python_files)
510+
# 3. Run Ruff to format code
511+
session.run(
512+
"ruff",
513+
"format",
514+
f"--target-version=py{ALL_PYTHON[0].replace('.', '')}",
515+
"--line-length=88", # Standard Black line length
516+
*LINT_PATHS,
517+
)

0 commit comments

Comments
 (0)