-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(bindgen): Python interface package with environment dispatch
- Loading branch information
Showing
22 changed files
with
313 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 0 additions & 14 deletions
14
packages/compress-stringify/python/compress-stringify-wasi/README.md
This file was deleted.
Oops, something went wrong.
14 changes: 14 additions & 0 deletions
14
packages/compress-stringify/python/itkwasm-compress-stringify-wasi/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# itkwasm-compress-stringify-wasi | ||
|
||
[![PyPI version](https://badge.fury.io/py/itkwasm-compress-stringify-wasi.svg)](https://badge.fury.io/py/itkwasm-compress-stringify-wasi) | ||
|
||
Zstandard compression and decompression and base64 encoding and decoding in WebAssembly. WASI implementation. | ||
|
||
This package provides the WASI WebAssembly implementation. It is usually not called directly. Please use the [`itkwasm-compress-stringify`](https://pypi.org/project/itkwasm-compress-stringify/) instead. | ||
|
||
|
||
## Installation | ||
|
||
```sh | ||
pip install itkwasm-compress-stringify-wasi | ||
``` |
6 changes: 6 additions & 0 deletions
6
...ingify/python/itkwasm-compress-stringify-wasi/itkwasm_compress_stringify_wasi/__init__.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
"""itkwasm-compress-stringify-wasi: Zstandard compression and decompression and base64 encoding and decoding in WebAssembly. WASI implementation.""" | ||
|
||
from .compress_stringify import compress_stringify | ||
from .parse_string_decompress import parse_string_decompress | ||
|
||
from ._version import __version__ |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
54 changes: 54 additions & 0 deletions
54
packages/compress-stringify/python/itkwasm-compress-stringify-wasi/pyproject.toml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
[build-system] | ||
requires = ["hatchling", "hatch-vcs"] | ||
build-backend = "hatchling.build" | ||
|
||
[project] | ||
name = "itkwasm-compress-stringify-wasi" | ||
readme = "README.md" | ||
license = "Apache-2.0" | ||
dynamic = ["version", "description"] | ||
classifiers = [ | ||
"License :: OSI Approved :: Apache Software License", | ||
"Programming Language :: Python", | ||
"Programming Language :: C++", | ||
"Environment :: WebAssembly", | ||
"Environment :: WebAssembly :: Emscripten", | ||
"Environment :: WebAssembly :: WASI", | ||
"Development Status :: 3 - Alpha", | ||
"Intended Audience :: Developers", | ||
"Intended Audience :: Science/Research", | ||
"Programming Language :: Python :: 3", | ||
"Programming Language :: Python :: 3.7", | ||
"Programming Language :: Python :: 3.8", | ||
"Programming Language :: Python :: 3.9", | ||
"Programming Language :: Python :: 3.10", | ||
"Programming Language :: Python :: 3.11", | ||
] | ||
keywords = [ | ||
"itkwasm", | ||
"webassembly", | ||
"emscripten", | ||
"wasi", | ||
] | ||
|
||
requires-python = ">=3.7" | ||
dependencies = [ | ||
"itkwasm >= 1.0b93", | ||
"importlib_resources", | ||
] | ||
|
||
[tool.hatch.version] | ||
path = "itkwasm_compress_stringify_wasi/_version.py" | ||
|
||
[tool.hatch.envs.default] | ||
dependencies = [ | ||
"pytest", | ||
] | ||
|
||
[tool.hatch.envs.default.scripts] | ||
test = "pytest" | ||
|
||
[tool.hatch.build] | ||
exclude = [ | ||
"/examples", | ||
] |
33 changes: 33 additions & 0 deletions
33
...compress-stringify/python/itkwasm-compress-stringify-wasi/test/test_compress_stringify.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
from itkwasm_compress_stringify_wasi import compress_stringify, parse_string_decompress | ||
|
||
def test_decompress_returns_what_was_compressed(): | ||
data = bytes([222, 173, 190, 239]) | ||
compressed_data = compress_stringify(data, compression_level=8) | ||
decompressed_data = parse_string_decompress(compressed_data) | ||
|
||
assert decompressed_data[0] == 222 | ||
assert decompressed_data[1] == 173 | ||
assert decompressed_data[2] == 190 | ||
assert decompressed_data[3] == 239 | ||
|
||
def test_we_can_stringify_during_compression(): | ||
data = bytes([222, 173, 190, 239]) | ||
compressed_data = compress_stringify(data, compression_level=8, stringify=True) | ||
assert compressed_data.decode() == 'data:base64,KLUv/SAEIQAA3q2+7w==' | ||
decompressed_data = parse_string_decompress(compressed_data, parse_string=True) | ||
|
||
assert decompressed_data[0] == 222 | ||
assert decompressed_data[1] == 173 | ||
assert decompressed_data[2] == 190 | ||
assert decompressed_data[3] == 239 | ||
|
||
def test_we_can_use_a_custom_data_url_prefix(): | ||
data = bytes([222, 173, 190, 239]) | ||
compressed_data = compress_stringify(data, compression_level=8, stringify=True, data_url_prefix='custom,') | ||
assert compressed_data.decode() == 'custom,KLUv/SAEIQAA3q2+7w==' | ||
decompressed_data = parse_string_decompress(compressed_data, parse_string=True) | ||
|
||
assert decompressed_data[0] == 222 | ||
assert decompressed_data[1] == 173 | ||
assert decompressed_data[2] == 190 | ||
assert decompressed_data[3] == 239 |
11 changes: 11 additions & 0 deletions
11
packages/compress-stringify/python/itkwasm-compress-stringify/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# itkwasm-compress-stringify | ||
|
||
[![PyPI version](https://badge.fury.io/py/itkwasm-compress-stringify.svg)](https://badge.fury.io/py/itkwasm-compress-stringify) | ||
|
||
Zstandard compression and decompression and base64 encoding and decoding in WebAssembly. | ||
|
||
## Installation | ||
|
||
```sh | ||
pip install itkwasm-compress-stringify | ||
``` |
2 changes: 1 addition & 1 deletion
2
...-wasi/compress_stringify_wasi/__init__.py → ...fy/itkwasm_compress_stringify/__init__.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
...mpress-stringify/python/itkwasm-compress-stringify/itkwasm_compress_stringify/_version.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
__version__ = "0.1.0" |
41 changes: 41 additions & 0 deletions
41
...ingify/python/itkwasm-compress-stringify/itkwasm_compress_stringify/compress_stringify.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
# Generated file. Do not edit. | ||
|
||
from itkwasm import ( | ||
environment_dispatch, | ||
BinaryStream, | ||
) | ||
|
||
def compress_stringify( | ||
input: bytes, | ||
stringify: bool = False, | ||
compression_level: int = 3, | ||
data_url_prefix: str = "data:base64,", | ||
) -> bytes: | ||
"""Given a binary, compress and optionally base64 encode. | ||
Parameters | ||
---------- | ||
input: bytes | ||
Input binary | ||
stringify: bool, optional | ||
Stringify the output | ||
compression_level: int, optional | ||
Compression level, typically 1-9 | ||
data_url_prefix: str, optional | ||
dataURL prefix | ||
Returns | ||
------- | ||
bytes | ||
Output compressed binary | ||
""" | ||
func = environment_dispatch("itkwasm_compress_stringify", "compress_stringify") | ||
output = func(input, stringify=stringify, compression_level=compression_level, data_url_prefix=data_url_prefix) | ||
return output |
33 changes: 33 additions & 0 deletions
33
...y/python/itkwasm-compress-stringify/itkwasm_compress_stringify/parse_string_decompress.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# Generated file. Do not edit. | ||
|
||
from itkwasm import ( | ||
environment_dispatch, | ||
BinaryStream, | ||
) | ||
|
||
def parse_string_decompress( | ||
input: bytes, | ||
parse_string: bool = False, | ||
) -> bytes: | ||
"""Given a binary or string produced with compress-stringify, decompress and optionally base64 decode. | ||
Parameters | ||
---------- | ||
input: bytes | ||
Compressed input | ||
parse_string: bool, optional | ||
Parse the input string before decompression | ||
Returns | ||
------- | ||
bytes | ||
Output decompressed binary | ||
""" | ||
func = environment_dispatch("itkwasm_compress_stringify", "parse_string_decompress") | ||
output = func(input, parse_string=parse_string) | ||
return output |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...gify-wasi/test/test_compress_stringify.py → ...stringify/test/test_compress_stringify.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.