Skip to content

Commit 49c0494

Browse files
committed
feat(backend-native): Allow importing modules from python files within cube.py
1 parent 9319b0d commit 49c0494

File tree

1 file changed

+10
-0
lines changed
  • packages/cubejs-backend-native/src/python

1 file changed

+10
-0
lines changed

packages/cubejs-backend-native/src/python/entry.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use crate::python::runtime::py_runtime_init;
66
use neon::prelude::*;
77
use pyo3::prelude::*;
88
use pyo3::types::{PyDict, PyFunction, PyList, PyString, PyTuple};
9+
use std::path::Path;
910

1011
fn python_load_config(mut cx: FunctionContext) -> JsResult<JsPromise> {
1112
let file_content_arg = cx.argument::<JsString>(0)?.value(&mut cx);
@@ -20,6 +21,15 @@ fn python_load_config(mut cx: FunctionContext) -> JsResult<JsPromise> {
2021
py_runtime_init(&mut cx, channel.clone())?;
2122

2223
let conf_res = Python::with_gil(|py| -> PyResult<CubeConfigPy> {
24+
let sys_path = py.import("sys")?.getattr("path")?.downcast::<PyList>()?;
25+
26+
let config_dir = Path::new(&options_file_name)
27+
.parent()
28+
.unwrap_or_else(|| Path::new("."));
29+
let config_dir_str = config_dir.to_str().unwrap_or(".");
30+
31+
sys_path.insert(0, PyString::new(py, config_dir_str))?;
32+
2333
let cube_code = include_str!(concat!(
2434
env!("CARGO_MANIFEST_DIR"),
2535
"/python/cube/src/__init__.py"

0 commit comments

Comments
 (0)