Skip to main content

PythonRuntime

Struct PythonRuntime 

Source
pub struct PythonRuntime { /* private fields */ }
Expand description

The Python runtime instance. One per init() call.

Implementations§

Source§

impl PythonRuntime

Source

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.

Source

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.

Source

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().

Source

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.

Source

pub fn dispose_function(&mut self, handle: *mut c_void)

Dispose a compiled function handle, freeing associated resources.

Source

pub fn language_id() -> &'static str

Return the language identifier.

Source

pub fn lsp_config() -> LanguageRuntimeLspConfig

Return LSP configuration for Python (pyright).

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> Ungil for T
where T: Send,