Snex.Interpreter (Snex v0.2.0)
View SourceRuns a Python interpreter in a separate OS process.
This module is responsible for facilitating in-and-out communication between Elixir and the spawned Python interpreter.
Usually you won't interact with this module directly.
Instead, you would create a custom interpreter module with use Snex.Interpreter:
defmodule SnexTest.NumpyInterpreter do
use Snex.Interpreter,
pyproject_toml: """
[project]
name = "my-numpy-project"
version = "0.0.0"
requires-python = "==3.11.*"
dependencies = ["numpy>=2"]
"""
endSee the Snex module documentation for more detail.
Summary
Functions
Returns a specification to start this module under a supervisor.
Starts a new Python interpreter.
Types
@type option() :: {:python, String.t()} | {:cd, Path.t()} | {:environment, %{optional(String.t()) => String.t()}} | {:init_script, String.t()} | {:sync_start?, boolean()} | GenServer.option()
Options for start_link/1.
@type server() :: GenServer.server()
Running instance of Snex.Interpreter.
Functions
Returns a specification to start this module under a supervisor.
See Supervisor.
@spec start_link([option()]) :: GenServer.on_start()
Starts a new Python interpreter.
The interpreter can be used by functions in the Snex module.
Options
:python- The Python executable to use. This can be a full path or a command to find viaSystem.find_executable/1.:cd- The directory to change to before running the interpreter.:environment- A map of environment variables to set when running the Python executable.:init_script- A string of Python code to run when the interpreter is started. Failing to run the script will cause the process initialization to fail. The variable context left by the script will be the initial context for allSnex.make_env/3calls using this interpreter.:sync_start?- Iftrue, the interpreter will start and run the init script in the init callback. Setting this tofalseis useful for long-running init scripts; the downside is that if something goes wrong, the interpreter process will start crashing after successfully starting as a part of the supervision tree. Default:true.- any other options will be passed to
GenServer.start_link/3.