diff --git a/test_files/components/README.md b/test_files/components/README.md new file mode 100644 index 0000000..21f5975 --- /dev/null +++ b/test_files/components/README.md @@ -0,0 +1 @@ +https://component-model.bytecodealliance.org/ diff --git a/test_files/components/python_decoder/.gitignore b/test_files/components/python_decoder/.gitignore new file mode 100644 index 0000000..bee8a64 --- /dev/null +++ b/test_files/components/python_decoder/.gitignore @@ -0,0 +1 @@ +__pycache__ diff --git a/test_files/components/python_decoder/README.md b/test_files/components/python_decoder/README.md new file mode 100644 index 0000000..cbd48df --- /dev/null +++ b/test_files/components/python_decoder/README.md @@ -0,0 +1,11 @@ +How to create and build the Python component: + +1. `pip install componentize-py` +2. Create the `python_decoder` folder +3. `cd python_decoder` +4. Create `.gitignore` with content `__pycache__` +5. Create the `src` folder with the file `app.py` +6. Create the `wit` folder with the file `world.wit` +7. Update code as needed +8. `componentize-py --wit-path wit/world.wit bindings src/bindings` +9. `componentize-py --wit-path wit/world.wit componentize src.app --output python_decoder.wasm` diff --git a/test_files/components/python_decoder/python_decoder.wasm b/test_files/components/python_decoder/python_decoder.wasm new file mode 100644 index 0000000..8c894a1 Binary files /dev/null and b/test_files/components/python_decoder/python_decoder.wasm differ diff --git a/test_files/components/python_decoder/src/app.py b/test_files/components/python_decoder/src/app.py new file mode 100644 index 0000000..b5cfeff --- /dev/null +++ b/test_files/components/python_decoder/src/app.py @@ -0,0 +1,14 @@ +from .bindings.component import exports +from .bindings.component.imports import host + +name = "Python Test Decoder" + +class Decoder(exports.Decoder): + def init(self) -> None: + host.log(f"{name} initialized") + + def name(self) -> str: + return name + + def format_signal_value(self, value: str) -> str: + return str + "!" diff --git a/test_files/components/python_decoder/src/bindings/component/__init__.py b/test_files/components/python_decoder/src/bindings/component/__init__.py new file mode 100644 index 0000000..2690a80 --- /dev/null +++ b/test_files/components/python_decoder/src/bindings/component/__init__.py @@ -0,0 +1,12 @@ +from typing import TypeVar, Generic, Union, Optional, Protocol, Tuple, List, Any, Self +from enum import Flag, Enum, auto +from dataclasses import dataclass +from abc import abstractmethod +import weakref + +from .types import Result, Ok, Err, Some + + + +class Component(Protocol): + pass diff --git a/test_files/components/python_decoder/src/bindings/component/exports/__init__.py b/test_files/components/python_decoder/src/bindings/component/exports/__init__.py new file mode 100644 index 0000000..fa97298 --- /dev/null +++ b/test_files/components/python_decoder/src/bindings/component/exports/__init__.py @@ -0,0 +1,24 @@ +from typing import TypeVar, Generic, Union, Optional, Protocol, Tuple, List, Any, Self +from enum import Flag, Enum, auto +from dataclasses import dataclass +from abc import abstractmethod +import weakref + +from ..types import Result, Ok, Err, Some + + +class Decoder(Protocol): + + @abstractmethod + def init(self) -> None: + raise NotImplementedError + + @abstractmethod + def name(self) -> str: + raise NotImplementedError + + @abstractmethod + def format_signal_value(self, value: str) -> str: + raise NotImplementedError + + diff --git a/test_files/components/python_decoder/src/bindings/component/exports/decoder.py b/test_files/components/python_decoder/src/bindings/component/exports/decoder.py new file mode 100644 index 0000000..794d5a1 --- /dev/null +++ b/test_files/components/python_decoder/src/bindings/component/exports/decoder.py @@ -0,0 +1,9 @@ +from typing import TypeVar, Generic, Union, Optional, Protocol, Tuple, List, Any, Self +from enum import Flag, Enum, auto +from dataclasses import dataclass +from abc import abstractmethod +import weakref + +from ..types import Result, Ok, Err, Some + + diff --git a/test_files/components/python_decoder/src/bindings/component/imports/__init__.py b/test_files/components/python_decoder/src/bindings/component/imports/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/test_files/components/python_decoder/src/bindings/component/imports/host.py b/test_files/components/python_decoder/src/bindings/component/imports/host.py new file mode 100644 index 0000000..527a50a --- /dev/null +++ b/test_files/components/python_decoder/src/bindings/component/imports/host.py @@ -0,0 +1,13 @@ +from typing import TypeVar, Generic, Union, Optional, Protocol, Tuple, List, Any, Self +from enum import Flag, Enum, auto +from dataclasses import dataclass +from abc import abstractmethod +import weakref + +from ..types import Result, Ok, Err, Some + + + +def log(message: str) -> None: + raise NotImplementedError + diff --git a/test_files/components/python_decoder/src/bindings/component/types.py b/test_files/components/python_decoder/src/bindings/component/types.py new file mode 100644 index 0000000..77ad379 --- /dev/null +++ b/test_files/components/python_decoder/src/bindings/component/types.py @@ -0,0 +1,23 @@ +from typing import TypeVar, Generic, Union, Optional, Protocol, Tuple, List, Any, Self +from enum import Flag, Enum, auto +from dataclasses import dataclass +from abc import abstractmethod +import weakref + + +S = TypeVar('S') +@dataclass +class Some(Generic[S]): + value: S + +T = TypeVar('T') +@dataclass +class Ok(Generic[T]): + value: T + +E = TypeVar('E') +@dataclass(frozen=True) +class Err(Generic[E], Exception): + value: E + +Result = Union[Ok[T], Err[E]] diff --git a/test_files/components/python_decoder/wit/world.wit b/test_files/components/python_decoder/wit/world.wit new file mode 100644 index 0000000..27b8204 --- /dev/null +++ b/test_files/components/python_decoder/wit/world.wit @@ -0,0 +1,16 @@ +package component:python-decoder; + +interface host { + log: func(message: string); +} + +interface decoder { + init: func(); + name: func() -> string; + format-signal-value: func(value: string) -> string; +} + +world component { + import host; + export decoder; +}