1313# limitations under the License.
1414
1515import os
16+
1617import nox
1718
1819DEFAULT_PYTHON_VERSION = "3.14"
1920UNIT_TEST_PYTHON_VERSIONS = ["3.8" , "3.9" , "3.10" , "3.11" , "3.12" , "3.13" , "3.14" ]
21+ RUFF_VERSION = "ruff==0.14.14"
2022
2123ALL_PYTHON = list (UNIT_TEST_PYTHON_VERSIONS )
2224# ALL_PYTHON.extend(["3.7"]) # User said NOT to include 3.7
3234 "core_deps_from_source" ,
3335]
3436
37+
3538def _skip_if_37 (session ):
3639 if session .python in ("3.7" ,):
3740 session .skip ("Python 3.7 is no longer supported" )
3841
42+
3943@nox .session (python = DEFAULT_PYTHON_VERSION )
4044def mypy (session ):
4145 """Run the type checker."""
4246 # TODO(https://github.com/googleapis/google-cloud-python/issues/16014):
4347 # Add mypy tests
4448 session .skip ("mypy tests are not yet supported" )
4549
50+
4651@nox .session (python = DEFAULT_PYTHON_VERSION )
4752def core_deps_from_source (session ):
4853 """Run all tests with core dependencies installed from source
@@ -52,37 +57,70 @@ def core_deps_from_source(session):
5257 # Add core deps from source tests
5358 session .skip ("Core deps from source tests are not yet supported" )
5459
60+
5561@nox .session (python = DEFAULT_PYTHON_VERSION )
5662def prerelease_deps (session ):
57- """Run all tests with prerelease versions of dependencies installed.
58- """
63+ """Run all tests with prerelease versions of dependencies installed."""
5964 # TODO(https://github.com/googleapis/google-cloud-python/issues/16014):
6065 # Add prerelease deps tests
6166 session .skip ("prerelease deps tests are not yet supported" )
6267
63- @nox .session
64- def format (session : nox .sessions .Session ) -> None :
68+
69+ @nox .session (python = DEFAULT_PYTHON_VERSION )
70+ def format (session ):
6571 """
66- Run isort to sort imports. Then run black
67- to format code to uniform standard.
72+ Run ruff to sort imports and format code.
6873 """
6974 _skip_if_37 (session )
70- session .install ("black" , "isort" )
71- python_files = [path for path in os .listdir ("." ) if path .endswith (".py" )]
72- if not python_files :
73- pass
74-
75- # Use the --fss option to sort imports using strict alphabetical order.
76- # See https://pycqa.github.io/isort/docs/configuration/options.html#force-sort-within-sections
77- session .run ("isort" , "--fss" , * python_files )
78- session .run ("black" , * python_files )
75+
76+ # 1. Install ruff (skipped automatically if you run with --no-venv)
77+ session .install (RUFF_VERSION )
78+
79+ # 2. Run Ruff to fix imports
80+ # check --select I: Enables strict import sorting
81+ # --fix: Applies the changes automatically
82+ session .run (
83+ "ruff" ,
84+ "check" ,
85+ "--select" ,
86+ "I" ,
87+ "--fix" ,
88+ f"--target-version=py{ ALL_PYTHON [0 ].replace ('.' , '' )} " ,
89+ "--line-length=88" , # Standard Black line length
90+ "." ,
91+ )
92+
93+ # 3. Run Ruff to format code
94+ session .run (
95+ "ruff" ,
96+ "format" ,
97+ f"--target-version=py{ ALL_PYTHON [0 ].replace ('.' , '' )} " ,
98+ "--line-length=88" , # Standard Black line length
99+ "." ,
100+ )
101+
79102
80103@nox .session (python = DEFAULT_PYTHON_VERSION )
81104def lint (session ):
82- """Run linter."""
83- _skip_if_37 (session )
84- session .install ("flake8" )
85- session .run ("flake8" , "." )
105+ """Run linters.
106+
107+ Returns a failure if the linters find linting errors or sufficiently
108+ serious code quality issues.
109+ """
110+ session .install (RUFF_VERSION )
111+
112+ # 2. Check formatting
113+ session .run (
114+ "ruff" ,
115+ "format" ,
116+ "--check" ,
117+ f"--target-version=py{ ALL_PYTHON [0 ].replace ('.' , '' )} " ,
118+ "--line-length=88" ,
119+ "." ,
120+ )
121+
122+ session .run ("ruff" , "check" , "." )
123+
86124
87125@nox .session (python = DEFAULT_PYTHON_VERSION )
88126def lint_setup_py (session ):
@@ -91,6 +129,7 @@ def lint_setup_py(session):
91129 session .install ("setuptools" , "flake8" )
92130 session .run ("flake8" , "setup.py" )
93131
132+
94133@nox .session (python = UNIT_TEST_PYTHON_VERSIONS )
95134def unit (session ):
96135 """Run unit tests."""
@@ -99,6 +138,7 @@ def unit(session):
99138 session .install ("pytest" )
100139 session .run ("pytest" , "tests" )
101140
141+
102142@nox .session (python = "3.10" )
103143def docs (session ):
104144 """Build documentation."""
0 commit comments