<commit_before>package ducttape.cli

import collection.Set
import ducttape.workflow.Types.UnpackedWorkVert
import ducttape.workflow.RealTask
import ducttape.exec.FullTaskEnvironment
import ducttape.workflow.TaskTemplate
import ducttape.exec.DirectoryArchitect
import ducttape.workflow.HyperWorkflow
import ducttape.workflow.Realization
import ducttape.exec.PackageVersioner

object EnvironmentMode {
  
  def run(workflow: HyperWorkflow,
          plannedVertices: Set[(String,Realization)],
          packageVersions: PackageVersioner)
         (implicit opts: Opts, conf: Config, dirs: DirectoryArchitect) {
    
    if (opts.taskName == None) {
      opts.exitHelp("env requires a taskName", 1)
    }
    if (opts.realNames.size != 1) {
      opts.exitHelp("env requires one realization name", 1)
    }
    val goalTaskName = opts.taskName.get
    val goalRealName = opts.realNames.head

    // TODO: Dont' apply plan filter?
    // TODO: Apply filters so that we do much less work to get here
    val matchingTasks: Iterable[UnpackedWorkVert] = {
      workflow.unpackedWalker(plannedVertices=plannedVertices).iterator.
        filter { v: UnpackedWorkVert => v.packed.value.get.name == goalTaskName }
    }.toIterable
    System.err.println("Found %d vertices with matching task name".format(matchingTasks.size))
    
    val matchingReals: Iterable[RealTask] = {
      matchingTasks.map { v: UnpackedWorkVert => {
        val taskT: TaskTemplate = v.packed.value.get
        val task: RealTask = taskT.realize(v)
        if (task.realization.toString == goalRealName) {
          Some(task)
        } else {
          None
        }
      }}.filter(_ != None).map(_.get)
    }
    System.err.println("Found %d vertices with matching realizations".format(matchingReals.size))
    
    for (task: RealTask <- matchingReals) {
      val env = new FullTaskEnvironment(dirs, packageVersions, task)
      for ( (k,v) <- env.env) {
        println("%s=%s".format(k,v))
      }
    }
  }
}<commit_msg>Allow wildcards in environment mode<commit_after>package ducttape.cli

import collection.Set
import ducttape.workflow.Types.UnpackedWorkVert
import ducttape.workflow.RealTask
import ducttape.exec.FullTaskEnvironment
import ducttape.workflow.TaskTemplate
import ducttape.exec.DirectoryArchitect
import ducttape.workflow.HyperWorkflow
import ducttape.workflow.Realization
import ducttape.exec.PackageVersioner

object EnvironmentMode {
  
  def run(workflow: HyperWorkflow,
          plannedVertices: Set[(String,Realization)],
          packageVersions: PackageVersioner)
         (implicit opts: Opts, conf: Config, dirs: DirectoryArchitect) {
    
    if (opts.taskName == None) {
      opts.exitHelp("env requires a taskName", 1)
    }
    if (opts.realNames.size != 1) {
      opts.exitHelp("env requires one realization name", 1)
    }
    val goalTaskName = opts.taskName.get
    val goalRealName = opts.realNames.head

    // TODO: Dont' apply plan filter?
    // TODO: Apply filters so that we do much less work to get here
    val matchingTasks: Iterable[UnpackedWorkVert] = {
      workflow.unpackedWalker(plannedVertices=plannedVertices).iterator.
        filter { v: UnpackedWorkVert => goalTaskName == "*" || v.packed.value.get.name == goalTaskName }
    }.toIterable
    System.err.println("Found %d vertices with matching task name".format(matchingTasks.size))
    
    val matchingReals: Iterable[RealTask] = {
      matchingTasks.map { v: UnpackedWorkVert => {
        val taskT: TaskTemplate = v.packed.value.get
        val task: RealTask = taskT.realize(v)
        if (goalRealName == "*" || task.realization.toString == goalRealName) {
          Some(task)
        } else {
          None
        }
      }}.filter(_ != None).map(_.get)
    }
    System.err.println("Found %d vertices with matching realizations".format(matchingReals.size))
    
    for (task: RealTask <- matchingReals) {
      println(task.name + " " + task.realization + ":")
      val env = new FullTaskEnvironment(dirs, packageVersions, task)
      for ( (k,v) <- env.env) {
        println("%s=%s".format(k,v))
      }
      println()
    }
  }
}
{'fraction_non_alphanumeric': 0.1082648622522958, 'fraction_numerical': 0.0014499758337361043, 'mean_word_length': 3.147294589178357, 'pattern_counts': {'":': 1, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6954045', 'n_tokens_mistral': 1299, 'n_tokens_neox': 1240, 'n_words': 281}