diff --git a/.formatter.exs b/.formatter.exs new file mode 100644 index 0000000..d304ff3 --- /dev/null +++ b/.formatter.exs @@ -0,0 +1,3 @@ +[ + inputs: ["{mix,.formatter}.exs", "{config,lib,test}/**/*.{ex,exs}"] +] diff --git a/.gitignore b/.gitignore index 0ff0618..32f323a 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,5 @@ erl_crash.dump *.ez /doc +.ruby-version +test/__pycache__/ \ No newline at end of file diff --git a/lib/export/helpers.ex b/lib/export/helpers.ex index 657f144..536b798 100644 --- a/lib/export/helpers.ex +++ b/lib/export/helpers.ex @@ -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 diff --git a/lib/export/python.ex b/lib/export/python.ex index 8c9507c..545d395 100644 --- a/lib/export/python.ex +++ b/lib/export/python.ex @@ -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. @@ -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. @@ -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 """ @@ -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. @@ -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 diff --git a/lib/export/ruby.ex b/lib/export/ruby.ex index 12faab5..97085aa 100644 --- a/lib/export/ruby.ex +++ b/lib/export/ruby.ex @@ -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. @@ -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. @@ -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 """ @@ -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. @@ -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 diff --git a/mix.exs b/mix.exs index 42a7f64..ccb8bc1 100644 --- a/mix.exs +++ b/mix.exs @@ -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, @@ -25,7 +25,7 @@ defmodule Export.Mixfile do links: %{ github: "https://github.com/fazibear/export" } - ] + ] end def application() do @@ -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 diff --git a/mix.lock b/mix.lock index ac51ac3..d57f922 100644 --- a/mix.lock +++ b/mix.lock @@ -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"}, }