Skip to content

Commit f83a8c2

Browse files
committed
chore: updates to noxfile sessions and python versions
1 parent 165f33d commit f83a8c2

1 file changed

Lines changed: 58 additions & 10 deletions

File tree

packages/google-cloud-storage/noxfile.py

Lines changed: 58 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,25 +19,32 @@
1919

2020

2121
from __future__ import absolute_import
22+
2223
import os
2324
import pathlib
2425
import shutil
2526

2627
import nox
2728

28-
2929
BLACK_VERSION = "black==23.7.0"
30+
ISORT_VERSION = "isort==5.12.0"
3031
BLACK_PATHS = ["docs", "google", "tests", "noxfile.py", "setup.py"]
3132

3233
DEFAULT_PYTHON_VERSION = "3.14"
33-
SYSTEM_TEST_PYTHON_VERSIONS = ["3.10", "3.14"]
3434
UNIT_TEST_PYTHON_VERSIONS = [
35+
"3.8",
36+
"3.9",
3537
"3.10",
3638
"3.11",
3739
"3.12",
3840
"3.13",
3941
"3.14",
4042
]
43+
44+
ALL_PYTHON = list(UNIT_TEST_PYTHON_VERSIONS)
45+
ALL_PYTHON.extend(["3.7"])
46+
SYSTEM_TEST_PYTHON_VERSIONS = ["3.12"]
47+
4148
CONFORMANCE_TEST_PYTHON_VERSIONS = ["3.12"]
4249

4350
CURRENT_DIRECTORY = pathlib.Path(__file__).parent.absolute()
@@ -51,16 +58,18 @@
5158
"conftest_retry_bidi",
5259
"docfx",
5360
"docs",
61+
"format",
5462
"lint",
5563
"lint_setup_py",
64+
"mypy",
65+
"conftest_retry",
5666
"system",
57-
"unit-3.10",
58-
"unit-3.11",
59-
"unit-3.12",
60-
"unit-3.13",
61-
"unit-3.14",
62-
# cover must be last to avoid error `No data to report`
67+
"unit", # cover must be last to avoid error `No data to report`
6368
"cover",
69+
"docfx",
70+
"docs",
71+
"core_deps_from_source",
72+
"prerelease_deps",
6473
]
6574

6675

@@ -80,7 +89,7 @@ def lint(session):
8089
session.run("flake8", "google", "tests")
8190

8291

83-
@nox.session(python="3.14")
92+
@nox.session(python=DEFAULT_PYTHON_VERSION)
8493
def blacken(session):
8594
"""Run black.
8695
@@ -149,7 +158,7 @@ def default(session, install_extras=True):
149158
)
150159

151160

152-
@nox.session(python=UNIT_TEST_PYTHON_VERSIONS)
161+
@nox.session(python=ALL_PYTHON)
153162
def unit(session):
154163
"""Run the unit test suite."""
155164
if session.python in ("3.7",):
@@ -400,6 +409,12 @@ def docfx(session):
400409
def prerelease_deps(session, protobuf_implementation):
401410
"""Run all tests with prerelease versions of dependencies installed."""
402411

412+
# Environment check: Only run tests if the environment variable is set.
413+
if not os.environ.get("GOOGLE_APPLICATION_CREDENTIALS", ""):
414+
session.skip(
415+
"Credentials must be set via environment variable GOOGLE_APPLICATION_CREDENTIALS"
416+
)
417+
403418
# Install all test dependencies
404419
session.install("mock", "pytest", "pytest-cov", "brotli")
405420

@@ -468,3 +483,36 @@ def prerelease_deps(session, protobuf_implementation):
468483
"PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation,
469484
},
470485
)
486+
487+
488+
@nox.session(python=DEFAULT_PYTHON_VERSION)
489+
def mypy(session):
490+
"""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")
494+
495+
496+
@nox.session(python=DEFAULT_PYTHON_VERSION)
497+
def core_deps_from_source(session):
498+
"""Run all tests with core dependencies installed from source
499+
rather than pulling the dependencies from PyPI.
500+
"""
501+
# TODO(https://github.com/googleapis/google-cloud-python/issues/16014):
502+
# Add core deps from source tests
503+
session.skip("Core deps from source tests are not yet supported")
504+
505+
506+
@nox.session
507+
def format(session: nox.sessions.Session) -> None:
508+
"""
509+
Run isort to sort imports. Then run black
510+
to format code to uniform standard.
511+
"""
512+
session.install(BLACK_VERSION, ISORT_VERSION)
513+
python_files = [path for path in os.listdir(".") if path.endswith(".py")]
514+
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)

0 commit comments

Comments
 (0)