diff options
Diffstat (limited to 'check')
-rwxr-xr-x | check | 113 |
1 files changed, 77 insertions, 36 deletions
@@ -13,9 +13,10 @@ from subprocess import PIPE, DEVNULL, STDOUT class Runcmd: """Run external commands in various ways""" - def __init__(self, verbose, progress): + def __init__(self, verbose, progress, offline): self._verbose = verbose self._progress = progress + self.offline = offline # Deliberately chosen because it's 12:45 / 13:45 offset from UTC # As such it ought to show any TZ related errors if we're lucky. self._env = {"TZ": "NZ-CHAT"} @@ -94,11 +95,6 @@ class Runcmd: p = self.runcmd_unchecked(["which", name], stdout=DEVNULL) return p.returncode == 0 - def pandoc_is_newer(self): - """Is pandoc new enough for --citeproc""" - p = self.runcmd(["pandoc", "--help"], stdout=PIPE) - return "--citeproc" in p.stdout.decode("UTF-8") - def cargo(self, args, **kwargs): """Run cargo with arguments.""" return self.runcmd(["cargo"] + args, **kwargs) @@ -166,21 +162,38 @@ class Runcmd: **kwargs, ) - def get_templates(self, filename): - metadata = self.cargo( + def libdocgen(self, bindings, output): + self.cargo( [ "run", - "--quiet", "--package=subplot", "--bin=subplot", "--", f"--resources={os.path.abspath('share')}", - "metadata", - "-o", - "json", - "--merciful", - filename, - ], + "libdocgen", + "--output", + output, + bindings, + ] + ) + + def get_templates(self, filename, strict): + args = [ + "run", + "--quiet", + "--package=subplot", + "--bin=subplot", + "--", + f"--resources={os.path.abspath('share')}", + "metadata", + "-o", + "json", + ] + if not strict: + args += ["--merciful"] + args += [filename] + metadata = self.cargo( + args, stdout=PIPE, stderr=PIPE, ).stdout.decode("UTF-8") @@ -236,13 +249,16 @@ def check_shell(r): r.runcmd_maybe(["shellcheck"] + sh) -def check_rust(r, strict=False): +def check_rust(r, strict=False, sloppy=False): """Run all checks for Rust code""" r.title("checking Rust code") - r.runcmd(["cargo", "build", "--workspace", "--all-targets"]) + argv = ["cargo", "build", "--workspace", "--all-targets"] + if r.offline: + argv.append("--offline") + r.runcmd(argv) - if r.got_cargo("clippy"): + if r.got_cargo("clippy") and not sloppy: argv = [ "cargo", "clippy", @@ -259,10 +275,11 @@ def check_rust(r, strict=False): sys.exit("Strict Rust checks specified, but clippy was not found") r.runcmd(["cargo", "test", "--workspace"]) - r.runcmd(["cargo", "fmt", "--", "--check"]) + if not sloppy: + r.runcmd(["cargo", "fmt", "--", "--check"]) -def check_subplots(r): +def check_subplots(r, strict=False): """Run all Subplots and generate documents for them""" output = os.path.abspath("test-outputs") os.makedirs(output, exist_ok=True) @@ -271,6 +288,9 @@ def check_subplots(r): "**/*.subplot", lambda f: f == f.lower() and "subplotlib" not in f and "test-outputs" not in f, ) + if r.offline: + r.msg("Only testing subplot.subplot due to --offline") + subplots = ["subplot.subplot"] for subplot0 in subplots: r.title(f"checking subplot {subplot0}") @@ -280,7 +300,7 @@ def check_subplots(r): doc_template = None - for template in r.get_templates(subplot0): + for template in r.get_templates(subplot0, strict): if doc_template is None: doc_template = template if template == "python": @@ -320,8 +340,9 @@ def check_subplots(r): base = os.path.basename(subplot) base, _ = os.path.splitext(subplot) base = os.path.join(output, base) - r.docgen(subplot, doc_template, base + ".pdf", cwd=dirname) - r.docgen(subplot, doc_template, base + ".html", cwd=dirname) + html = base + ".html" + r.docgen(subplot, doc_template, html, cwd=dirname) + r.runcmd(["tidy", "-errors", html], cwd=dirname) def tail(filename, numlines=100): @@ -342,21 +363,13 @@ def check_tooling(r): "bash", "cargo", "dot", - "pandoc", - "pandoc-citeproc", - "pdflatex", "plantuml", "rustc", "rustfmt", + "tidy", ] for command in commands: if not r.got_command(command): - if command == "pandoc-citeproc": - if r.pandoc_is_newer(): - r.msg( - " Fortunately pandoc is new enough for --citeproc, no need for pandoc-citeproc" - ) - continue sys.exit(f"can't find {command}, which is needed for test suite") if not r.got_command("daemonize") and not r.got_command("/usr/sbin/daemonize"): @@ -365,6 +378,26 @@ def check_tooling(r): ) +def check_doc(r): + docs = os.path.join("test-outputs", "libdocs") + if not os.path.exists(docs): + os.mkdir(docs) + + bindings = [] + for dirname, _, basenames in os.walk("share"): + dirname = dirname[len("share/") :] + bindings += [ + os.path.join(dirname, x) + for x in basenames + if x != "template.yaml" and x.endswith(".yaml") + ] + + for filename in bindings: + md = os.path.splitext(os.path.basename(filename))[0] + ".md" + md = os.path.join(docs, md) + r.libdocgen(filename, md) + + def parse_args(): """Parse command line arguments to this script""" p = argparse.ArgumentParser() @@ -375,8 +408,14 @@ def parse_args(): p.add_argument( "--strict", action="store_true", help="don't allow compiler warnings" ) + p.add_argument( + "--sloppy", action="store_true", help="don't check formatting or with clippy" + ) + p.add_argument( + "--offline", action="store_true", help="only run tests that can be run offline" + ) - all_whats = ["tooling", "python", "shell", "rust", "subplots"] + all_whats = ["tooling", "python", "shell", "rust", "subplots", "doc"] p.add_argument( "what", nargs="*", default=all_whats, help=f"what to test: {all_whats}" ) @@ -397,7 +436,7 @@ def main(): """Main program""" args = parse_args() - r = Runcmd(args.verbose, args.progress) + r = Runcmd(args.verbose, args.progress, args.offline) r.setenv("PYTHONDONTWRITEBYTECODE", "1") for what in args.what: @@ -406,11 +445,13 @@ def main(): elif what == "shell": check_shell(r) elif what == "rust": - check_rust(r, strict=args.strict) + check_rust(r, strict=args.strict, sloppy=args.sloppy) elif what == "subplots": - check_subplots(r) + check_subplots(r, strict=args.strict) elif what == "tooling": check_tooling(r) + elif what == "doc": + check_doc(r) else: sys.exit(f"Unknown test {what}") |