Skip to content

Commit

Permalink
Up
Browse files Browse the repository at this point in the history
  • Loading branch information
jonatanklosko committed Feb 21, 2025
1 parent da1a394 commit c573339
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 10 deletions.
16 changes: 8 additions & 8 deletions c_src/pythonx/pythonx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ fine::Ok<> init(ErlNifEnv *env, std::string python_dl_path,
// containing the built-in Python modules [1].
//
// [1]: https://docs.python.org/3/using/cmdline.html#envvar-PYTHONHOME
// Py_SetPythonHome(python_home_path_w.c_str());
Py_SetPythonHome(python_home_path_w.c_str());
Py_SetProgramName(python_executable_path_w.c_str());

Py_InitializeEx(0);
Expand Down Expand Up @@ -299,14 +299,14 @@ fine::Ok<> init(ErlNifEnv *env, std::string python_dl_path,
raise_if_failed(env, py_sys_path);
auto py_sys_path_guard = PyDecRefGuard(py_sys_path);

// for (const auto &path : sys_paths) {
// auto py_path = PyUnicode_FromStringAndSize(
// reinterpret_cast<const char *>(path.data), path.size);
// raise_if_failed(env, py_path);
// auto py_path_guard = PyDecRefGuard(py_path);
for (const auto &path : sys_paths) {
auto py_path = PyUnicode_FromStringAndSize(
reinterpret_cast<const char *>(path.data), path.size);
raise_if_failed(env, py_path);
auto py_path_guard = PyDecRefGuard(py_path);

// raise_if_failed(env, PyList_Append(py_sys_path, py_path));
// }
raise_if_failed(env, PyList_Append(py_sys_path, py_path));
}

// Define global stdout and stdin overrides

Expand Down
7 changes: 6 additions & 1 deletion lib/pythonx.ex
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ defmodule Pythonx do
"""
@spec init(String.t(), String.t(), keyword()) :: :ok
def init(python_dl_path, python_home_path, python_executable_path, opts \\ [])
when is_binary(python_dl_path) and is_binary(python_home_path) and is_list(opts) do
when is_binary(python_dl_path) and is_binary(python_home_path)
when is_binary(python_executable_path) and is_list(opts) do
opts = Keyword.validate!(opts, sys_paths: [])

if not File.exists?(python_dl_path) do
Expand All @@ -50,6 +51,10 @@ defmodule Pythonx do
raise ArgumentError, "the given python home directory does not exist: #{python_home_path}"
end

if not File.exists?(python_home_path) do
raise ArgumentError, "the given python executable does not exist: #{python_executable_path}"
end

Pythonx.NIF.init(python_dl_path, python_home_path, python_executable_path, opts[:sys_paths])
end

Expand Down
5 changes: 4 additions & 1 deletion lib/pythonx/uv.ex
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,10 @@ defmodule Pythonx.Uv do

python_home_path = make_windows_slashes(root_dir)

python_executable_path = Path.join(abs_executable_dir, "python.exe")
python_executable_path =
abs_executable_dir
|> Path.join("python.exe")
|> make_windows_slashes()

venv_packages_path =
project_dir
Expand Down

0 comments on commit c573339

Please sign in to comment.