diff options
author | Lars Wirzenius <liw@liw.fi> | 2021-02-13 09:04:20 +0200 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2021-02-13 12:03:52 +0200 |
commit | eef7b40a392750d9ff86280a64fb0b64f80a4b7e (patch) | |
tree | f73ba6c633153b82e66385e57d8b0983fbf4266f /subplot.py | |
parent | 3ce866aa66a97c177c67a47ba0ba339afd5373bc (diff) | |
download | subplot-eef7b40a392750d9ff86280a64fb0b64f80a4b7e.tar.gz |
feat: allow subplot.md to be used to test an installed Subplot
Diffstat (limited to 'subplot.py')
-rw-r--r-- | subplot.py | 41 |
1 files changed, 27 insertions, 14 deletions
@@ -20,23 +20,36 @@ def install_subplot(ctx): runcmd_prepend_to_path = globals()["runcmd_prepend_to_path"] srcdir = globals()["srcdir"] - # Create a "bin" directory for the wrapper. Can't put this into datadir, as - # some of Subplot's scenarios make assumptions on what files exist there. - bindir = ctx["bin-dir"] = tempfile.mkdtemp() - for prog in ["sp-codegen", "sp-docgen"]: - filename = os.path.join(bindir, prog) - with open(filename, "w") as f: - f.write(wrapper.format(prog=prog, srcdir=srcdir)) - os.chmod(filename, 0o755) - - # Add the temporary bin directory to the path, and then the source - # directory's Rust binary target directory. - runcmd_prepend_to_path(ctx, dirname=bindir) - runcmd_prepend_to_path(ctx, dirname=os.path.join(srcdir, "target", "debug")) + # If the SUBPLOT_DIR is set, we expect the Subplot binaries to be installed + # in that directory. Otherwise, we expect them to be in the source + # directory, under target/debug, which is where Rust puts them. In the + # latter case, we create a wrapper script to add the necessary options to + # also use the resources from the source tree. + + bindir = os.environ.get("SUBPLOT_DIR") + if bindir is not None: + runcmd_prepend_to_path(ctx, dirname=bindir) + else: + # Create a "bin" directory for the wrapper. Can't put this into datadir, as + # some of Subplot's scenarios make assumptions on what files exist there. + bindir = ctx["bin-dir"] = tempfile.mkdtemp() + for prog in ["sp-codegen", "sp-docgen"]: + filename = os.path.join(bindir, prog) + with open(filename, "w") as f: + f.write(wrapper.format(prog=prog, srcdir=srcdir)) + os.chmod(filename, 0o755) + + # Add the temporary bin directory to the path, and then the source + # directory's Rust binary target directory. + runcmd_prepend_to_path(ctx, dirname=bindir) + runcmd_prepend_to_path(ctx, dirname=os.path.join(srcdir, "target", "debug")) def uninstall_subplot(ctx): - shutil.rmtree(ctx["bin-dir"]) + if "bin-dir" in ctx: + bindir = ctx["bin-dir"] + if os.path.exists(bindir): + shutil.rmtree(bindir) def scenario_was_run(ctx, name=None): |