Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/core/python/itkwasm/itkwasm/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""itkwasm: Python interface to itk-wasm WebAssembly modules."""

__version__ = "1.0b200"
__version__ = "1.0b201"

from .interface_types import InterfaceTypes
from .image import Image, ImageType, ImageRegion
Expand Down
7 changes: 4 additions & 3 deletions packages/core/python/itkwasm/itkwasm/pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,6 @@
WasiConfig,
Linker,
WasmtimeError,
DirPerms,
FilePerms
)

# Get the value of the ITKWASM_CACHE_DIR environment variable
Expand Down Expand Up @@ -86,7 +84,10 @@ def __init__(
wasi_config.argv = args

for preopen in preopen_directories:
wasi_config.preopen_dir(preopen, preopen, DirPerms.READ_WRITE, FilePerms.READ_WRITE)
# Read-write access is the default in every supported wasmtime; passing
# it explicitly is not portable -- wasmtime 48 replaced the DirPerms /
# FilePerms arguments with a single fs_mutable flag.
wasi_config.preopen_dir(preopen, preopen)

store.set_wasi(wasi_config)

Expand Down
61 changes: 61 additions & 0 deletions packages/core/python/itkwasm/test/test_pipeline.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from pathlib import Path, PurePosixPath
import shutil
import tempfile
from dataclasses import asdict
import sys
Expand Down Expand Up @@ -138,6 +139,66 @@ def test_pipeline_input_output_files():
assert content[3] == 239


@pytest.mark.skipif(
sys.platform == "win32",
reason="Windows tempfile resource, https://github.com/bytecodealliance/wasmtime-py/issues/132",
)
def test_pipeline_input_output_files_same_directory():
"""A directory preopened for both input and output is read-write.

Inputs and outputs in the same directory collapse to a single preopen, so
that one preopen must serve reads and writes. This pins the read-write
default relied on by RunInstance.preopen_dir.
"""
pipeline = Pipeline(test_input_dir / "input-output-files-test.wasi.wasm")

with tempfile.TemporaryDirectory() as tmpdirname:
tmpdir = Path(tmpdirname)
shutil.copy(test_input_dir / "input.txt", tmpdir / "input.txt")
shutil.copy(test_input_dir / "input.bin", tmpdir / "input.bin")

input_text_file = PurePosixPath(tmpdir / "input.txt")
input_binary_file = PurePosixPath(tmpdir / "input.bin")
output_text_file = PurePosixPath(tmpdir / "output.txt")
output_binary_file = PurePosixPath(tmpdir / "output.bin")

pipeline_inputs = [
PipelineInput(InterfaceTypes.TextFile, TextFile(input_text_file)),
PipelineInput(InterfaceTypes.BinaryFile, BinaryFile(input_binary_file)),
]

pipeline_outputs = [
PipelineOutput(InterfaceTypes.TextFile, TextFile(output_text_file)),
PipelineOutput(InterfaceTypes.BinaryFile, BinaryFile(output_binary_file)),
]

args = [
"--memory-io",
"--use-files",
"--input-text-file",
str(input_text_file),
"--input-binary-file",
str(input_binary_file),
"--output-text-file",
str(output_text_file),
"--output-binary-file",
str(output_binary_file),
]

outputs = pipeline.run(args, pipeline_outputs, pipeline_inputs)

assert outputs[0].type == InterfaceTypes.TextFile
with open(outputs[0].data.path, "r") as fp:
assert fp.read() == "The answer is 42."
assert outputs[1].type == InterfaceTypes.BinaryFile
with open(outputs[1].data.path, "rb") as fp:
content = fp.read()
assert content[0] == 222
assert content[1] == 173
assert content[2] == 190
assert content[3] == 239


def test_pipeline_write_read_image():
pipeline = Pipeline(test_input_dir / "median-filter-test.wasi.wasm")

Expand Down
Loading