diff options
author | Joseph Hunkeler <jhunkeler@gmail.com> | 2019-06-03 08:41:42 -0400 |
---|---|---|
committer | Joseph Hunkeler <jhunkeler@gmail.com> | 2019-06-03 08:41:52 -0400 |
commit | 8f8960e1ca30a44b00688691cc9688b0d2a14cd9 (patch) | |
tree | 68666a2f67cc0d5845bdda1fa2977dce061f28bc /source | |
parent | 13822c77b8c06bba522a40fdccd9e0c8e6f7d547 (diff) | |
download | dm-8f8960e1ca30a44b00688691cc9688b0d2a14cd9.tar.gz |
Minor improvements:
* testdir can be changed
* testdir is no longer incorporated into the delivery
* pip calls will use an index if defined
* multiarg now returns empty string if input is empty
* remove clone repos if they already exist. guarantees pristine code/tests
Diffstat (limited to 'source')
-rw-r--r-- | source/app.d | 37 | ||||
-rw-r--r-- | source/conda.d | 2 | ||||
-rw-r--r-- | source/merge.d | 14 | ||||
-rw-r--r-- | source/util.d | 4 |
4 files changed, 41 insertions, 16 deletions
diff --git a/source/app.d b/source/app.d index 3252c62..65966e4 100644 --- a/source/app.d +++ b/source/app.d @@ -14,6 +14,7 @@ import util; int main(string[] args) { string output_dir = "delivery"; + string test_dir = "testdir"; string installer_prefix = "miniconda"; string installer_variant = "3"; string installer_version = "4.5.12"; @@ -34,6 +35,7 @@ int main(string[] args) { config.passThrough, config.required, "config", "dm yaml configuration", &configfile, "output-dir|o", "store delivery-related results in dir", &output_dir, + "test-dir|t", "store test-related results in dir", &test_dir, "install-prefix|p", "path to install miniconda", &installer_prefix, "install-variant", "miniconda Python variant", &installer_variant, "install-version|i", "version of miniconda installer", &installer_version, @@ -52,6 +54,7 @@ int main(string[] args) { Session_t session = getconf(configfile); installer_prefix = buildPath(installer_prefix).absolutePath; output_dir = buildPath(output_dir, session.delivery).absolutePath; + test_dir = buildPath(test_dir).absolutePath; dumpfile_yaml = buildPath(output_dir, session.delivery ~ ".yml"); dumpfile_explicit = buildPath(output_dir, session.delivery ~ ".txt"); @@ -82,11 +85,15 @@ int main(string[] args) { return 1; } + // Assimilate environment variables from the configuration file foreach (pair; session.runtime.byPair) { conda.env[pair.key] = session.runtime[pair.key]; } + + // Place miniconda at the head of PATH. conda.initialize(); + // When reusing an environment it's best to destroy it before continuing. if (conda.env_exists(session.delivery)) { writefln("Environment '%s' already exists. Removing.", session.delivery); conda.run("env remove -n " ~ session.delivery); @@ -102,6 +109,7 @@ int main(string[] args) { output_dir.mkdirRecurse; } + // Generate deliverables conda.activate(session.delivery); writeln("Creating YAML dump: " ~ dumpfile_yaml); conda.dump_env_yaml(dumpfile_yaml); @@ -112,25 +120,38 @@ int main(string[] args) { conda.deactivate(); if (session.run_tests) { + if (!test_dir.exists) { + writeln("Creating test output directory: " ~ test_dir); + test_dir.mkdirRecurse; + } + int failures = 0; - string testdir = buildPath(output_dir, "testdir"); + + // Discover git repository data for just-installed packages testable_t[] pkgs = testable_packages(conda, session.conda_requirements, session.test_filter_git_orgs); // Allow use of environment variables in test program argument list session.test_args = interpolate(conda.env, session.test_args); + // Process each package, executing its tests foreach (i, pkg; pkgs.enumerate(0)) { - string tmpenv = format("%04d_%s", i, session.delivery); - if(conda.run("create -n " ~ tmpenv ~ " --clone " ~ session.delivery)) { - return false; + string cloned = format("%04d_%s", i, session.delivery); + if(conda.run("create -n " ~ cloned ~ " --clone " ~ session.delivery)) { + return 1; } - conda.activate(tmpenv); - failures += integration_test(session, conda, testdir, pkg); + // activate conda on the cloned environment + conda.activate(cloned); + + // count up the number of failures + failures += integration_test(session, conda, test_dir, pkg); + // deactivate conda environment conda.deactivate(); - if(conda.run("env remove -n " ~ tmpenv)) { - return false; + + // remove conda environement + if(conda.run("env remove -n " ~ cloned)) { + return 1; } } diff --git a/source/conda.d b/source/conda.d index 9fee38f..c7e7fe3 100644 --- a/source/conda.d +++ b/source/conda.d @@ -213,6 +213,8 @@ class Conda { } string multiarg(string flag, string[] arr) { + if (arr.empty) + return ""; return flag ~ " " ~ arr.join(" " ~ flag ~ " "); } diff --git a/source/merge.d b/source/merge.d index 528582c..fa625c8 100644 --- a/source/merge.d +++ b/source/merge.d @@ -176,10 +176,12 @@ int integration_test(ref Session_t session, .replace(".git", ""); outdir.mkdirRecurse; - if (!repo_root.exists) { - if (conda.sh("git clone --recursive " ~ pkg.repo ~ " " ~ repo_root)) { - return 1; - } + if (repo_root.exists) { + repo_root.rmdirRecurse; + } + + if (conda.sh("git clone --recursive " ~ pkg.repo ~ " " ~ repo_root)) { + return 1; } repo_root.chdir; @@ -206,12 +208,14 @@ int integration_test(ref Session_t session, if (!session.test_pip_requirements.empty) { if (conda.sh("python -m pip install " + ~ conda.multiarg("-i", session.pip_index) ~ " " ~ safe_install(session.test_pip_requirements))) { return 1; } } - if (conda.sh("python -m pip install -e .[test]")) { + if (conda.sh("python -m pip install " + ~ conda.multiarg("-i", session.pip_index) ~ " -e .[test]")) { return 1; } diff --git a/source/util.d b/source/util.d index 1d0abf1..3624d88 100644 --- a/source/util.d +++ b/source/util.d @@ -82,7 +82,6 @@ string safe_spec(string s) { return "'" ~ s ~ "'"; } - string safe_install(string[] specs) { string[] result; foreach (record; specs) { @@ -91,7 +90,6 @@ string safe_install(string[] specs) { return result.join(" "); } - string safe_install(string specs) { string[] result; foreach (record; specs.split(" ")) { @@ -226,7 +224,7 @@ string interpolate(string[string]aa, string str, char delim = '$') { if (pair.key != match) continue; s = s.replace(delim ~ pair.key, pair.value) - .replace(format("%c{%s}", delim, pair.key), pair.value); + .replace(format("%c{%s}", delim, pair.key), pair.value); } } |