Skip to content

Commit 618a2c3

Browse files
committed
chore: updates to noxfile sessions and python versions
1 parent e7b8dd8 commit 618a2c3

File tree

1 file changed

+58
-13
lines changed

1 file changed

+58
-13
lines changed

packages/google-cloud-storage/noxfile.py

Lines changed: 58 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,25 +15,32 @@
1515
# limitations under the License.
1616

1717
from __future__ import absolute_import
18+
1819
import os
1920
import pathlib
2021
import shutil
2122

2223
import nox
2324

24-
2525
BLACK_VERSION = "black==23.7.0"
26+
ISORT_VERSION = "isort==5.12.0"
2627
BLACK_PATHS = ["docs", "google", "tests", "noxfile.py", "setup.py"]
2728

2829
DEFAULT_PYTHON_VERSION = "3.14"
29-
SYSTEM_TEST_PYTHON_VERSIONS = ["3.10", "3.14"]
3030
UNIT_TEST_PYTHON_VERSIONS = [
31+
"3.8",
32+
"3.9",
3133
"3.10",
3234
"3.11",
3335
"3.12",
3436
"3.13",
3537
"3.14",
3638
]
39+
40+
ALL_PYTHON = list(UNIT_TEST_PYTHON_VERSIONS)
41+
ALL_PYTHON.extend(["3.7"])
42+
SYSTEM_TEST_PYTHON_VERSIONS = ["3.12"]
43+
3744
CONFORMANCE_TEST_PYTHON_VERSIONS = ["3.12"]
3845

3946
CURRENT_DIRECTORY = pathlib.Path(__file__).parent.absolute()
@@ -43,19 +50,18 @@
4350

4451
nox.options.sessions = [
4552
"blacken",
46-
"conftest_retry",
47-
"docfx",
48-
"docs",
53+
"format",
4954
"lint",
5055
"lint_setup_py",
56+
"mypy",
57+
"conftest_retry",
5158
"system",
52-
"unit-3.10",
53-
"unit-3.11",
54-
"unit-3.12",
55-
"unit-3.13",
56-
"unit-3.14",
57-
# cover must be last to avoid error `No data to report`
59+
"unit", # cover must be last to avoid error `No data to report`
5860
"cover",
61+
"docfx",
62+
"docs",
63+
"core_deps_from_source",
64+
"prerelease_deps",
5965
]
6066

6167

@@ -77,7 +83,7 @@ def lint(session):
7783
session.run("flake8", "google", "tests")
7884

7985

80-
@nox.session(python="3.14")
86+
@nox.session(python=DEFAULT_PYTHON_VERSION)
8187
def blacken(session):
8288
"""Run black.
8389
@@ -146,7 +152,7 @@ def default(session, install_extras=True):
146152
)
147153

148154

149-
@nox.session(python=UNIT_TEST_PYTHON_VERSIONS)
155+
@nox.session(python=ALL_PYTHON)
150156
def unit(session):
151157
"""Run the unit test suite."""
152158
if session.python in ("3.7",):
@@ -364,6 +370,12 @@ def docfx(session):
364370
def prerelease_deps(session, protobuf_implementation):
365371
"""Run all tests with prerelease versions of dependencies installed."""
366372

373+
# Environment check: Only run tests if the environment variable is set.
374+
if not os.environ.get("GOOGLE_APPLICATION_CREDENTIALS", ""):
375+
session.skip(
376+
"Credentials must be set via environment variable GOOGLE_APPLICATION_CREDENTIALS"
377+
)
378+
367379
# Install all test dependencies
368380
session.install("mock", "pytest", "pytest-cov", "brotli")
369381

@@ -432,3 +444,36 @@ def prerelease_deps(session, protobuf_implementation):
432444
"PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation,
433445
},
434446
)
447+
448+
449+
@nox.session(python=DEFAULT_PYTHON_VERSION)
450+
def mypy(session):
451+
"""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")
455+
456+
457+
@nox.session(python=DEFAULT_PYTHON_VERSION)
458+
def core_deps_from_source(session):
459+
"""Run all tests with core dependencies installed from source
460+
rather than pulling the dependencies from PyPI.
461+
"""
462+
# TODO(https://github.com/googleapis/google-cloud-python/issues/16014):
463+
# Add core deps from source tests
464+
session.skip("Core deps from source tests are not yet supported")
465+
466+
467+
@nox.session
468+
def format(session: nox.sessions.Session) -> None:
469+
"""
470+
Run isort to sort imports. Then run black
471+
to format code to uniform standard.
472+
"""
473+
session.install(BLACK_VERSION, ISORT_VERSION)
474+
python_files = [path for path in os.listdir(".") if path.endswith(".py")]
475+
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)

0 commit comments

Comments
 (0)