Run yapf on all python files in the repo

Signed-off-by: Ravago Jones <ravagojones@gmail.com>
Change-Id: I221e04c3f517fab8535b22551553799e0fee7a80
diff --git a/tools/actions/generate_compile_command.py b/tools/actions/generate_compile_command.py
index b41f2fc..6f10e09 100755
--- a/tools/actions/generate_compile_command.py
+++ b/tools/actions/generate_compile_command.py
@@ -5,23 +5,26 @@
 
 import third_party.bazel.protos.extra_actions_base_pb2 as extra_actions_base_pb2
 
+
 def _get_cpp_command(cpp_compile_info):
-  compiler = cpp_compile_info.tool
-  options = ' '.join(cpp_compile_info.compiler_option)
-  source = cpp_compile_info.source_file
-  output = cpp_compile_info.output_file
-  return '%s %s -c %s -o %s' % (compiler, options, source, output), source
+    compiler = cpp_compile_info.tool
+    options = ' '.join(cpp_compile_info.compiler_option)
+    source = cpp_compile_info.source_file
+    output = cpp_compile_info.output_file
+    return '%s %s -c %s -o %s' % (compiler, options, source, output), source
+
 
 def main(argv):
-  action = extra_actions_base_pb2.ExtraActionInfo()
-  with open(argv[1], 'rb') as f:
-    action.MergeFromString(f.read())
-  command, source_file = _get_cpp_command(
-      action.Extensions[extra_actions_base_pb2.CppCompileInfo.cpp_compile_info])
-  with open(argv[2], 'w') as f:
-    f.write(command)
-    f.write('\0')
-    f.write(source_file)
+    action = extra_actions_base_pb2.ExtraActionInfo()
+    with open(argv[1], 'rb') as f:
+        action.MergeFromString(f.read())
+    command, source_file = _get_cpp_command(action.Extensions[
+        extra_actions_base_pb2.CppCompileInfo.cpp_compile_info])
+    with open(argv[2], 'w') as f:
+        f.write(command)
+        f.write('\0')
+        f.write(source_file)
+
 
 if __name__ == '__main__':
-  sys.exit(main(sys.argv))
+    sys.exit(main(sys.argv))
diff --git a/tools/actions/generate_compile_commands_json.py b/tools/actions/generate_compile_commands_json.py
index d867698..04df592 100755
--- a/tools/actions/generate_compile_commands_json.py
+++ b/tools/actions/generate_compile_commands_json.py
@@ -13,7 +13,6 @@
 import pathlib
 import os.path
 import subprocess
-
 '''
 Args:
   path: The pathlib.Path to _compile_command file.
@@ -21,18 +20,21 @@
 
 Returns a string to stick in compile_commands.json.
 '''
+
+
 def _get_command(path, command_directory):
-  with path.open('r') as f:
-    contents = f.read().split('\0')
-    if len(contents) != 2:
-      # Old/incomplete file or something; silently ignore it.
-      return None
-    return '''{
+    with path.open('r') as f:
+        contents = f.read().split('\0')
+        if len(contents) != 2:
+            # Old/incomplete file or something; silently ignore it.
+            return None
+        return '''{
         "directory": "%s",
         "command": "%s",
         "file": "%s",
       },''' % (command_directory, contents[0].replace('"', '\\"'), contents[1])
 
+
 '''
 Args:
   path: A directory pathlib.Path to look for _compile_command files under.
@@ -40,29 +42,34 @@
 
 Yields strings to stick in compile_commands.json.
 '''
+
+
 def _get_compile_commands(path, command_directory):
-  for f in path.iterdir():
-    if f.is_dir():
-      yield from _get_compile_commands(f, command_directory)
-    elif f.name.endswith('_compile_command'):
-      command = _get_command(f, command_directory)
-      if command:
-        yield command
+    for f in path.iterdir():
+        if f.is_dir():
+            yield from _get_compile_commands(f, command_directory)
+        elif f.name.endswith('_compile_command'):
+            command = _get_command(f, command_directory)
+            if command:
+                yield command
+
 
 def main(argv):
-  source_path = os.path.join(os.path.dirname(__file__), '../..')
-  action_outs = os.path.join(source_path,
-                             'bazel-bin/../extra_actions',
-                             'tools/actions/generate_compile_commands_action')
-  command_directory = subprocess.check_output(
-      ('bazel', 'info', 'execution_root'),
-      cwd=source_path).decode('utf-8').rstrip()
-  commands = _get_compile_commands(pathlib.Path(action_outs), command_directory)
-  with open(os.path.join(source_path, 'compile_commands.json'), 'w') as f:
-    f.write('[')
-    for command in commands:
-      f.write(command)
-    f.write(']')
+    source_path = os.path.join(os.path.dirname(__file__), '../..')
+    action_outs = os.path.join(
+        source_path, 'bazel-bin/../extra_actions',
+        'tools/actions/generate_compile_commands_action')
+    command_directory = subprocess.check_output(
+        ('bazel', 'info', 'execution_root'),
+        cwd=source_path).decode('utf-8').rstrip()
+    commands = _get_compile_commands(pathlib.Path(action_outs),
+                                     command_directory)
+    with open(os.path.join(source_path, 'compile_commands.json'), 'w') as f:
+        f.write('[')
+        for command in commands:
+            f.write(command)
+        f.write(']')
+
 
 if __name__ == '__main__':
-  sys.exit(main(sys.argv))
+    sys.exit(main(sys.argv))
diff --git a/tools/build_rules/apache_runner.py b/tools/build_rules/apache_runner.py
index 3839cb0..87d7224 100644
--- a/tools/build_rules/apache_runner.py
+++ b/tools/build_rules/apache_runner.py
@@ -34,6 +34,7 @@
 dummy@frc971.org
 """
 
+
 def wait_for_server(port: int):
     """Waits for the server at the specified port to respond to TCP connections."""
     while True:
@@ -46,102 +47,110 @@
             connection.close()
             time.sleep(0.01)
 
+
 def main(argv):
-  parser = argparse.ArgumentParser()
-  parser.add_argument("--binary", type=str, required=True)
-  parser.add_argument("--https_port", type=int, default=7000)
-  parser.add_argument("--wrapped_port", type=int, default=7500)
-  parser.add_argument(
-    "--ldap_info",
-    type=str,
-    help="JSON file containing 'ldap_bind_dn', 'ldap_url', and 'ldap_password' entries.",
-    default="",
-  )
-  args, unknown_args = parser.parse_known_args(argv[1:])
-
-  if not args.ldap_info:
-    args.ldap_info = os.path.join(os.environ["BUILD_WORKSPACE_DIRECTORY"], "ldap.json")
-
-  with open("tools/build_rules/apache_template.conf", "r") as file:
-    template = jinja2.Template(file.read())
-
-  with open(args.ldap_info, "r") as file:
-    substitutions = json.load(file)
-
-  for key in ("ldap_bind_dn", "ldap_url", "ldap_password"):
-    if key not in substitutions:
-      raise KeyError(f"The ldap_info JSON file must contain key '{key}'.")
-
-  substitutions.update({
-    "https_port": args.https_port,
-    "wrapped_port": args.wrapped_port,
-  })
-
-  config_text = template.render(substitutions)
-
-  with tempfile.TemporaryDirectory() as temp_dir:
-    temp_dir = Path(temp_dir)
-    with open(temp_dir / "apache2.conf", "w") as file:
-      file.write(config_text)
-
-    # Create a directory for error logs and such.
-    logs_dir = temp_dir / "logs"
-    os.mkdir(logs_dir)
-
-    print("-" * 60)
-    print(f"Logs are in {logs_dir}/")
-    print("-" * 60)
-
-    # Make modules available.
-    modules_path = Path("external/apache2/usr/lib/apache2/modules")
-    os.symlink(modules_path.resolve(), temp_dir / "modules")
-
-    # Generate a testing cert.
-    subprocess.run([
-        "openssl",
-        "req",
-        "-x509",
-        "-nodes",
-        "-days=365",
-        "-newkey=rsa:2048",
-        "-keyout=" + str(temp_dir / "apache-selfsigned.key"),
-        "-out="  + str(temp_dir / "apache-selfsigned.crt"),
-      ],
-      check=True,
-      input=DUMMY_CERT_ANSWERS,
-      text=True,
+    parser = argparse.ArgumentParser()
+    parser.add_argument("--binary", type=str, required=True)
+    parser.add_argument("--https_port", type=int, default=7000)
+    parser.add_argument("--wrapped_port", type=int, default=7500)
+    parser.add_argument(
+        "--ldap_info",
+        type=str,
+        help=
+        "JSON file containing 'ldap_bind_dn', 'ldap_url', and 'ldap_password' entries.",
+        default="",
     )
+    args, unknown_args = parser.parse_known_args(argv[1:])
 
-    # Start the wrapped binary in the background.
-    # Tell it via the environment what port to listen on.
-    env = os.environ.copy()
-    env["APACHE_WRAPPED_PORT"] = str(args.wrapped_port)
-    wrapped_binary = subprocess.Popen([args.binary] + unknown_args, env=env)
+    if not args.ldap_info:
+        args.ldap_info = os.path.join(os.environ["BUILD_WORKSPACE_DIRECTORY"],
+                                      "ldap.json")
 
-    # Start the apache server.
-    env = os.environ.copy()
-    env["LD_LIBRARY_PATH"] = "external/apache2/usr/lib/x86_64-linux-gnu"
-    apache = subprocess.Popen(
-      ["external/apache2/usr/sbin/apache2", "-X", "-d", str(temp_dir)],
-      env=env,
-    )
+    with open("tools/build_rules/apache_template.conf", "r") as file:
+        template = jinja2.Template(file.read())
 
-    wait_for_server(args.https_port)
-    wait_for_server(args.wrapped_port)
-    # Sleep to attempt to get the HTTPS message after the webserver message.
-    time.sleep(1)
-    print(f"Serving HTTPS on port {args.https_port}")
+    with open(args.ldap_info, "r") as file:
+        substitutions = json.load(file)
 
-    # Wait until we see a request to shut down.
-    signal.signal(signal.SIGINT, lambda signum, frame: None)
-    signal.signal(signal.SIGTERM, lambda signum, frame: None)
-    signal.pause()
+    for key in ("ldap_bind_dn", "ldap_url", "ldap_password"):
+        if key not in substitutions:
+            raise KeyError(
+                f"The ldap_info JSON file must contain key '{key}'.")
 
-    print("\nShutting down apache and wrapped binary.")
-    apache.terminate()
-    wrapped_binary.terminate()
-    apache.wait()
-    wrapped_binary.wait()
+    substitutions.update({
+        "https_port": args.https_port,
+        "wrapped_port": args.wrapped_port,
+    })
+
+    config_text = template.render(substitutions)
+
+    with tempfile.TemporaryDirectory() as temp_dir:
+        temp_dir = Path(temp_dir)
+        with open(temp_dir / "apache2.conf", "w") as file:
+            file.write(config_text)
+
+        # Create a directory for error logs and such.
+        logs_dir = temp_dir / "logs"
+        os.mkdir(logs_dir)
+
+        print("-" * 60)
+        print(f"Logs are in {logs_dir}/")
+        print("-" * 60)
+
+        # Make modules available.
+        modules_path = Path("external/apache2/usr/lib/apache2/modules")
+        os.symlink(modules_path.resolve(), temp_dir / "modules")
+
+        # Generate a testing cert.
+        subprocess.run(
+            [
+                "openssl",
+                "req",
+                "-x509",
+                "-nodes",
+                "-days=365",
+                "-newkey=rsa:2048",
+                "-keyout=" + str(temp_dir / "apache-selfsigned.key"),
+                "-out=" + str(temp_dir / "apache-selfsigned.crt"),
+            ],
+            check=True,
+            input=DUMMY_CERT_ANSWERS,
+            text=True,
+        )
+
+        # Start the wrapped binary in the background.
+        # Tell it via the environment what port to listen on.
+        env = os.environ.copy()
+        env["APACHE_WRAPPED_PORT"] = str(args.wrapped_port)
+        wrapped_binary = subprocess.Popen([args.binary] + unknown_args,
+                                          env=env)
+
+        # Start the apache server.
+        env = os.environ.copy()
+        env["LD_LIBRARY_PATH"] = "external/apache2/usr/lib/x86_64-linux-gnu"
+        apache = subprocess.Popen(
+            ["external/apache2/usr/sbin/apache2", "-X", "-d",
+             str(temp_dir)],
+            env=env,
+        )
+
+        wait_for_server(args.https_port)
+        wait_for_server(args.wrapped_port)
+        # Sleep to attempt to get the HTTPS message after the webserver message.
+        time.sleep(1)
+        print(f"Serving HTTPS on port {args.https_port}")
+
+        # Wait until we see a request to shut down.
+        signal.signal(signal.SIGINT, lambda signum, frame: None)
+        signal.signal(signal.SIGTERM, lambda signum, frame: None)
+        signal.pause()
+
+        print("\nShutting down apache and wrapped binary.")
+        apache.terminate()
+        wrapped_binary.terminate()
+        apache.wait()
+        wrapped_binary.wait()
+
 
 if __name__ == "__main__":
-  sys.exit(main(sys.argv))
+    sys.exit(main(sys.argv))
diff --git a/tools/build_rules/jinja2_generator.py b/tools/build_rules/jinja2_generator.py
index 34f3354..e5f6fa3 100644
--- a/tools/build_rules/jinja2_generator.py
+++ b/tools/build_rules/jinja2_generator.py
@@ -8,22 +8,26 @@
 
 
 def main():
-  # Note: this is a pretty transparent interface to jinja2--there's no reason
-  # this script couldn't be renamed and then used to generate any config from
-  # a template.
-  parser = argparse.ArgumentParser(
-      description="Generates the raspberry pi configs from a template.")
-  parser.add_argument("template", type=str, help="File to use for template.")
-  parser.add_argument("replacements", type=json.loads, help="Dictionary of parameters to replace in the template.")
-  parser.add_argument("output", type=str, help="Output file to create.")
-  args = parser.parse_args(sys.argv[1:])
+    # Note: this is a pretty transparent interface to jinja2--there's no reason
+    # this script couldn't be renamed and then used to generate any config from
+    # a template.
+    parser = argparse.ArgumentParser(
+        description="Generates the raspberry pi configs from a template.")
+    parser.add_argument("template", type=str, help="File to use for template.")
+    parser.add_argument(
+        "replacements",
+        type=json.loads,
+        help="Dictionary of parameters to replace in the template.")
+    parser.add_argument("output", type=str, help="Output file to create.")
+    args = parser.parse_args(sys.argv[1:])
 
-  with open(args.template, 'r') as input_file:
-    template = jinja2.Template(input_file.read())
+    with open(args.template, 'r') as input_file:
+        template = jinja2.Template(input_file.read())
 
-  output = template.render(args.replacements)
-  with open(args.output, 'w') as config_file:
-    config_file.write(output)
+    output = template.render(args.replacements)
+    with open(args.output, 'w') as config_file:
+        config_file.write(output)
+
 
 if __name__ == '__main__':
-  main()
+    main()
diff --git a/tools/go/mirror_go_repos.py b/tools/go/mirror_go_repos.py
index ae8f722..52d611f 100644
--- a/tools/go/mirror_go_repos.py
+++ b/tools/go/mirror_go_repos.py
@@ -20,15 +20,20 @@
 
 GO_DEPS_WWWW_DIR = "/var/www/html/files/frc971/Build-Dependencies/go_deps"
 
+
 def compute_sha256(filepath: str) -> str:
     """Computes the SHA256 of a file at the specified location."""
     with open(filepath, "rb") as file:
         contents = file.read()
     return hashlib.sha256(contents).hexdigest()
 
+
 def get_existing_mirrored_repos(ssh_host: str) -> Dict[str, str]:
     """Gathers information about the libraries that are currently mirrored."""
-    run_result = subprocess.run(["ssh", ssh_host, f"bash -c 'sha256sum {GO_DEPS_WWWW_DIR}/*'"], check=True, stdout=subprocess.PIPE)
+    run_result = subprocess.run(
+        ["ssh", ssh_host, f"bash -c 'sha256sum {GO_DEPS_WWWW_DIR}/*'"],
+        check=True,
+        stdout=subprocess.PIPE)
 
     existing_mirrored_repos = {}
     for line in run_result.stdout.decode("utf-8").splitlines():
@@ -37,10 +42,10 @@
 
     return existing_mirrored_repos
 
-def download_repos(
-        repos: Dict[str, str],
-        existing_mirrored_repos: Dict[str, str],
-        tar: tarfile.TarFile) -> Dict[str, str]:
+
+def download_repos(repos: Dict[str, str], existing_mirrored_repos: Dict[str,
+                                                                        str],
+                   tar: tarfile.TarFile) -> Dict[str, str]:
     """Downloads the not-yet-mirrored repos into a tarball."""
     cached_info = {}
 
@@ -52,7 +57,8 @@
 
         download_result = subprocess.run(
             ["external/go_sdk/bin/go", "mod", "download", "-json", module],
-            check=True, stdout=subprocess.PIPE)
+            check=True,
+            stdout=subprocess.PIPE)
         if download_result.returncode != 0:
             print("Failed to download file.")
             return 1
@@ -81,6 +87,7 @@
 
     return cached_info
 
+
 def copy_to_host_and_unpack(filename: str, ssh_host: str) -> None:
     subprocess.run(["scp", filename, f"{ssh_host}:"], check=True)
 
@@ -94,7 +101,10 @@
     ])
 
     print("You might be asked for your sudo password shortly.")
-    subprocess.run(["ssh", "-t", ssh_host, f"sudo -u www-data bash -c '{command}'"], check=True)
+    subprocess.run(
+        ["ssh", "-t", ssh_host, f"sudo -u www-data bash -c '{command}'"],
+        check=True)
+
 
 def main(argv):
     parser = argparse.ArgumentParser()
@@ -113,12 +123,15 @@
               "Build-Dependencies files live. Only specify this if you have "
               "access to the server."))
     parser.add_argument("--go_deps_bzl", type=str, default="go_deps.bzl")
-    parser.add_argument("--go_mirrors_bzl", type=str, default="tools/go/go_mirrors.bzl")
+    parser.add_argument("--go_mirrors_bzl",
+                        type=str,
+                        default="tools/go/go_mirrors.bzl")
     args = parser.parse_args(argv[1:])
 
     os.chdir(os.environ["BUILD_WORKSPACE_DIRECTORY"])
 
-    repos = org_frc971.tools.go.mirror_lib.parse_go_repositories(args.go_deps_bzl)
+    repos = org_frc971.tools.go.mirror_lib.parse_go_repositories(
+        args.go_deps_bzl)
 
     if args.ssh_host:
         existing_mirrored_repos = get_existing_mirrored_repos(args.ssh_host)
@@ -129,7 +142,8 @@
 
     if args.prune:
         # Delete all mirror info that is not needed anymore.
-        existing_cache_info = org_frc971.tools.go.mirror_lib.parse_go_mirror_info(args.go_mirrors_bzl)
+        existing_cache_info = org_frc971.tools.go.mirror_lib.parse_go_mirror_info(
+            args.go_mirrors_bzl)
         cached_info = {}
         for repo in repos:
             try:
@@ -151,10 +165,12 @@
         if args.ssh_host and num_not_already_mirrored:
             copy_to_host_and_unpack("go_deps.tar", args.ssh_host)
         else:
-            print("Skipping mirroring because of lack of --ssh_host or there's "
-                  "nothing to actually mirror.")
+            print(
+                "Skipping mirroring because of lack of --ssh_host or there's "
+                "nothing to actually mirror.")
 
-    org_frc971.tools.go.mirror_lib.write_go_mirror_info(args.go_mirrors_bzl, cached_info)
+    org_frc971.tools.go.mirror_lib.write_go_mirror_info(
+        args.go_mirrors_bzl, cached_info)
 
     return exit_code
 
diff --git a/tools/go/mirror_lib.py b/tools/go/mirror_lib.py
index ea23abc..b613ca8 100644
--- a/tools/go/mirror_lib.py
+++ b/tools/go/mirror_lib.py
@@ -13,6 +13,7 @@
     with open(filepath, "r") as file:
         return file.read()
 
+
 def parse_go_repositories(filepath: str) -> List[Dict[str, str]]:
     """Parses the top-level go_deps.bzl file.
 
@@ -53,7 +54,8 @@
     return global_data["GO_MIRROR_INFO"]
 
 
-def write_go_mirror_info(filepath: str, mirror_info: Dict[str, Dict[str, str]]):
+def write_go_mirror_info(filepath: str, mirror_info: Dict[str, Dict[str,
+                                                                    str]]):
     """Saves the specified mirror_info as GO_MIRROR_INFO into tools/go/go_mirrors.bzl."""
     with open(filepath, "w") as file:
         file.write("# This file is auto-generated. Do not edit.\n")
@@ -64,9 +66,10 @@
 
     # Properly format the file now so that the linter doesn't complain.
     r = runfiles.Create()
-    subprocess.run(
-        [
-            r.Rlocation("com_github_bazelbuild_buildtools/buildifier/buildifier_/buildifier"),
-            filepath,
-        ],
-        check=True)
+    subprocess.run([
+        r.Rlocation(
+            "com_github_bazelbuild_buildtools/buildifier/buildifier_/buildifier"
+        ),
+        filepath,
+    ],
+                   check=True)
diff --git a/tools/go/tweak_gazelle_go_deps.py b/tools/go/tweak_gazelle_go_deps.py
index d9d7901..d7f3372 100644
--- a/tools/go/tweak_gazelle_go_deps.py
+++ b/tools/go/tweak_gazelle_go_deps.py
@@ -14,22 +14,27 @@
 
 import org_frc971.tools.go.mirror_lib
 
+
 def main(argv):
     parser = argparse.ArgumentParser()
     parser.add_argument("go_deps_bzl", type=str)
     args = parser.parse_args(argv[1:])
 
-    repos = org_frc971.tools.go.mirror_lib.parse_go_repositories(args.go_deps_bzl)
+    repos = org_frc971.tools.go.mirror_lib.parse_go_repositories(
+        args.go_deps_bzl)
 
     with open(args.go_deps_bzl, "w") as file:
-        file.write(textwrap.dedent("""\
+        file.write(
+            textwrap.dedent("""\
             # This file is auto-generated. Do not edit.
             load("//tools/go:mirrored_go_deps.bzl", "maybe_override_go_dep")
 
             def go_dependencies():
             """))
         for repo in repos:
-            file.write(textwrap.indent(textwrap.dedent(f"""\
+            file.write(
+                textwrap.indent(
+                    textwrap.dedent(f"""\
                 maybe_override_go_dep(
                     name = "{repo['name']}",
                     importpath = "{repo['importpath']}",
@@ -38,5 +43,6 @@
                 )
                 """), " " * 4))
 
+
 if __name__ == "__main__":
     sys.exit(main(sys.argv))