mirror of
https://github.com/OrcaSlicer/OrcaSlicer.git
synced 2026-09-01 06:16:58 +00:00
Merge branch 'feat/plugin-feature' into feature/speed-dial
This commit is contained in:
@@ -30,6 +30,19 @@ if (WIN32)
|
|||||||
COMMENT "Copying Python runtime for slic3rutils plugin host API tests"
|
COMMENT "Copying Python runtime for slic3rutils plugin host API tests"
|
||||||
VERBATIM
|
VERBATIM
|
||||||
)
|
)
|
||||||
|
elseif (APPLE)
|
||||||
|
target_link_options(${_TEST_NAME}_tests PRIVATE
|
||||||
|
"LINKER:-rpath,@executable_path/python/lib")
|
||||||
|
|
||||||
|
add_custom_command(TARGET ${_TEST_NAME}_tests POST_BUILD
|
||||||
|
COMMAND ${CMAKE_COMMAND} -E rm -rf
|
||||||
|
"$<TARGET_FILE_DIR:${_TEST_NAME}_tests>/python"
|
||||||
|
COMMAND ${CMAKE_COMMAND} -E copy_directory
|
||||||
|
"${CMAKE_PREFIX_PATH}/libpython"
|
||||||
|
"$<TARGET_FILE_DIR:${_TEST_NAME}_tests>/python"
|
||||||
|
COMMENT "Copying Python runtime for macOS plugin host API tests"
|
||||||
|
VERBATIM
|
||||||
|
)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
orcaslicer_discover_tests(${_TEST_NAME}_tests)
|
orcaslicer_discover_tests(${_TEST_NAME}_tests)
|
||||||
|
|||||||
@@ -2,7 +2,10 @@
|
|||||||
|
|
||||||
// Shared embedded-interpreter bootstrap for slic3rutils tests that need a live Python
|
// Shared embedded-interpreter bootstrap for slic3rutils tests that need a live Python
|
||||||
// interpreter (test_plugin_host_api.cpp, test_slicing_pipeline_bindings.cpp, ...).
|
// interpreter (test_plugin_host_api.cpp, test_slicing_pipeline_bindings.cpp, ...).
|
||||||
|
#include <boost/dll/runtime_symbol_info.hpp>
|
||||||
|
#include <boost/filesystem.hpp>
|
||||||
|
#include <memory.h>
|
||||||
|
#include <stdexcept>
|
||||||
#include <pybind11/embed.h>
|
#include <pybind11/embed.h>
|
||||||
#include <pybind11/pybind11.h>
|
#include <pybind11/pybind11.h>
|
||||||
|
|
||||||
@@ -12,17 +15,29 @@ namespace {
|
|||||||
|
|
||||||
void ensure_python_initialized()
|
void ensure_python_initialized()
|
||||||
{
|
{
|
||||||
// Deliberately a bare scoped_interpreter rather than Slic3r::PythonInterpreter:
|
if (Py_IsInitialized())
|
||||||
// `orca` is a PYBIND11_EMBEDDED_MODULE compiled into this test binary, so importing
|
return;
|
||||||
// it needs no bundled stdlib/sys.path, and the deterministic assertions are
|
|
||||||
// independent of the host's Python. PythonInterpreter::initialize() expects the
|
static std::unique_ptr<pybind11::scoped_interpreter> interpreter;
|
||||||
// bundled Python home laid out next to the app bundle (lib/python3.12/encodings),
|
|
||||||
// which is not deployed beside the test binary, so using it here would fail to find
|
PyConfig config;
|
||||||
// a home on macOS/Linux. The optional numpy-backed assertions are guarded at runtime.
|
PyConfig_InitPythonConfig(&config);
|
||||||
if (!Py_IsInitialized()) {
|
config.parse_argv = 0;
|
||||||
static pybind11::scoped_interpreter interpreter;
|
|
||||||
(void) interpreter;
|
const auto python_home = boost::dll::program_location().parent_path() / "python";
|
||||||
|
|
||||||
|
if (boost::filesystem::exists(python_home)) {
|
||||||
|
const std::string home = python_home.string();
|
||||||
|
const PyStatus status = PyConfig_SetBytesString(&config, &config.home, home.c_str());
|
||||||
|
|
||||||
|
if (PyStatus_Exception(status)) {
|
||||||
|
const char* message = status.err_msg ? status.err_msg : "Failed to set Python home";
|
||||||
|
PyConfig_Clear(&config);
|
||||||
|
throw std::runtime_error(message);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interpreter = std::make_unique<pybind11::scoped_interpreter>(&config);
|
||||||
}
|
}
|
||||||
|
|
||||||
pybind11::module_ import_orca_module()
|
pybind11::module_ import_orca_module()
|
||||||
|
|||||||
Reference in New Issue
Block a user