diff options
Diffstat (limited to 'source')
| -rw-r--r-- | source/app.d | 5 | ||||
| -rw-r--r-- | source/conda.d | 24 | ||||
| -rw-r--r-- | source/merge.d | 56 | 
3 files changed, 79 insertions, 6 deletions
| diff --git a/source/app.d b/source/app.d index 94f7ac8..603ff5b 100644 --- a/source/app.d +++ b/source/app.d @@ -21,12 +21,17 @@ int main(string[] args) {          return 1;      }      conda.initialize(); +    auto info = testable_packages(conda, "test.dm"); +    writeln(info); + +    /*      env_combine(conda,              "delivery",              "https://raw.githubusercontent.com/astroconda/astroconda-releases/master/hstdp/2019.3/dev/hstdp-2019.3-linux-py36.02.txt",              "test.dm");      conda.run("info");      conda.run("list"); +    */      /*      conda.activate("base"); diff --git a/source/conda.d b/source/conda.d index 90799c8..6fb7bd1 100644 --- a/source/conda.d +++ b/source/conda.d @@ -1,4 +1,6 @@  import core.cpuid : isX86_64; +import std.array; +import std.conv;  import std.file;  import std.stdio;  import std.string; @@ -59,7 +61,7 @@ class Conda {      this() {          env = getenv();          env_orig = env.dup; -        this.url_installer = join([this.url_miniconda, this.installer_file()], dirSeparator); +        this.url_installer = join([this.url_miniconda, this.installer_file()], "/");      }      void dump_env_shell() { @@ -179,7 +181,7 @@ class Conda {      void configure_headless() {          // YAML is cheap.          // Generate a .condarc inside the new prefix root -        auto fp = File(this.install_prefix ~ dirSeparator ~ ".condarc", "w+"); +        auto fp = File(chainPath(this.install_prefix, ".condarc").array, "w+");          fp.write("changeps1: False\n");          fp.write("always_yes: True\n");          fp.write("quiet: True\n"); @@ -202,7 +204,7 @@ class Conda {          }          this.env["PATH"] = join( -                [this.install_prefix ~ dirSeparator ~ "bin", +                [cast(string)chainPath(this.install_prefix, "bin").array,                  this.env["PATH"]],                  pathSeparator);          this.configure_headless(); @@ -239,4 +241,20 @@ class Conda {      string multiarg(string flag, string[] arr) {          return flag ~ " " ~ arr.join(" " ~ flag ~ " ");      } + +    string[] scan_packages(string pattern="*") { +        string[] result; +        string pkgdir = chainPath(this.install_prefix, "pkgs").array; +        if (!pkgdir.exists) { +            throw new Exception(pkgdir ~ " does not exist"); +        } + +        foreach (DirEntry e; dirEntries(pkgdir, pattern, SpanMode.shallow)) { +            if (e.isFile || e.name.endsWith(dirSeparator ~ "cache")) { +                continue; +            } +            result ~= baseName(e.name); +        } +        return result; +    }  } diff --git a/source/merge.d b/source/merge.d index 919a577..4f3caea 100644 --- a/source/merge.d +++ b/source/merge.d @@ -1,12 +1,17 @@  module merge; -import std.stdio; -import std.string; +import std.algorithm;  import std.array; +import std.conv : to; +import std.file;  import std.format;  import std.typecons; -import std.file; +import std.path; +import std.range;  import std.regex; +import std.stdio; +import std.string;  import conda; +import dyaml : dumper, Loader, Node;  auto RE_COMMENT = regex(r"[;#]"); @@ -19,6 +24,7 @@ string safe_spec(string s) {      return "'" ~ s ~ "'";  } +  string safe_install(string[] specs) {      string[] result;      foreach (record; specs) { @@ -27,6 +33,7 @@ string safe_install(string[] specs) {      return result.join(" ");  } +  string[string][] dmfile(string filename) {      string[string][] results;      foreach (line; File(filename).byLine()) { @@ -48,6 +55,7 @@ string[string][] dmfile(string filename) {      return results;  } +  bool env_combine(ref Conda conda, string name, string specfile, string mergefile) {      if (indexOf(specfile, "://", 0) < 0 && !specfile.exists) {          throw new Exception(specfile ~ " does not exist"); @@ -81,3 +89,45 @@ bool env_combine(ref Conda conda, string name, string specfile, string mergefile      }      return true;  } + + +string[string][] testable_packages(ref Conda conda, string mergefile) { +    string[string][] results; +    foreach (record; dmfile(mergefile)) { +        string[] found_packages = conda.scan_packages(record["name"] +                                                ~ "-" +                                                ~ record["version"] +                                                ~ "*"); +        string pkg = found_packages[$-1]; +        string pkg_d = chainPath(conda.install_prefix, +                                 "pkgs", +                                 pkg).array; +        string info_d = chainPath(pkg_d, "info").array; +        string recipe_d = chainPath(info_d, "recipe").array; +        string git_log = chainPath(info_d, "git").array; +        string recipe = chainPath(recipe_d, "meta.yaml").array; +        string repository; +        string head; +        string[] logdata; +        Node meta; + +        if (!git_log.exists) { +            continue; +        } + +        foreach (line; File(git_log).byLine) { +            logdata ~= line.dup; +        } + +        if (logdata.empty) { +            continue; +        } + +        head = logdata[1].split()[1]; +        meta = Loader.fromFile(recipe).load(); +        repository = meta["source"]["git_url"].as!string; + +        results ~= ["repo": repository, "commit": head]; +    } +    return results; +} | 
