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"
@@ -702,3 +703,34 @@ def core_deps_from_source(session):
702703 # TODO(https://github.com/googleapis/google-cloud-python/issues/16014):
703704 # Add core deps from source tests
704705 session .skip ("Core deps from source tests are not yet supported" )
706+
707+ @nox .session
708+ def format (session : nox .sessions .Session ) -> None :
709+ """
710+ Run ruff to sort imports and format code.
711+ """
712+ # 1. Install ruff (skipped automatically if you run with --no-venv)
713+ session .install (RUFF_VERSION )
714+
715+ # 2. Run Ruff to fix imports
716+ # check --select I: Enables strict import sorting
717+ # --fix: Applies the changes automatically
718+ session .run (
719+ "ruff" ,
720+ "check" ,
721+ "--select" ,
722+ "I" ,
723+ "--fix" ,
724+ f"--target-version=py{ ALL_PYTHON [0 ].replace ('.' , '' )} " ,
725+ "--line-length=88" , # Standard Black line length
726+ * LINT_PATHS ,
727+ )
728+
729+ # 3. Run Ruff to format code
730+ session .run (
731+ "ruff" ,
732+ "format" ,
733+ f"--target-version=py{ ALL_PYTHON [0 ].replace ('.' , '' )} " ,
734+ "--line-length=88" , # Standard Black line length
735+ * LINT_PATHS ,
736+ )
0 commit comments