diff options
author | Daniel Silverstone <dsilvers@digital-scurf.org> | 2021-11-19 19:33:02 +0000 |
---|---|---|
committer | Daniel Silverstone <dsilvers@digital-scurf.org> | 2021-11-19 20:19:00 +0000 |
commit | ae873daa84782eeddb35fa24057b7c5b3420660d (patch) | |
tree | df16f55668b5998f8c4ba5a0b68afa450753a4b9 /check | |
parent | c8c6ab1671ec3317c463d2d6330609d38b421bb2 (diff) | |
download | subplot-ae873daa84782eeddb35fa24057b7c5b3420660d.tar.gz |
check: Reimplement get_template() for polyglot documents
Signed-off-by: Daniel Silverstone <dsilvers@digital-scurf.org>
Diffstat (limited to 'check')
-rwxr-xr-x | check | 39 |
1 files changed, 25 insertions, 14 deletions
@@ -97,12 +97,12 @@ class Runcmd: def cargo(self, args, **kwargs): """Run cargo with arguments.""" - self.runcmd(["cargo"] + args, **kwargs) + return self.runcmd(["cargo"] + args, **kwargs) def cargo_maybe(self, args, **kwargs): """Run cargo if the desired subcommand is available""" if self.got_cargo(args[0]): - self.runcmd(["cargo"] + args, **kwargs) + return self.runcmd(["cargo"] + args, **kwargs) def got_cargo(self, subcommand): """Is a cargo subcommand available?""" @@ -156,6 +156,28 @@ class Runcmd: **kwargs, ) + def get_template(self, filename): + metadata = self.cargo( + [ + "run", + "--package=subplot", + "--bin=subplot", + "--", + f"--resources={os.path.abspath('share')}", + "metadata", + "-o", + "json", + filename, + ], + stdout=PIPE, + ).stdout.decode("UTF-8") + metadata = json.loads(metadata) + impls = metadata.get("impls", {}) + if not impls: + sys.exit(f"{filename} does not specify a template") + impl_names = [name for name in impls.keys()] + return impl_names[0] + def find_files(pattern, pred): """Find files recursively, if they are accepted by a predicate function""" @@ -233,7 +255,7 @@ def check_subplots(r): md = os.path.basename(md0) base, _ = os.path.splitext(md) - template = get_template(md0) + template = r.get_template(md0) if template == "python": test_py = os.path.join(output, f"test-{base}.py") test_log = os.path.join(output, f"test-{base}.log") @@ -348,17 +370,6 @@ def check_tooling(r): ) -def get_template(filename): - prefix = "template: " - with open(filename) as f: - data = f.read() - for line in data.splitlines(): - if line.startswith(prefix): - line = line[len(prefix) :] - return line - sys.exit(f"{filename} does not specify a template") - - def parse_args(): """Parse command line arguments to this script""" p = argparse.ArgumentParser() |