code: def checkStyle():
      """Run flake8, checking only lines that are modified since the last
      git commit."""
  
      # First check _all_ code against mandatory error codes
      print("flake8: check all code against mandatory error set...")
      errors = ",".join(FLAKE_MANDATORY)
      cmd = ["flake8", "--select=" + errors] + FLAKE_CHECK_PATHS
      proc = subprocess.Popen(cmd, stdout=subprocess.PIPE)
      # ret = proc.wait()
      output = proc.stdout.read().decode("utf-8")
      ret = proc.wait()
      printFlakeOutput(output)
  
      # Check for DOS newlines
      print("check line endings in all files...")
      count = 0
      allowedEndings = set([None, "\n"])
      for path, dirs, files in os.walk("."):
          if path.startswith("." + os.path.sep + ".tox"):
              continue
          for f in files:
              if os.path.splitext(f)[1] not in (".py", ".rst"):
                  continue
              filename = os.path.join(path, f)
              with open(filename, "U") as fh:
                  _ = fh.readlines()
                  endings = set(
                      fh.newlines
                      if isinstance(fh.newlines, tuple)
                      else (fh.newlines,)
                  )
                  endings -= allowedEndings
                  if len(endings) > 0:
                      print(
                          "\033[0;31m"
                          + "File has invalid line endings: "
                          + "%s" % filename
                          + "\033[0m"
                      )
                      ret = ret | 2
                  count += 1
      print("checked line endings in %d files" % count)
  
      # Next check new code with optional error codes
      print("flake8: check new code against recommended error set...")
      diff = subprocess.check_output(["git", "diff"])
      proc = subprocess.Popen(
          [
              "flake8",
              "--diff",  # '--show-source',
              "--ignore=" + errors,
          ],
          stdin=subprocess.PIPE,
          stdout=subprocess.PIPE,
      )
      proc.stdin.write(diff)
      proc.stdin.close()
      output = proc.stdout.read().decode("utf-8")
      ret |= printFlakeOutput(output)
  
      if ret == 0:
          print("style test passed.")
      else:
          print("style test failed: %d" % ret)
      return ret
  
imports: from contextlib import suppress
  import json
  import os
  import re
  import shutil
  import subprocess
  import sys
  from distutils import core
  from typing import Dict, Any
  from .generateChangelog import generateDebianChangelog
label_desc: Use image node_id 1 for calling a global function with example usage: checkStyle() and returns: ret