Giter Club home page Giter Club logo

export's Introduction

Export Package Version Build Status

Erlport wrapper for Elixir.

Installation

Add export to your list of dependencies in mix.exs:

def application do
  [applications: [:export]]
end

def deps do
  [
    {:export, "~> 0.1.0"},
  ]
end

Usage

Ruby

defmodule SomeRubyCall do
  use Export.Ruby

  def call_ruby_method do
    # path to ruby files
    {:ok, ruby} = Ruby.start(ruby_lib: Path.expand("lib/ruby"))

    # call "upcase" method from "test" file with "hello" argument
    ruby |> Ruby.call("test", "upcase", ["hello"])

    # same as above but prettier
    ruby |> Ruby.call(upcase("hello"), from_file: "test")
  end
end

Python

defmodule SomePythonCall do
  use Export.Python

  def call_python_method do
    # path to our python files
    {:ok, py} = Python.start(python_path: Path.expand("lib/python"))

    # call "upcase" method from "test" file with "hello" argument
    py |> Python.call("test", "upcase", ["hello"])

    # same as above but prettier
    val = py |> Python.call(upcase("hello"), from_file: "test")

    # close the Python process
    py |> Python.close()

    val
  end
end

Thank you!

Become Patreon

export's People

Contributors

bingoabs avatar fazibear avatar jeffutter avatar kicktheken avatar magicfoodhand avatar zakjholt avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

export's Issues

For those who might find it helpful. Applicable to python3 only

screenshot from 2017-05-31 00-20-23

  • If we look closely to these tables -> columns for erlang binary() to python bytes() for [python3 only] vise versa.

  • This basically means that arguments of str() data type in erlang sent over to python functions will be converted to bytes() in python3.

  • So for python functions expecting arguments of str() data type, do not forget to convert the received arguments back to python string before using.

# gist ref
decoded_args = locals()
for arg_name, arg_value in locals().items():
if isinstance(arg_value, bytes):
decoded_args[arg_name] = arg_value.decode("utf-8")

Deprecated functions

$ mix deps.compile
===> Analyzing applications...
===> Compiling erlport
==> export
Compiling 4 files (.ex)
warning: Atom.to_char_list/1 is deprecated. Use Atom.to_charlist/1 instead
  lib/export/helpers.ex:9: Export.Helpers.convert_options/1

warning: String.to_char_list/1 is deprecated. Use String.to_charlist/1 instead
Found at 2 locations:
  lib/export/helpers.ex:9: Export.Helpers.convert_options/1
  lib/export/helpers.ex:12: Export.Helpers.convert_options/1

Generated export app

Cut a new release for hex

I know there haven't been a lot of changes since 2017, but the OTP-21 support at least seems big enough to bump the version.

`require': cannot load such file -- erlport/cli (LoadError)

Trying to build this from source leads to the following errors:

jose@devbox:~/export (master *%)$ mix test
/usr/share/rubygems/rubygems/core_ext/kernel_require.rb:55:in `require': cannot load such file -- erlport/cli (LoadError)
	from /usr/share/rubygems/rubygems/core_ext/kernel_require.rb:55:in `require'
	from -e:1:in `<main>'
=ERROR REPORT==== 24-Apr-2019::14:18:50.851078 ===
** Generic server name terminating
** Last message in was {#Port<0.6>,{exit_status,1}}
** When Server state == {state,infinity,0,#Port<0.6>,
                               [{1,
                                 {{<0.177.0>,
                                   #Ref<0.1331792202.2041577475.72287>},
                                  undefined}}],
                               []}
** Reason for termination ==
** {port_closed,{code,1}}

=CRASH REPORT==== 24-Apr-2019::14:18:50.857599 ===
  crasher:
    initial call: erlport:init/1
    pid: <0.178.0>
    registered_name: name
    exception exit: {port_closed,{code,1}}
      in function  gen_server:handle_common_reply/8 (gen_server.erl, line 751)
    ancestors: [<0.177.0>]
    message_queue_len: 1
    messages: [{'EXIT',#Port<0.6>,normal}]
    links: []
    dictionary: []
    trap_exit: true
    status: running
    heap_size: 2586
    stack_size: 27
    reductions: 4571
  neighbours:



  1) test Ruby.start with name (ExportRubyTest)
     test/export_ruby_test.exs:14
     ** (ErlangError) Erlang error: {:port_closed, {:code, 1}}
     code: result = pid |> Ruby.call("test", "upcase", ["hello"])
     stacktrace:
       (erlport) /export/home/jose/export/deps/erlport/src/erlport.erl:234: :erlport.call/3
       test/export_ruby_test.exs:16: (test)

/usr/share/rubygems/rubygems/core_ext/kernel_require.rb:55:in `require': cannot load such file -- erlport/cli (LoadError)
	from /usr/share/rubygems/rubygems/core_ext/kernel_require.rb:55:in `require'
	from -e:1:in `<main>'
=ERROR REPORT==== 24-Apr-2019::14:18:50.895793 ===
** Generic server name terminating
** Last message in was {#Port<0.8>,{exit_status,1}}
** When Server state == {state,infinity,0,#Port<0.8>,
                               [{1,
                                 {{<0.179.0>,
                                   #Ref<0.1331792202.2041577473.73492>},
                                  undefined}}],
                               []}
** Reason for termination ==
** {port_closed,{code,1}}

=CRASH REPORT==== 24-Apr-2019::14:18:50.896061 ===
  crasher:
    initial call: erlport:init/1
    pid: <0.180.0>
    registered_name: []
    exception exit: {port_closed,{code,1}}
      in function  gen_server:handle_common_reply/8 (gen_server.erl, line 751)
    ancestors: [<0.179.0>]
    message_queue_len: 1
    messages: [{'EXIT',#Port<0.8>,normal}]
    links: []
    dictionary: []
    trap_exit: true
    status: running
    heap_size: 1598
    stack_size: 27
    reductions: 4485
  neighbours:



  2) test Ruby.start with global name (ExportRubyTest)
     test/export_ruby_test.exs:21
     ** (ErlangError) Erlang error: {:port_closed, {:code, 1}}
     code: result = pid |> Ruby.call("test", "upcase", ["hello"])
     stacktrace:
       (erlport) /export/home/jose/export/deps/erlport/src/erlport.erl:234: :erlport.call/3
       test/export_ruby_test.exs:23: (test)

/usr/share/rubygems/rubygems/core_ext/kernel_require.rb:55:in `require': cannot load such file -- erlport/cli (LoadError)
	from /usr/share/rubygems/rubygems/core_ext/kernel_require.rb:55:in `require'
	from -e:1:in `<main>'
=ERROR REPORT==== 24-Apr-2019::14:18:50.935981 ===
** Generic server <0.182.0> terminating
** Last message in was {#Port<0.10>,{exit_status,1}}
** When Server state == {state,infinity,0,#Port<0.10>,
                               [{1,
                                 {{<0.181.0>,
                                   #Ref<0.1331792202.2041577473.73513>},
                                  undefined}}],
                               []}
** Reason for termination ==
** {port_closed,{code,1}}

=CRASH REPORT==== 24-Apr-2019::14:18:50.936280 ===
  crasher:
    initial call: erlport:init/1
    pid: <0.182.0>
    registered_name: []
    exception exit: {port_closed,{code,1}}
      in function  gen_server:handle_common_reply/8 (gen_server.erl, line 751)
    ancestors: [<0.181.0>]
    message_queue_len: 1
    messages: [{'EXIT',#Port<0.10>,normal}]
    links: []
    dictionary: []
    trap_exit: true
    status: running
    heap_size: 1598
    stack_size: 27
    reductions: 4463
  neighbours:



  3) test Ruby.start (ExportRubyTest)
     test/export_ruby_test.exs:7
     ** (ErlangError) Erlang error: {:port_closed, {:code, 1}}
     code: result = pid |> Ruby.call("test", "upcase", ["hello"])
     stacktrace:
       (erlport) /export/home/jose/export/deps/erlport/src/erlport.erl:234: :erlport.call/3
       test/export_ruby_test.exs:9: (test)

/usr/share/rubygems/rubygems/core_ext/kernel_require.rb:55:in `require': cannot load such file -- erlport/cli (LoadError)
	from /usr/share/rubygems/rubygems/core_ext/kernel_require.rb:55:in `require'
	from -e:1:in `<main>'
=ERROR REPORT==== 24-Apr-2019::14:18:50.975822 ===
** Generic server <0.184.0> terminating
** Last message in was {#Port<0.12>,{exit_status,1}}
** When Server state == {state,infinity,0,#Port<0.12>,
                               [{1,
                                 {{<0.183.0>,
                                   #Ref<0.1331792202.2041577473.73533>},
                                  undefined}}],
                               []}
** Reason for termination ==
** {port_closed,{code,1}}

=CRASH REPORT==== 24-Apr-2019::14:18:50.976093 ===
  crasher:
    initial call: erlport:init/1
    pid: <0.184.0>
    registered_name: []
    exception exit: {port_closed,{code,1}}
      in function  gen_server:handle_common_reply/8 (gen_server.erl, line 751)
    ancestors: [<0.183.0>]
    message_queue_len: 1
    messages: [{'EXIT',#Port<0.12>,normal}]
    links: []
    dictionary: []
    trap_exit: true
    status: running
    heap_size: 1598
    stack_size: 27
    reductions: 4463
  neighbours:



  4) test Ruby.call macro (ExportRubyTest)
     test/export_ruby_test.exs:28
     ** (ErlangError) Erlang error: {:port_closed, {:code, 1}}
     code: result = pid |> Ruby.call(upcase("hello"), from_file: "test")
     stacktrace:
       (erlport) /export/home/jose/export/deps/erlport/src/erlport.erl:234: :erlport.call/3
       test/export_ruby_test.exs:30: (test)

....

Finished in 0.5 seconds
8 tests, 4 failures

Randomized with seed 743063

System Information
Centos 7 x64
Ruby: ruby 2.0.0p648 (2015-12-16) [x86_64-linux]
Python: Python 3.6.6
I installed both Ruby and Python via the terminal using yum install python ruby

It seems to be complaining about a ruby gem of some kind but it's not available in rubygems website so I have no idea what its looking for. Anyone have an idea?

Ruby.start is not working with name option

iex(8)> Ruby.start(:test, [ruby_lib: "/app/apps/mongo/priv"])
** (FunctionClauseError) no function clause matching in :gen.where/1
(stdlib) gen.erl:297: :gen.where(:andrew)
(stdlib) gen.erl:75: :gen.start/6

Elixir Version: 1.4.1 and 1.4.2
export version: 0.1.0

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.