@@ -12,47 +12,6 @@ defmodule Pythonx do
1212
1313 @ type encoder :: ( term ( ) , encoder ( ) -> Object . t ( ) )
1414
15- @ doc """
16- Initializes the Python interpreter.
17-
18- > #### Reproducability {: .info}
19- >
20- > This function can be called to use a custom Python installation,
21- > however in most cases it is more convenient to call `uv_init/2`,
22- > which installs Python and dependencies, and then automatically
23- > initializes the interpreter using the correct paths.
24-
25- The `python_dl_path` argument is the Python dynamically linked
26- library file. The usual file name is `libpython3.x.so` (Linux),
27- `libpython3.x.dylib` (macOS), `python3x.dll` (Windows).
28-
29- The `python_home_path` is the Python home directory, where the Python
30- built-in modules reside. Specifically, the modules should be located
31- in `{python_home_path}/lib/pythonx.y` (Linux and macOS) or
32- `{python_home_path}/Lib` (Windows).
33-
34- ## Options
35-
36- * `:sys_paths` - directories to be added to the module search path
37- (`sys.path`). Defaults to `[]`.
38-
39- """
40- @ spec init ( String . t ( ) , String . t ( ) , keyword ( ) ) :: :ok
41- def init ( python_dl_path , python_home_path , opts \\ [ ] )
42- when is_binary ( python_dl_path ) and is_binary ( python_home_path ) and is_list ( opts ) do
43- opts = Keyword . validate! ( opts , sys_paths: [ ] )
44-
45- if not File . exists? ( python_dl_path ) do
46- raise ArgumentError , "the given dynamic library file does not exist: #{ python_dl_path } "
47- end
48-
49- if not File . dir? ( python_home_path ) do
50- raise ArgumentError , "the given python home directory does not exist: #{ python_home_path } "
51- end
52-
53- Pythonx.NIF . init ( python_dl_path , python_home_path , opts [ :sys_paths ] )
54- end
55-
5615 @ doc ~S'''
5716 Installs Python and dependencies using [uv](https://docs.astral.sh/uv)
5817 package manager and initializes the interpreter.
@@ -99,6 +58,53 @@ defmodule Pythonx do
9958 Pythonx.Uv . init ( pyproject_toml , false )
10059 end
10160
61+ # Initializes the Python interpreter.
62+ #
63+ # > #### Reproducability {: .info}
64+ # >
65+ # > This function can be called to use a custom Python installation,
66+ # > however in most cases it is more convenient to call `uv_init/2`,
67+ # > which installs Python and dependencies, and then automatically
68+ # > initializes the interpreter using the correct paths.
69+ #
70+ # `python_dl_path` is the Python dynamically linked library file.
71+ # The usual file name is `libpython3.x.so` (Linux), `libpython3.x.dylib`
72+ # (macOS), `python3x.dll` (Windows).
73+ #
74+ # `python_home_path` is the Python home directory, where the Python
75+ # built-in modules reside. Specifically, the modules should be
76+ # located in `{python_home_path}/lib/pythonx.y` (Linux and macOS)
77+ # or `{python_home_path}/Lib` (Windows).
78+ #
79+ # `python_executable_path` is the Python executable file.
80+ #
81+ # ## Options
82+ #
83+ # * `:sys_paths` - directories to be added to the module search path
84+ # (`sys.path`). Defaults to `[]`.
85+ #
86+ @ doc false
87+ @ spec init ( String . t ( ) , String . t ( ) , keyword ( ) ) :: :ok
88+ def init ( python_dl_path , python_home_path , python_executable_path , opts \\ [ ] )
89+ when is_binary ( python_dl_path ) and is_binary ( python_home_path )
90+ when is_binary ( python_executable_path ) and is_list ( opts ) do
91+ opts = Keyword . validate! ( opts , sys_paths: [ ] )
92+
93+ if not File . exists? ( python_dl_path ) do
94+ raise ArgumentError , "the given dynamic library file does not exist: #{ python_dl_path } "
95+ end
96+
97+ if not File . dir? ( python_home_path ) do
98+ raise ArgumentError , "the given python home directory does not exist: #{ python_home_path } "
99+ end
100+
101+ if not File . exists? ( python_home_path ) do
102+ raise ArgumentError , "the given python executable does not exist: #{ python_executable_path } "
103+ end
104+
105+ Pythonx.NIF . init ( python_dl_path , python_home_path , python_executable_path , opts [ :sys_paths ] )
106+ end
107+
102108 @ doc ~S'''
103109 Evaluates the Python `code`.
104110
0 commit comments