From fbdfe7cc1b9fdcd760bbc2e497840911cdc37b9f Mon Sep 17 00:00:00 2001 From: stevenewald Date: Thu, 5 Oct 2023 20:26:05 +0100 Subject: [PATCH] Changing interpreter initialization location + importing packages within cpp --- Dockerfile | 2 +- src/lint/lint.cpp | 1 - src/main.cpp | 2 ++ src/pywrapper/runtime.cpp | 3 +++ 4 files changed, 6 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index cb112e8..6b09cfc 100644 --- a/Dockerfile +++ b/Dockerfile @@ -19,7 +19,7 @@ RUN cmake --preset=ci-docker \ # Main stage -FROM python:3.11 +FROM python:3.11-slim RUN pip install numpy pandas polars scipy scikit-learn diff --git a/src/lint/lint.cpp b/src/lint/lint.cpp index 022e039..b9a1037 100644 --- a/src/lint/lint.cpp +++ b/src/lint/lint.cpp @@ -10,7 +10,6 @@ lint(const std::string& uid, const std::string& algo_id) return "Could not find algorithm"; } - pybind11::scoped_interpreter guard{}; bool e = nutc::pywrapper::create_api_module(nutc::mock_api::getMarketFunc()); if (!e) { log_e(linting, "Failed to create API module"); diff --git a/src/main.cpp b/src/main.cpp index 1a67327..617723f 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -76,6 +76,8 @@ main(int argc, const char** argv) crow::SimpleApp app; + pybind11::scoped_interpreter guard{}; + CROW_ROUTE(app, "/") ([&](const crow::request& req) { if (!req.url_params.get("uid")) { diff --git a/src/pywrapper/runtime.cpp b/src/pywrapper/runtime.cpp index 7a9283e..2b4f931 100644 --- a/src/pywrapper/runtime.cpp +++ b/src/pywrapper/runtime.cpp @@ -16,6 +16,9 @@ create_api_module( "nutc_api", "Official NUTC Exchange API", new py::module::module_def ); m.def("publish_market_order", publish_market_order); + py::module_::import("numpy"); + py::module_::import("scipy"); + py::module_::import("pandas"); py::module_ sys = py::module_::import("sys"); py::dict sys_modules = sys.attr("modules").cast();