3434FLAKE8_VERSION = "flake8==6.1.0"
3535BLACK_VERSION = "black[jupyter]==23.7.0"
3636ISORT_VERSION = "isort==5.11.0"
37+ RUFF_VERSION = "ruff==0.14.14"
3738LINT_PATHS = ["google" , "tests" , "noxfile.py" , "setup.py" ]
3839
3940DEFAULT_PYTHON_VERSION = "3.14"
@@ -655,3 +656,34 @@ def core_deps_from_source(session):
655656 # TODO(https://github.com/googleapis/google-cloud-python/issues/16014):
656657 # Add core deps from source tests
657658 session .skip ("Core deps from source tests are not yet supported" )
659+
660+ @nox .session
661+ def format (session : nox .sessions .Session ) -> None :
662+ """
663+ Run ruff to sort imports and format code.
664+ """
665+ # 1. Install ruff (skipped automatically if you run with --no-venv)
666+ session .install (RUFF_VERSION )
667+
668+ # 2. Run Ruff to fix imports
669+ # check --select I: Enables strict import sorting
670+ # --fix: Applies the changes automatically
671+ session .run (
672+ "ruff" ,
673+ "check" ,
674+ "--select" ,
675+ "I" ,
676+ "--fix" ,
677+ f"--target-version=py{ ALL_PYTHON [0 ].replace ('.' , '' )} " ,
678+ "--line-length=88" , # Standard Black line length
679+ * LINT_PATHS ,
680+ )
681+
682+ # 3. Run Ruff to format code
683+ session .run (
684+ "ruff" ,
685+ "format" ,
686+ f"--target-version=py{ ALL_PYTHON [0 ].replace ('.' , '' )} " ,
687+ "--line-length=88" , # Standard Black line length
688+ * LINT_PATHS ,
689+ )
0 commit comments