Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update project #14

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .formatter.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[
inputs: ["{mix,.formatter}.exs", "{config,lib,test}/**/*.{ex,exs}"]
]
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@
erl_crash.dump
*.ez
/doc
.ruby-version
test/__pycache__/
18 changes: 12 additions & 6 deletions lib/export/helpers.ex
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,21 @@ defmodule Export.Helpers do
@moduledoc false

def convert_options(options) do
options |> Enum.map(fn (opt)->
options
|> Enum.map(fn opt ->
case opt do
{key, other_options} when other_options |> is_list ->
{key, other_options |> Enum.map(fn ({key, value}) ->
{key |> Atom.to_charlist, value |> String.to_charlist}
end)}
{key,
other_options
|> Enum.map(fn {key, value} ->
{key |> Atom.to_charlist(), value |> String.to_charlist()}
end)}

{key, value} when value |> is_bitstring ->
{key, value |> String.to_charlist}
_ -> opt
{key, value |> String.to_charlist()}

_ ->
opt
end
end)
end
Expand Down
27 changes: 19 additions & 8 deletions lib/export/python.ex
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ defmodule Export.Python do
{:ok, pid}

"""
def start(), do: :python.start()
def start, do: :python.start()

@doc """
Start Python instance with options.
Expand All @@ -51,7 +51,7 @@ defmodule Export.Python do
- python: Path to the Python interpreter executable
- python_path: The Python modules search path. The Path variable can be a string in PYTHONPATH format or a list of paths.
"""
def start(options), do: options |> convert_options |> :python.start
def start(options), do: options |> convert_options |> :python.start()

@doc """
Start Python instance with name and options.
Expand All @@ -61,23 +61,27 @@ defmodule Export.Python do
- python: Path to the Python interpreter executable
- python_path: The Python modules search path. The Path variable can be a string in PYTHONPATH format or a list of paths.
"""
def start(name, options) when not is_tuple(name), do: :python.start({:local, name}, options |> convert_options)
def start(name, options) when not is_tuple(name),
do: :python.start({:local, name}, options |> convert_options)

def start(name, options), do: :python.start(name, options |> convert_options)

@doc """
The same as start/0 except the link to the current process is also created.
"""
def start_link(), do: :python.start_link()
def start_link, do: :python.start_link()

@doc """
The same as start/1 except the link to the current process is also created.
"""
def start_link(options), do: options |> convert_options |> :python.start_link
def start_link(options), do: options |> convert_options |> :python.start_link()

@doc """
The same as start/2 except the link to the current process is also created.
"""
def start_link(name, options) when not is_tuple(name), do: :python.start_link({:local, name}, options |> convert_options)
def start_link(name, options) when not is_tuple(name),
do: :python.start_link({:local, name}, options |> convert_options)

def start_link(name, options), do: :python.start_link(name, options |> convert_options)

@doc """
Expand All @@ -100,7 +104,8 @@ defmodule Export.Python do
py |> Python.call("test", "upcase", ["hello"])
```
"""
def call(instance, file, function, arguments), do: :python.call(instance, String.to_atom(file), String.to_atom(function), arguments)
def call(instance, file, function, arguments),
do: :python.call(instance, String.to_atom(file), String.to_atom(function), arguments)

@doc """
Call Python function.
Expand All @@ -119,8 +124,14 @@ defmodule Export.Python do
defmacro call(instance, expression, from_file: file) do
{function, _meta, arguments} = expression
arguments = arguments || []

quote do
:python.call(unquote(instance), String.to_atom(unquote(file)), unquote(function), unquote(arguments))
:python.call(
unquote(instance),
String.to_atom(unquote(file)),
unquote(function),
unquote(arguments)
)
end
end
end
27 changes: 19 additions & 8 deletions lib/export/ruby.ex
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ defmodule Export.Ruby do
{:ok, pid}

"""
def start(), do: :ruby.start()
def start, do: :ruby.start()

@doc """
Start Ruby instance with options.
Expand All @@ -52,7 +52,7 @@ defmodule Export.Ruby do
- ruby_lib: The Ruby programs search path. The Path variable can be a string in RUBYLIB format or a list of paths.

"""
def start(options), do: options |> convert_options |> :ruby.start
def start(options), do: options |> convert_options |> :ruby.start()

@doc """
Start Ruby instance with name and options.
Expand All @@ -63,23 +63,27 @@ defmodule Export.Ruby do
- ruby_lib: The Ruby programs search path. The Path variable can be a string in RUBYLIB format or a list of paths.

"""
def start(name, options) when not is_tuple(name), do: :ruby.start({:local, name}, options |> convert_options)
def start(name, options) when not is_tuple(name),
do: :ruby.start({:local, name}, options |> convert_options)

def start(name, options), do: :ruby.start(name, options |> convert_options)

@doc """
The same as start/0 except the link to the current process is also created.
"""
def start_link(), do: :ruby.start_link()
def start_link, do: :ruby.start_link()

@doc """
The same as start/1 except the link to the current process is also created.
"""
def start_link(options), do: options |> convert_options |> :ruby.start_link
def start_link(options), do: options |> convert_options |> :ruby.start_link()

@doc """
The same as start/2 except the link to the current process is also created.
"""
def start_link(name, options) when not is_tuple(name), do: :ruby.start_link({:local, name}, options |> convert_options)
def start_link(name, options) when not is_tuple(name),
do: :ruby.start_link({:local, name}, options |> convert_options)

def start_link(name, options), do: :ruby.start_link(name, options |> convert_options)

@doc """
Expand All @@ -102,7 +106,8 @@ defmodule Export.Ruby do
ruby |> Ruby.call("test", "upcase", ["hello"])
```
"""
def call(instance, file, function, arguments), do: :ruby.call(instance, String.to_atom(file), String.to_atom(function), arguments)
def call(instance, file, function, arguments),
do: :ruby.call(instance, String.to_atom(file), String.to_atom(function), arguments)

@doc """
Call Ruby function.
Expand All @@ -121,8 +126,14 @@ defmodule Export.Ruby do
defmacro call(instance, expression, from_file: file) do
{function, _meta, arguments} = expression
arguments = arguments || []

quote do
:ruby.call(unquote(instance), String.to_atom(unquote(file)), unquote(function), unquote(arguments))
:ruby.call(
unquote(instance),
String.to_atom(unquote(file)),
unquote(function),
unquote(arguments)
)
end
end
end
8 changes: 4 additions & 4 deletions mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ defmodule Export.Mixfile do
package: package(),
version: "0.1.1",
elixir: "~> 1.2",
build_embedded: Mix.env == :prod,
start_permanent: Mix.env == :prod,
build_embedded: Mix.env() == :prod,
start_permanent: Mix.env() == :prod,
deps: deps(),
docs: [
main: Export,
Expand All @@ -25,7 +25,7 @@ defmodule Export.Mixfile do
links: %{
github: "https://github.com/fazibear/export"
}
]
]
end

def application() do
Expand All @@ -37,7 +37,7 @@ defmodule Export.Mixfile do
defp deps() do
[
{:erlport, "~> 0.10"},
{:ex_doc, ">= 0.0.0", only: :dev},
{:ex_doc, ">= 0.0.0", only: :dev}
]
end
end
10 changes: 7 additions & 3 deletions mix.lock
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
%{
"earmark": {:hex, :earmark, "1.0.3", "89bdbaf2aca8bbb5c97d8b3b55c5dd0cff517ecc78d417e87f1d0982e514557b", [:mix], []},
"erlport": {:hex, :erlport, "0.10.0", "2436ec2f4ed62538c6e9c52f523f9315b6002ee7e298d9bd10b35abc3f6b32e7", [:rebar3], [], "hexpm"},
"ex_doc": {:hex, :ex_doc, "0.14.5", "c0433c8117e948404d93ca69411dd575ec6be39b47802e81ca8d91017a0cf83c", [:mix], [{:earmark, "~> 1.0", [hex: :earmark, optional: false]}]},
"earmark_parser": {:hex, :earmark_parser, "1.4.15", "b29e8e729f4aa4a00436580dcc2c9c5c51890613457c193cc8525c388ccb2f06", [:mix], [], "hexpm", "044523d6438ea19c1b8ec877ec221b008661d3c27e3b848f4c879f500421ca5c"},
"erlport": {:hex, :erlport, "0.10.1", "c96ffa51bbcab0298232fcdfe8c3e110f1598011de71ae6b9082b80c9e2e476a", [:rebar3], [], "hexpm", "34931e8cb62a131d1bc8a2bd04d4007c73c03e4f10e22ee4a218e7172227a918"},
"ex_doc": {:hex, :ex_doc, "0.25.3", "3edf6a0d70a39d2eafde030b8895501b1c93692effcbd21347296c18e47618ce", [:mix], [{:earmark_parser, "~> 1.4.0", [hex: :earmark_parser, repo: "hexpm", optional: false]}, {:makeup_elixir, "~> 0.14", [hex: :makeup_elixir, repo: "hexpm", optional: false]}, {:makeup_erlang, "~> 0.1", [hex: :makeup_erlang, repo: "hexpm", optional: false]}], "hexpm", "9ebebc2169ec732a38e9e779fd0418c9189b3ca93f4a676c961be6c1527913f5"},
"makeup": {:hex, :makeup, "1.0.5", "d5a830bc42c9800ce07dd97fa94669dfb93d3bf5fcf6ea7a0c67b2e0e4a7f26c", [:mix], [{:nimble_parsec, "~> 0.5 or ~> 1.0", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "cfa158c02d3f5c0c665d0af11512fed3fba0144cf1aadee0f2ce17747fba2ca9"},
"makeup_elixir": {:hex, :makeup_elixir, "0.15.1", "b5888c880d17d1cc3e598f05cdb5b5a91b7b17ac4eaf5f297cb697663a1094dd", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}, {:nimble_parsec, "~> 1.1", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "db68c173234b07ab2a07f645a5acdc117b9f99d69ebf521821d89690ae6c6ec8"},
"makeup_erlang": {:hex, :makeup_erlang, "0.1.1", "3fcb7f09eb9d98dc4d208f49cc955a34218fc41ff6b84df7c75b3e6e533cc65f", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}], "hexpm", "174d0809e98a4ef0b3309256cbf97101c6ec01c4ab0b23e926a9e17df2077cbb"},
"nimble_parsec": {:hex, :nimble_parsec, "1.1.0", "3a6fca1550363552e54c216debb6a9e95bd8d32348938e13de5eda962c0d7f89", [:mix], [], "hexpm", "08eb32d66b706e913ff748f11694b17981c0b04a33ef470e33e11b3d3ac8f54b"},
}