python_decoder
This commit is contained in:
parent
139eb3d31a
commit
8f351bd639
1
test_files/components/README.md
Normal file
1
test_files/components/README.md
Normal file
|
@ -0,0 +1 @@
|
|||
https://component-model.bytecodealliance.org/
|
1
test_files/components/python_decoder/.gitignore
vendored
Normal file
1
test_files/components/python_decoder/.gitignore
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
__pycache__
|
11
test_files/components/python_decoder/README.md
Normal file
11
test_files/components/python_decoder/README.md
Normal file
|
@ -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`
|
BIN
test_files/components/python_decoder/python_decoder.wasm
Normal file
BIN
test_files/components/python_decoder/python_decoder.wasm
Normal file
Binary file not shown.
14
test_files/components/python_decoder/src/app.py
Normal file
14
test_files/components/python_decoder/src/app.py
Normal file
|
@ -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 + "!"
|
|
@ -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
|
|
@ -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
|
||||
|
||||
|
|
@ -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
|
||||
|
||||
|
|
@ -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
|
||||
|
|
@ -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]]
|
16
test_files/components/python_decoder/wit/world.wit
Normal file
16
test_files/components/python_decoder/wit/world.wit
Normal file
|
@ -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;
|
||||
}
|
Loading…
Reference in a new issue