@@ -17,7 +17,7 @@ defmodule Pythonx do
1717
1818 alias Pythonx.Object
1919
20- @ type python_config :: % __MODULE__ {
20+ @ type init_state :: % __MODULE__ {
2121 python_dl_path: String . t ( ) ,
2222 python_home_path: String . t ( ) ,
2323 python_executable_path: String . t ( ) ,
@@ -71,7 +71,41 @@ defmodule Pythonx do
7171 opts = Keyword . validate! ( opts , force: false , uv_version: Pythonx.Uv . default_uv_version ( ) )
7272
7373 Pythonx.Uv . fetch ( pyproject_toml , false , opts )
74- Pythonx.Uv . init ( pyproject_toml , false , Keyword . take ( opts , [ :uv_version ] ) )
74+ init_state = Pythonx.Uv . init ( pyproject_toml , false , Keyword . take ( opts , [ :uv_version ] ) )
75+ :persistent_term . put ( :pythonx_init_state , init_state )
76+ end
77+
78+ @ spec init_state ( ) :: init_state ( )
79+ defp init_state ( ) do
80+ :persistent_term . get ( :pythonx_init_state )
81+ end
82+
83+ @ doc ~s'''
84+ Returns a map containing the environment variables required to initialize Pythonx.
85+ '''
86+ @ spec flame_env ( ) :: map ( )
87+ def flame_env ( ) do
88+ init_state =
89+ init_state ( )
90+ |> :erlang . term_to_binary ( )
91+ |> Base . encode64 ( )
92+
93+ % { name: "PYTHONX_FLAME_INIT_STATE" , value: init_state }
94+ end
95+
96+ @ doc ~s'''
97+ Returns a list of paths to copy to the flame runner.
98+ '''
99+ @ spec flame_paths_to_copy ( ) :: list ( String . t ( ) )
100+ def flame_paths_to_copy ( ) do
101+ init_state = init_state ( )
102+
103+ [
104+ init_state . python_dl_path ,
105+ init_state . python_home_path ,
106+ init_state . python_executable_path ,
107+ init_state . sys_paths
108+ ]
75109 end
76110
77111 # Initializes the Python interpreter.
@@ -124,7 +158,7 @@ defmodule Pythonx do
124158 Pythonx.NIF . init ( python_dl_path , python_home_path , python_executable_path , opts [ :sys_paths ] )
125159 end
126160
127- @ spec init ( python_config ( ) ) :: :ok
161+ @ spec init ( init_state ( ) ) :: :ok
128162 def init ( % __MODULE__ {
129163 python_dl_path: python_dl_path ,
130164 python_home_path: python_home_path ,
0 commit comments