pub struct PythonRuntime { /* private fields */ }Expand description
The Python runtime instance. One per init() call.
Implementations§
Source§impl PythonRuntime
impl PythonRuntime
Sourcepub fn new(_config_msgpack: &[u8]) -> Result<Self, String>
pub fn new(_config_msgpack: &[u8]) -> Result<Self, String>
Initialize a new Python runtime.
_config_msgpack is the MessagePack-encoded configuration from the
host. Currently unused – reserved for future settings like
virtualenv path, Python version constraints, etc.
Sourcepub fn register_types(&mut self, _types_msgpack: &[u8]) -> Result<(), String>
pub fn register_types(&mut self, _types_msgpack: &[u8]) -> Result<(), String>
Register Shape type schemas for Python stub generation.
The runtime receives the full set of Shape types so it can generate Python dataclass stubs that the user’s code can reference.
Sourcepub fn compile(
&mut self,
name: &str,
source: &str,
param_names: &[String],
param_types: &[String],
return_type: &str,
is_async: bool,
) -> Result<*mut c_void, String>
pub fn compile( &mut self, name: &str, source: &str, param_names: &[String], param_types: &[String], return_type: &str, is_async: bool, ) -> Result<*mut c_void, String>
Compile a foreign function body into a callable Python function.
When is_async is false, wraps the user’s body in:
def __shape_fn__(param1, param2) -> return_type:
<body>When is_async is true, wraps it in an async def with an asyncio runner:
import asyncio
async def __shape_async__(param1, param2) -> return_type:
<body>
def __shape_fn__(param1, param2) -> return_type:
return asyncio.run(__shape_async__(param1, param2))Returns a handle that can be passed to invoke().
Sourcepub fn invoke(
&self,
handle: *mut c_void,
args_msgpack: &[u8],
) -> Result<Vec<u8>, String>
pub fn invoke( &self, handle: *mut c_void, args_msgpack: &[u8], ) -> Result<Vec<u8>, String>
Invoke a previously compiled function with msgpack-encoded arguments.
Returns msgpack-encoded result on success.
Sourcepub fn dispose_function(&mut self, handle: *mut c_void)
pub fn dispose_function(&mut self, handle: *mut c_void)
Dispose a compiled function handle, freeing associated resources.
Sourcepub fn language_id() -> &'static str
pub fn language_id() -> &'static str
Return the language identifier.
Sourcepub fn lsp_config() -> LanguageRuntimeLspConfig
pub fn lsp_config() -> LanguageRuntimeLspConfig
Return LSP configuration for Python (pyright).