From 1ca41e5bdf7994b76c11b2892e38abc7f2edd694 Mon Sep 17 00:00:00 2001 From: Volodymyr Shymanskyy Date: Tue, 19 Jan 2021 22:28:53 +0200 Subject: [PATCH] Publish pywasm3 to pypi --- .github/workflows/tests.yml | 6 +++--- platforms/python/LICENSE | 21 ++++++++++++++++++++ platforms/python/README.md | 34 ++++++++++++++++++++++++++++++++ platforms/python/m3module.c | 22 ++++++++++----------- platforms/python/setup.py | 30 ++++++++++++++++++++++++---- platforms/python/test/test_m3.py | 2 +- 6 files changed, 96 insertions(+), 19 deletions(-) create mode 100644 platforms/python/LICENSE create mode 100644 platforms/python/README.md diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 0ce5e98..7c1d220 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -516,8 +516,8 @@ jobs: run: | cd platforms/python python setup.py sdist - pip install ./dist/wasm3-*.tar.gz - - name: Test with pytest + pip install ./dist/pywasm3-*.tar.gz + - name: Test run: | pip install pytest - pytest platforms/python/test + pytest platforms/python diff --git a/platforms/python/LICENSE b/platforms/python/LICENSE new file mode 100644 index 0000000..5276280 --- /dev/null +++ b/platforms/python/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2019 Volodymyr Shymanskyy + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/platforms/python/README.md b/platforms/python/README.md new file mode 100644 index 0000000..aa8fe30 --- /dev/null +++ b/platforms/python/README.md @@ -0,0 +1,34 @@ +# pywasm3 + +Python binding for Wasm3, the fastest WebAssembly interpreter. + +## Install + +```sh +pip3 install pywasm3 +``` + +## Usage example + +```py +import wasm3 + +# WebAssembly binary +WASM = bytes.fromhex(""" + 00 61 73 6d 01 00 00 00 01 06 01 60 01 7e 01 7e + 03 02 01 00 07 07 01 03 66 69 62 00 00 0a 1f 01 + 1d 00 20 00 42 02 54 04 40 20 00 0f 0b 20 00 42 + 02 7d 10 00 20 00 42 01 7d 10 00 7c 0f 0b +""") + +env = wasm3.Environment() +rt = env.new_runtime(1024) +mod = env.parse_module(WASM) +rt.load(mod) +func = rt.find_function("fib") +result = func.call_argv("24") +print(result) # 46368 +``` + +### License +This project is released under The MIT License (MIT) diff --git a/platforms/python/m3module.c b/platforms/python/m3module.c index b5fda11..2b30334 100644 --- a/platforms/python/m3module.c +++ b/platforms/python/m3module.c @@ -88,7 +88,7 @@ static PyMethodDef M3_Environment_methods[] = { }; static PyType_Slot M3_Environment_Type_slots[] = { - {Py_tp_doc, "The m3.Environment type"}, + {Py_tp_doc, "The wasm3.Environment type"}, {Py_tp_finalize, delEnvironment}, {Py_tp_new, newEnvironment}, {Py_tp_methods, M3_Environment_methods}, @@ -150,7 +150,7 @@ static PyMethodDef M3_Runtime_methods[] = { }; static PyType_Slot M3_Runtime_Type_slots[] = { - {Py_tp_doc, "The m3.Runtime type"}, + {Py_tp_doc, "The wasm3.Runtime type"}, // {Py_tp_finalize, delRuntime}, // {Py_tp_new, newRuntime}, {Py_tp_methods, M3_Runtime_methods}, @@ -169,7 +169,7 @@ static PyGetSetDef M3_Module_properties[] = { }; static PyType_Slot M3_Module_Type_slots[] = { - {Py_tp_doc, "The m3.Module type"}, + {Py_tp_doc, "The wasm3.Module type"}, // {Py_tp_finalize, delModule}, // {Py_tp_new, newModule}, // {Py_tp_methods, M3_Module_methods}, @@ -280,7 +280,7 @@ M3_Function_call(m3_function *self, PyObject *args, PyObject *kwargs) } static PyType_Slot M3_Function_Type_slots[] = { - {Py_tp_doc, "The m3.Function type"}, + {Py_tp_doc, "The wasm3.Function type"}, // {Py_tp_finalize, delFunction}, // {Py_tp_new, newFunction}, {Py_tp_call, M3_Function_call}, @@ -290,7 +290,7 @@ static PyType_Slot M3_Function_Type_slots[] = { }; static PyType_Spec M3_Environment_Type_spec = { - "m3.Environment", + "wasm3.Environment", sizeof(m3_environment), 0, Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC, @@ -298,7 +298,7 @@ static PyType_Spec M3_Environment_Type_spec = { }; static PyType_Spec M3_Runtime_Type_spec = { - "m3.Runtime", + "wasm3.Runtime", sizeof(m3_runtime), 0, Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC, @@ -306,7 +306,7 @@ static PyType_Spec M3_Runtime_Type_spec = { }; static PyType_Spec M3_Module_Type_spec = { - "m3.Module", + "wasm3.Module", sizeof(m3_module), 0, Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC, @@ -314,7 +314,7 @@ static PyType_Spec M3_Module_Type_spec = { }; static PyType_Spec M3_Function_Type_spec = { - "m3.Function", + "wasm3.Function", sizeof(m3_function), 0, Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC, @@ -353,11 +353,11 @@ static PyModuleDef_Slot m3_slots[] = { }; PyDoc_STRVAR(m3_doc, -"m3 - wasm3 bindings"); +"wasm3 python bindings"); static struct PyModuleDef m3module = { PyModuleDef_HEAD_INIT, - "m3", + "wasm3", m3_doc, 0, 0, // methods @@ -368,7 +368,7 @@ static struct PyModuleDef m3module = { }; PyMODINIT_FUNC -PyInit_m3(void) +PyInit_wasm3(void) { return PyModuleDef_Init(&m3module); } diff --git a/platforms/python/setup.py b/platforms/python/setup.py index 221d1a9..f711b63 100644 --- a/platforms/python/setup.py +++ b/platforms/python/setup.py @@ -1,13 +1,35 @@ from setuptools import setup from distutils.core import Extension from glob import glob +from pathlib import Path + +HERE = Path(__file__).parent SOURCES = glob('m3/*.c') + ['m3module.c'] setup( - name='wasm3', - version='0.0.1', + name = "pywasm3", + version = "0.0.2", + description = "The fastest WebAssembly interpreter", + platforms = "any", + url = "https://github.com/wasm3/wasm3", + license = "MIT", + author = "Volodymyr Shymanskyy", + author_email = "vshymanskyi@gmail.com", + + long_description = (HERE / "README.md").read_text(), + long_description_content_type = "text/markdown", + ext_modules=[ - Extension('m3', sources=SOURCES, include_dirs=['m3'], - extra_compile_args=['-g', '-O0'])] + Extension('wasm3', sources=SOURCES, include_dirs=['m3'], + extra_compile_args=['-g', '-O0'])], + + classifiers = [ + "Topic :: Software Development :: Libraries :: Python Modules", + "Development Status :: 4 - Beta", + "License :: OSI Approved :: MIT License", + "Operating System :: POSIX :: Linux", + "Operating System :: Microsoft :: Windows", + "Operating System :: MacOS :: MacOS X" + ] ) diff --git a/platforms/python/test/test_m3.py b/platforms/python/test/test_m3.py index 9d751f3..c9b3289 100644 --- a/platforms/python/test/test_m3.py +++ b/platforms/python/test/test_m3.py @@ -1,4 +1,4 @@ -import m3 +import wasm3 as m3 FIB32_WASM = bytes.fromhex( "00 61 73 6d 01 00 00 00 01 06 01 60 01 7f 01 7f"