Sha256: 12c0c50406631f4f7833b83a1b6778a234b4876236ea033c1ab6e303525cf2ce

Contents?: true

Size: 822 Bytes

Versions: 18

Compression:

Stored size: 822 Bytes

Contents

# frozen_string_literal: true

require_relative '../../protocol'

# Binding for python language, allow specifying imports and paths
class Python
  # @implements LanguageImpl
  def initialize(libs: [], paths: [], runner: 'python')
    common_aliases = {
      pandas: :pd,
      numpy: :np
    }.freeze

    libs = libs.map(&:to_s) # convert all to strings
    @imports = libs.map { |lib| "import #{lib}" }
    common_aliases.each do |name, short|
      @imports.push("import #{name} as #{short}") if libs.include? name.to_s
    end
    @paths = ['import sys'] + paths.map { |path| "sys.path.append('#{path}')" }
    @runner = runner
  end

  def build(code, _task)
    (@paths + @imports + [code]).join "\n"
  end

  def run_script(env, fname, _task)
    run_cmd(env, "#{@runner} #{fname}")
  end
end

creator :py, Python

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
raka-0.3.18 lib/raka/lang/python/impl.rb
raka-0.3.17 lib/raka/lang/python/impl.rb
raka-0.3.16 lib/raka/lang/python/impl.rb
raka-0.3.15 lib/raka/lang/python/impl.rb
raka-0.3.14 lib/raka/lang/python/impl.rb
raka-0.3.13 lib/raka/lang/python/impl.rb
raka-0.3.12 lib/raka/lang/python/impl.rb
raka-0.3.11 lib/raka/lang/python/impl.rb
raka-0.3.10 lib/raka/lang/python/impl.rb
raka-0.3.9 lib/raka/lang/python/impl.rb
raka-0.3.8 lib/raka/lang/python/impl.rb
raka-0.3.7 lib/raka/lang/python/impl.rb
raka-0.3.6 lib/raka/lang/python/impl.rb
raka-0.3.4 lib/raka/lang/python/impl.rb
raka-0.3.3 lib/lang/python/impl.rb
raka-0.3.2 lib/lang/python/impl.rb
raka-0.3.1 lib/lang/python/impl.rb
raka-0.2.3 lib/lang/python/impl.rb