Sha256: ac0f82700bafad83cae61c6c8563c182b696bbae262685202179f9e3360a7dab

Contents?: true

Size: 890 Bytes

Versions: 2

Compression:

Stored size: 890 Bytes

Contents

require "open3"

module SimControl
  class PythonEnvironment < BaseEnvironment
    def initialize(script, args = {})
      @script = script
      @interpreter = args.delete(:interpreter)
      @virtualenv = args.delete(:virtualenv)
      raise "passing a virtualenv requires an interpreter" if @virtualenv and not @interpreter
    end

    def script
      @script
    end

    def args(scenario)
      scenario.args
    end

    def execute(scenario)
      stdin, stout, stderr, thread = Open3.popen3 command(scenario), chdir: basedir
      thread.join
    end

    def basedir
      File.dirname @script
    end

    def command(scenario)
      [interpreter, script, args(scenario)].reject(&:nil?).reject(&:empty?).join " "
    end

    def interpreter
      if @virtualenv
        File.join(@virtualenv, "bin", @interpreter) 
      else 
        @interpreter
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
SimControl-0.1.4 lib/SimControl/environments/python.rb
SimControl-0.1.3 lib/SimControl/environments/python.rb