Skip to content

Commit 6c988f0

Browse files
committed
Keep the old function to avoid breaking backwards compatibility
1 parent 1d4c7a1 commit 6c988f0

File tree

3 files changed

+26
-4
lines changed

3 files changed

+26
-4
lines changed

packages/api/src/import_object.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ impl ImportObject {
200200
self.inner.contains_namespace(namespace_name)
201201
}
202202

203-
/// Gets an `ImportObject` from a Python dictionary.
203+
/// Gets a Python dictionary from an `ImportObject`.
204204
#[pyo3(text_signature = "($self)")]
205205
pub(crate) fn to_dict<'py>(&'py self) -> Result<PyObject, PyErr> {
206206
let gil_guard = Python::acquire_gil();

packages/api/src/instance.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,8 @@ impl Instance {
113113
Ok(io) => wasmer::Instance::new(&module, io.borrow().inner()),
114114
Err(_e) => match import_object.downcast::<PyDict>() {
115115
Ok(dict) => {
116-
let io = ImportObject::from_pydict(dict).map_err(|e| InstanceError::PyErr(e.into()))?;
116+
let io = ImportObject::from_pydict(dict)
117+
.map_err(|e| InstanceError::PyErr(e.into()))?;
117118
wasmer::Instance::new(&module, io.borrow().inner())
118119
}
119120
Err(e) => {

packages/api/src/wasi.rs

+23-2
Original file line numberDiff line numberDiff line change
@@ -465,14 +465,35 @@ impl Environment {
465465
/// import_object = wasi_env.generate_import_object(store, wasi.Version.SNAPSHOT1)
466466
/// ```
467467
//#[pyo3(text_signature = "($self, store, wasi_version)")]
468-
fn generate_import_object(&self, store: &Store, wasi_version: Version) -> PyResult<PyObject> {
468+
fn generate_import_object(&self, store: &Store, wasi_version: Version) -> ImportObject {
469469
let import_object = wasmer_wasi::generate_import_object_from_env(
470470
store.inner(),
471471
self.inner.clone(),
472472
wasi_version.into(),
473473
);
474474

475-
ImportObject::raw_new(import_object).to_dict()
475+
ImportObject::raw_new(import_object)
476+
}
477+
478+
/// Create a dictionary of import with an existing
479+
/// `Environment`. The import object will be different according
480+
/// to the WASI version.
481+
///
482+
/// Use the `Version` enum to use a specific WASI version, or use
483+
/// `get_version` to read the WASI version from a `wasmer.Module`.
484+
///
485+
/// ## Example
486+
///
487+
/// ```py
488+
/// from wasmer import wasi, Store
489+
///
490+
/// store = Store()
491+
/// wasi_env = wasi.StateBuilder('test-program').argument('--foo').finalize()
492+
/// imports = wasi_env.generate_imports(store, wasi.Version.SNAPSHOT1)
493+
/// ```
494+
//#[pyo3(text_signature = "($self, store, wasi_version)")]
495+
fn generate_imports(&self, store: &Store, wasi_version: Version) -> PyResult<PyObject> {
496+
self.generate_import_object(store, wasi_version).to_dict()
476497
}
477498
}
478499

0 commit comments

Comments
 (0)