# Licensed to the Software Freedom Conservancy (SFC) under one1# or more contributor license agreements. See the NOTICE file2# distributed with this work for additional information3# regarding copyright ownership. The SFC licenses this file4# to you under the Apache License, Version 2.0 (the5# "License"); you may not use this file except in compliance6# with the License. You may obtain a copy of the License at7#8# http://www.apache.org/licenses/LICENSE-2.09#10# Unless required by applicable law or agreed to in writing,11# software distributed under the License is distributed on an12# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY13# KIND, either express or implied. See the License for the14# specific language governing permissions and limitations15# under the License.1617"""Run ruff format on Python files across the project.1819Usage:20bazel run //py:ruff-format -- [ruff format args]21"""2223import os24import subprocess25import sys2627from python.runfiles import Runfiles2829ALL_DIRS = ["py", "scripts", "common", "dotnet", "java", "javascript", "rb"]30EXCLUDES = ["**/node_modules/**", "**/.bundle/**", "**/devtools/**"]313233def run_format(ruff, exclude_args, dirs, extra_args):34"""Run ruff format."""35cmd = [ruff, "format", "--config=py/pyproject.toml"]36return subprocess.run(cmd + exclude_args + dirs + extra_args).returncode373839if __name__ == "__main__":40r = Runfiles.Create()41ruff = r.Rlocation("rules_multitool++multitool+multitool/tools/ruff/ruff")4243os.chdir(os.environ["BUILD_WORKSPACE_DIRECTORY"])4445exclude_args = []46for pattern in EXCLUDES:47exclude_args.extend(["--exclude", pattern])4849sys.exit(run_format(ruff, exclude_args, ALL_DIRS, sys.argv[1:]))505152