1
0
Fork 0
mirror of https://framagit.org/framasoft/mobilizon.git synced 2024-12-28 02:40:22 +00:00
mobilizon/lib/service/python_port.ex
Thomas Citharel ea276fbe73
Detect if Python3 is installed before launching PythonPort Genserver
Signed-off-by: Thomas Citharel <tcit@tcit.fr>
2021-11-09 09:15:31 +01:00

44 lines
985 B
Elixir

defmodule Mobilizon.PythonPort do
@moduledoc """
Port to use Python modules from Elixir
"""
use Export.Python
@python_path "/usr/bin/python3"
@doc """
Whether Python3 is installed
"""
@spec python_exists? :: boolean
def python_exists? do
File.exists?(python_path())
end
@doc """
## Parameters
- path: directory to include in python path
"""
@spec python_instance(String.t()) :: pid
def python_instance(path) do
{:ok, pid} = Python.start(python: python_path(), python_path: path)
pid
end
@doc """
Call python function using MFA format
"""
@spec call_python(pid, binary, binary, list) :: any
def call_python(pid, module, function, arguments \\ []) do
Python.call(pid, module, function, arguments)
end
@spec python_path :: String.t()
defp python_path do
case get_in(Application.get_env(:mobilizon, __MODULE__), [:path]) do
path when is_binary(path) -> path
nil -> @python_path
end
end
end