Sha256: 72c77819d8a2798ed1fb71a4c6d9a550ef91c5216e8efd5ebf43c637ac9bc678

Contents?: true

Size: 1.35 KB

Versions: 15

Compression:

Stored size: 1.35 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

    ENV['PYTHONPATH'] = [ File.expand_path('../python', __FILE__), ENV['PYTHONPATH'] ].compact.join(File::PATH_SEPARATOR)

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

    begin
      major, minor, _ = RUBY_VERSION.split('.')
      require "#{major}.#{minor}/pycall.so"
    rescue LoadError
      require 'pycall.so'
    end

    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

15 entries across 15 versions & 1 rubygems

Version Path
pycall-1.3.1 lib/pycall/init.rb
pycall-1.3.0 lib/pycall/init.rb
pycall-1.3.0.dev lib/pycall/init.rb
pycall-1.2.1 lib/pycall/init.rb
pycall-1.2.0 lib/pycall/init.rb
pycall-1.2.0.beta1 lib/pycall/init.rb
pycall-1.1.0.rc1 lib/pycall/init.rb
pycall-1.0.3 lib/pycall/init.rb
pycall-1.0.2-x86-mingw32 lib/pycall/init.rb
pycall-1.0.2-x64-mingw32 lib/pycall/init.rb
pycall-1.0.2 lib/pycall/init.rb
pycall-1.0.1-x86-mingw32 lib/pycall/init.rb
pycall-1.0.1-x64-mingw32 lib/pycall/init.rb
pycall-1.0.1 lib/pycall/init.rb
pycall-1.0.0 lib/pycall/init.rb