@@ -4,6 +4,7 @@ mod auth;
44mod channel;
55mod config;
66mod logger;
7+ #[ cfg( feature = "python" ) ]
78mod python;
89mod stream;
910mod transport;
@@ -13,14 +14,12 @@ use once_cell::sync::OnceCell;
1314
1415use std:: sync:: Arc ;
1516
16- use crate :: python:: CubeConfigPy ;
1717use auth:: NodeBridgeAuthService ;
1818use config:: NodeConfig ;
1919use cubesql:: { config:: CubeServices , telemetry:: ReportingLogger } ;
2020use log:: Level ;
2121use logger:: NodeBridgeLogger ;
2222use neon:: prelude:: * ;
23- use pyo3:: prelude:: * ;
2423use simple_logger:: SimpleLogger ;
2524use tokio:: runtime:: { Builder , Runtime } ;
2625use transport:: NodeBridgeTransport ;
@@ -48,19 +47,6 @@ fn runtime<'a, C: Context<'a>>(cx: &mut C) -> NeonResult<&'static Runtime> {
4847 } )
4948}
5049
51- fn py_runtime < ' a , C : Context < ' a > > ( cx : & mut C ) -> NeonResult < & ( ) > {
52- static PY_RUNTIME : OnceCell < ( ) > = OnceCell :: new ( ) ;
53-
54- let runtime = runtime ( cx) ?;
55-
56- PY_RUNTIME . get_or_try_init ( || {
57- pyo3:: prepare_freethreaded_python ( ) ;
58- pyo3_asyncio:: tokio:: init_with_runtime ( runtime) . unwrap ( ) ;
59-
60- Ok ( ( ) )
61- } )
62- }
63-
6450fn setup_logger ( mut cx : FunctionContext ) -> JsResult < JsUndefined > {
6551 let options = cx. argument :: < JsObject > ( 0 ) ?;
6652 let cube_logger = options
@@ -202,50 +188,25 @@ fn shutdown_interface(mut cx: FunctionContext) -> JsResult<JsPromise> {
202188 Ok ( promise)
203189}
204190
205- fn python_load_config ( mut cx : FunctionContext ) -> JsResult < JsPromise > {
206- let config_file_content = cx. argument :: < JsString > ( 0 ) ?. value ( & mut cx) ;
207-
208- let ( deferred, promise) = cx. promise ( ) ;
209- let channel = cx. channel ( ) ;
210-
211- py_runtime ( & mut cx) ?;
212-
213- let conf_res = Python :: with_gil ( |py| -> PyResult < CubeConfigPy > {
214- let cube_conf_code = include_str ! ( concat!(
215- env!( "CARGO_MANIFEST_DIR" ) ,
216- "/python/cube/src/conf/__init__.py"
217- ) ) ;
218- PyModule :: from_code ( py, cube_conf_code, "__init__.py" , "cube.conf" ) ?;
219-
220- let config_module = PyModule :: from_code ( py, & config_file_content, "config.py" , "" ) ?;
221- let settings_py = config_module. getattr ( "settings" ) ?;
222-
223- let mut cube_conf = CubeConfigPy :: new ( ) ;
224-
225- for attr_name in cube_conf. get_static_attrs ( ) {
226- cube_conf. static_from_attr ( settings_py, attr_name) ?;
227- }
228-
229- cube_conf. apply_dynamic_functions ( settings_py) ?;
230-
231- Ok ( cube_conf)
232- } ) ;
233-
234- deferred. settle_with ( & channel, move |mut cx| match conf_res {
235- Ok ( c) => c. to_object ( & mut cx) ,
236- Err ( err) => cx. throw_error ( format ! ( "Python error: {}" , err) ) ,
237- } ) ;
191+ fn is_fallback_build ( mut cx : FunctionContext ) -> JsResult < JsBoolean > {
192+ #[ cfg( feature = "python" ) ]
193+ {
194+ return Ok ( JsBoolean :: new ( & mut cx, false ) ) ;
195+ }
238196
239- Ok ( promise)
197+ #[ allow( unreachable_code) ]
198+ Ok ( JsBoolean :: new ( & mut cx, true ) )
240199}
241200
242201#[ neon:: main]
243202fn main ( mut cx : ModuleContext ) -> NeonResult < ( ) > {
244203 cx. export_function ( "setupLogger" , setup_logger) ?;
245204 cx. export_function ( "registerInterface" , register_interface) ?;
246205 cx. export_function ( "shutdownInterface" , shutdown_interface) ?;
206+ cx. export_function ( "isFallbackBuild" , is_fallback_build) ?;
247207
248- cx. export_function ( "pythonLoadConfig" , python_load_config) ?;
208+ #[ cfg( feature = "python" ) ]
209+ python:: python_register_module ( cx) ?;
249210
250211 Ok ( ( ) )
251212}
0 commit comments