diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 38c18b5ccf..50844cf58b 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -12,3 +12,8 @@ repos: hooks: - id: shfmt args: ["-w", "-i", "4", "-ci"] + +- repo: https://github.com/pre-commit/mirrors-yapf + rev: v0.31.0 + hooks: + - id: yapf diff --git a/.style.yapf b/.style.yapf new file mode 100644 index 0000000000..b05085101b --- /dev/null +++ b/.style.yapf @@ -0,0 +1,2 @@ +[style] +column_limit=100 diff --git a/src/make_dbg_constants.py b/src/make_dbg_constants.py index 51a9c4c3b7..3b5d7f2da6 100644 --- a/src/make_dbg_constants.py +++ b/src/make_dbg_constants.py @@ -53,11 +53,15 @@ namespace zeek::detail {\n void init_global_dbg_constants () { ''' % inputfile + def outputrecord(): global init_str, enum_str if dbginfo["names"]: - dbginfo["name_init"] = "const char * const names[] = {\n\t\t\t%s\n\t\t};\n" % ",\n\t\t\t".join(dbginfo["names"]) + dbginfo["name_init"] = "const char * const names[] = {\n"\ + "\t\t\t%s\n"\ + "\t\t};\n" \ + % ",\n\t\t\t".join(dbginfo["names"]) else: dbginfo["name_init"] = "const char * const names[] = { };\n" @@ -68,16 +72,25 @@ def outputrecord(): enum_str += "\t%s,\n" % dbginfo["cmd"] + def initdbginfo(): - return {"cmd": "", "name_init": "", "num_names": 0, "names": [], - "resume": "false", "help": "", "repeatable": "false"} + return { + "cmd": "", + "name_init": "", + "num_names": 0, + "names": [], + "resume": "false", + "help": "", + "repeatable": "false" + } + dbginfo = initdbginfo() inputf = open(inputfile, "r") for line in inputf: line = line.strip() - if not line or line.startswith("//"): # skip empty lines and comments + if not line or line.startswith("//"): # skip empty lines and comments continue fields = line.split(":", 1) @@ -95,9 +108,9 @@ for line in inputf: dbginfo[f1] = f2 elif f1 == "names": # put quotes around the strings - dbginfo[f1] = [ '"%s"' % n for n in f2.split() ] + dbginfo[f1] = ['"%s"' % n for n in f2.split()] elif f1 == "help": - dbginfo[f1] = f2.replace('"', '\\"') # escape quotation marks + dbginfo[f1] = f2.replace('"', '\\"') # escape quotation marks elif f1 in ("resume", "repeatable"): dbginfo[f1] = f2 else: diff --git a/testing/scripts/coverage-calc b/testing/scripts/coverage-calc index 016cfff5c4..0d5f2d8269 100755 --- a/testing/scripts/coverage-calc +++ b/testing/scripts/coverage-calc @@ -56,4 +56,5 @@ for k in stats: num_covered += 1 if len(stats) > 0: - print("%s/%s (%.1f%%) Zeek script statements covered." % (num_covered, len(stats), float(num_covered)/len(stats)*100)) + print("%s/%s (%.1f%%) Zeek script statements covered." % + (num_covered, len(stats), float(num_covered) / len(stats) * 100)) diff --git a/testing/scripts/httpd.py b/testing/scripts/httpd.py index 7ecfb636e9..00d7143165 100755 --- a/testing/scripts/httpd.py +++ b/testing/scripts/httpd.py @@ -2,8 +2,8 @@ import http.server as BaseHTTPServer -class MyRequestHandler(BaseHTTPServer.BaseHTTPRequestHandler): +class MyRequestHandler(BaseHTTPServer.BaseHTTPRequestHandler): def do_GET(self): self.send_response(200) self.send_header("Content-type", "text/plain") @@ -34,17 +34,21 @@ class MyRequestHandler(BaseHTTPServer.BaseHTTPRequestHandler): if __name__ == "__main__": from optparse import OptionParser p = OptionParser() - p.add_option("-a", "--addr", type="string", default="localhost", + p.add_option("-a", + "--addr", + type="string", + default="localhost", help=("listen on given address (numeric IP or host name), " "an empty string (the default) means INADDR_ANY")) - p.add_option("-p", "--port", type="int", default=32123, - help="listen on given TCP port number") - p.add_option("-m", "--max", type="int", default=-1, + p.add_option("-p", "--port", type="int", default=32123, help="listen on given TCP port number") + p.add_option("-m", + "--max", + type="int", + default=-1, help="max number of requests to respond to, -1 means no max") options, args = p.parse_args() - httpd = BaseHTTPServer.HTTPServer((options.addr, options.port), - MyRequestHandler) + httpd = BaseHTTPServer.HTTPServer((options.addr, options.port), MyRequestHandler) if options.max == -1: httpd.serve_forever() else: