Sha256: 61b920a1a35f4e25c862f9c19116aeb8d4bb36a4b4002eaad8e9054ed55e6471

Contents?: true

Size: 1.16 KB

Versions: 5

Compression:

Stored size: 1.16 KB

Contents

module PyCall
  def self.const_missing(name)
    case name
    when :PyPtr, :PyTypePtr, :PyObjectWrapper, :PYTHON_DESCRIPTION, :PYTHON_VERSION
      PyCall.init
      const_get(name)
    else
      super
    end
  end

  module LibPython
    def self.const_missing(name)
      case name
      when :API, :Conversion, :Helpers, :PYTHON_DESCRIPTION, :PYTHON_VERSION
        PyCall.init
        const_get(name)
      else
        super
      end
    end
  end

  def self.init(python = ENV['PYTHON'])
    return false if LibPython.instance_variable_defined?(:@handle)
    class << PyCall
      remove_method :const_missing
    end
    class << PyCall::LibPython
      remove_method :const_missing
    end

    LibPython.instance_variable_set(:@handle, LibPython::Finder.find_libpython(python))
    class << LibPython
      undef_method :handle
      attr_reader :handle
    end

    require 'pycall.so'

    PyCall.sys.path.append(File.expand_path('../python', __FILE__))

    require 'pycall/dict'
    require 'pycall/list'
    require 'pycall/slice'
    const_set(:PYTHON_VERSION, LibPython::PYTHON_VERSION)
    const_set(:PYTHON_DESCRIPTION, LibPython::PYTHON_DESCRIPTION)
    true
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
pycall-1.5.1 lib/pycall/init.rb
pycall-1.5.0 lib/pycall/init.rb
pycall-1.4.2 lib/pycall/init.rb
pycall-1.4.1 lib/pycall/init.rb
pycall-1.4.0 lib/pycall/init.rb