diff options
author | Lars Wirzenius <liw@liw.fi> | 2021-05-08 11:53:55 +0300 |
---|---|---|
committer | Daniel Silverstone <dsilvers@digital-scurf.org> | 2021-05-30 16:33:07 +0100 |
commit | 15559ce624a4679fe411ea0e5eee8fa3c99cd58d (patch) | |
tree | 262825283d9a5755271a667937ae25f313e2aa3a /check | |
parent | d990af7543a865f29f413cf951b2838c72b57d46 (diff) | |
download | subplot-15559ce624a4679fe411ea0e5eee8fa3c99cd58d.tar.gz |
test(check): write subplot outputs to ./test-outputs
Put output files into ./test-outputs so they don't clutter the source
tree.
Also, tell Python to not write byte code files, by setting
PYTHONDONTWRITEBYTECODE=1 in the environment. This should prevent
src/resource.rs from triggering a rebuild after ./check, because
share/python/lib doesn't get modified by ./check anymore.
Sponsored-by: author
Diffstat (limited to 'check')
-rwxr-xr-x | check | 52 |
1 files changed, 40 insertions, 12 deletions
@@ -14,11 +14,15 @@ class Runcmd: def __init__(self, verbose, progress): self._verbose = verbose self._progress = progress + self._env = {} def _write_msg(self, msg): sys.stdout.write(f"{msg}\n") sys.stdout.flush() + def setenv(self, key, value): + self._env[key] = value + def msg(self, msg): if self._verbose: self._write_msg(msg) @@ -53,7 +57,11 @@ class Runcmd: kwargs["stdout"] = PIPE kwargs["stderr"] = STDOUT - return run(argv, **kwargs) + assert "key" not in kwargs + env = dict(os.environ) + env.update(self._env) + + return run(argv, env=env, **kwargs) def runcmd(self, argv, **kwargs): """Run a command (generic version) @@ -139,7 +147,9 @@ def check_python(r): # Find all Python files anywhere, except those we know aren't proper Python. py = find_files( - "**/*.py", lambda f: os.path.basename(f) not in ("template.py", "test.py") + "**/*.py", + lambda f: os.path.basename(f) not in ("template.py", "test.py") + and "test-outputs" not in f, ) # Test with flake8 if available. Flake8 finds Python files itself. @@ -162,7 +172,10 @@ def check_shell(r): r.title("checking shell code") # Find all shell files anywhere, except generated test programs. - sh = find_files("**/*.sh", lambda f: os.path.basename(f) != "test.sh") + sh = find_files( + "**/*.sh", + lambda f: os.path.basename(f) != "test.sh" and "test-outputs" not in f, + ) r.runcmd_maybe(["shellcheck"] + sh) @@ -185,30 +198,41 @@ def check_rust(r, strict=False): def check_subplots(r): """Run all Subplots and generate documents for them""" - mds = find_files("**/*.md", lambda f: f == f.lower() and "subplotlib" not in f) + output = os.path.abspath("test-outputs") + os.makedirs(output, exist_ok=True) + + mds = find_files( + "**/*.md", + lambda f: f == f.lower() and "subplotlib" not in f and "test-outputs" not in f, + ) for md0 in mds: r.title(f"checking subplot {md0}") dirname = os.path.dirname(md0) or "." md = os.path.basename(md0) + base, _ = os.path.splitext(md) template = 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") + # Remove test log from previous run, if any. - test_log = os.path.join(dirname, "test.log") if os.path.exists(test_log): os.remove(test_log) - r.codegen(md, "test.py", cwd=dirname) - r.runcmd(["python3", "test.py", "--log", "test.log"], cwd=dirname) + r.codegen(md, test_py, cwd=dirname) + r.runcmd(["python3", test_py, "--log", test_log], cwd=dirname) elif template == "bash": - r.codegen(md, "test.sh", cwd=dirname) - r.runcmd(["bash", "-x", "test.sh"], cwd=dirname) - os.remove(os.path.join(dirname, "test.sh")) + test_sh = os.path.join(output, f"test-{base}.sh") + r.codegen(md, test_sh, cwd=dirname) + r.runcmd(["bash", "-x", test_sh], cwd=dirname) else: sys.exit(f"unknown template {template} in {md0}") + base = os.path.basename(md) base, _ = os.path.splitext(md) + base = os.path.join(output, base) r.docgen(md, base + ".pdf", cwd=dirname) r.docgen(md, base + ".html", cwd=dirname) @@ -217,6 +241,9 @@ def check_subplotlib(r): """Run all checks for subplotlib""" r.title("checking subplotlib code") + output = os.path.abspath("test-outputs/subplotlib") + os.makedirs(output, exist_ok=True) + # Run Rust tests for the subplotlib library. r.runcmd(["cargo", "test", "--lib"], cwd="subplotlib") @@ -234,8 +261,8 @@ def check_subplotlib(r): base, _ = os.path.splitext(md) test_rs = os.path.join("tests", base + ".rs") r.codegen(md, test_rs, cwd=dirname) - r.docgen(md, base + ".html", cwd=dirname) - r.docgen(md, base + ".pdf", cwd=dirname) + r.docgen(md, os.path.join(output, base + ".html"), cwd=dirname) + r.docgen(md, os.path.join(output, base + ".pdf"), cwd=dirname) # Format the code once more to keep things clean r.title("Formatting subplotlib") @@ -301,6 +328,7 @@ def main(): args = parse_args() r = Runcmd(args.verbose, args.progress) + r.setenv("PYTHONDONTWRITEBYTECODE", "1") for what in args.what: if what == "python": |