Skip to content

Commit 79b3e1a

Browse files
authored
chore(native): Use correct file name for python module loading (#6935)
1 parent c167002 commit 79b3e1a

File tree

6 files changed

+22
-14
lines changed

6 files changed

+22
-14
lines changed

packages/cubejs-backend-native/js/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ export interface PyConfiguration {
248248
contextToApiScopes?: () => Promise<string[]>
249249
}
250250

251-
export const pythonLoadConfig = async (content: string, options: { file: string }): Promise<PyConfiguration> => {
251+
export const pythonLoadConfig = async (content: string, options: { fileName: string }): Promise<PyConfiguration> => {
252252
if (isFallbackBuild()) {
253253
throw new Error('Python is not supported in fallback build');
254254
}

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,11 @@ use pyo3::prelude::*;
88
use pyo3::types::{PyDict, PyFunction, PyList, PyString, PyTuple};
99

1010
fn python_load_config(mut cx: FunctionContext) -> JsResult<JsPromise> {
11-
let config_file_content = cx.argument::<JsString>(0)?.value(&mut cx);
11+
let file_content_arg = cx.argument::<JsString>(0)?.value(&mut cx);
12+
let options_arg = cx.argument::<JsObject>(1)?;
13+
let options_file_name = options_arg
14+
.get::<JsString, _, _>(&mut cx, "fileName")?
15+
.value(&mut cx);
1216

1317
let (deferred, promise) = cx.promise();
1418
let channel = cx.channel();
@@ -22,7 +26,7 @@ fn python_load_config(mut cx: FunctionContext) -> JsResult<JsPromise> {
2226
));
2327
PyModule::from_code(py, cube_conf_code, "__init__.py", "cube.conf")?;
2428

25-
let config_module = PyModule::from_code(py, &config_file_content, "config.py", "")?;
29+
let config_module = PyModule::from_code(py, &file_content_arg, &options_file_name, "")?;
2630
let settings_py = if config_module.hasattr("__execution_context_locals")? {
2731
let execution_context_locals = config_module.getattr("__execution_context_locals")?;
2832
execution_context_locals.get_item("settings")?

packages/cubejs-backend-native/test/python.test.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,21 @@ const suite = native.isFallbackBuild() ? xdescribe : describe;
88
// TODO(ovr): Find what is going wrong with parallel tests & python on Linux
99
const darwinSuite = process.platform === 'darwin' && !native.isFallbackBuild() ? describe : xdescribe;
1010

11-
async function loadConfigurationFile(file: string) {
12-
const content = await fs.readFile(path.join(process.cwd(), 'test', file), 'utf8');
11+
async function loadConfigurationFile(fileName: string) {
12+
const content = await fs.readFile(path.join(process.cwd(), 'test', fileName), 'utf8');
1313
console.log('content', {
1414
content,
15-
file
15+
fileName
1616
});
1717

1818
const config = await native.pythonLoadConfig(
1919
content,
2020
{
21-
file
21+
fileName
2222
}
2323
);
2424

25-
console.log(`loaded config ${file}`, config);
25+
console.log(`loaded config ${fileName}`, config);
2626

2727
return config;
2828
}

packages/cubejs-backend-native/test/python.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import * as native from '../js';
1717
const config = await native.pythonLoadConfig(
1818
content,
1919
{
20-
file: 'config.py'
20+
fileName: 'config.py'
2121
}
2222
);
2323

packages/cubejs-backend-native/test/python_async_bench.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import * as native from '../js';
1717
const config = await native.pythonLoadConfig(
1818
content,
1919
{
20-
file: 'config.py'
20+
fileName: 'config.py'
2121
}
2222
);
2323

packages/cubejs-server/src/server/container.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -339,17 +339,21 @@ export class ServerContainer {
339339
}
340340

341341
protected async loadConfigurationFromPythonFile(): Promise<CreateOptions> {
342-
const file = await fsAsync.readFile(
342+
const content = await fsAsync.readFile(
343343
path.join(process.cwd(), 'cube.py'),
344344
'utf-8'
345345
);
346346

347347
if (this.configuration.debug) {
348-
console.log('Loaded python configuration file', file);
348+
console.log('Loaded python configuration file', content);
349349
}
350350

351-
const config = await pythonLoadConfig(file, {
352-
file: 'cube.py',
351+
return this.loadConfigurationFromPythonMemory(content);
352+
}
353+
354+
protected async loadConfigurationFromPythonMemory(content: string): Promise<CreateOptions> {
355+
const config = await pythonLoadConfig(content, {
356+
fileName: 'cube.py',
353357
});
354358

355359
return config as any;

0 commit comments

Comments
 (0)