* feat: add Pyodide support Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com> Co-authored-by: Hood Chatham <roberthoodchatham@gmail.com> Co-authored-by: Matthieu Darbois <mayeut@users.noreply.github.com> tests: fix two merge issues Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com> fix: include schema Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com> * Try to fix xbuildenv path [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci Try to install pyodide-build from main branch Try again Try again Update constraints file Try again Remove unused variable Drop constraints Remove --download option Fix xbuildenv install Try again Try again [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * fix: remove pinning on pyodide Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com> * Update for Pyodide 0.26.0a5 * Install pyodide-build from pypi * Update docs/options.md Co-authored-by: Henry Schreiner <HenrySchreinerIII@gmail.com> * Unxfail things that look like they were just a version mismatch * refactor: add constraints for pyodide Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com> * chore: minor cleanup Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com> * Apply suggestions from code review * Apply suggestion from code review * refactor: minor touchup Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com> * ci: xfail the pyodide test Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com> * review: use a pinned version of node * fix tests * review: error out on Windows * test: check node & test on macos arm64 * chore: minor cleanup * Add reference to emscripten libc issue * Apply suggestion from code review * review: use a pinned pip in test virtual environment * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * chore: rework test virtual environment seed packages * chore: workaround direct invocation of pytest This allows to still test direct invocation of `pytest` on most platforms (including pyodide on Linux) but falls back to `python -m pytest` when running pyodide on macOS. * Use release version of pyodide * fix: tests for 0.26.0 & parallel initialization of xbuildenv * Debug CI * fix: test/test_build_frontend_args.py * Revert "Debug CI" This reverts commit 917646cffc96dbfc619c47d1c03a828f447bcdb7. --------- Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com> Co-authored-by: Henry Schreiner <henryschreineriii@gmail.com> Co-authored-by: Matthieu Darbois <mayeut@users.noreply.github.com> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
110 lines
2.3 KiB
Python
110 lines
2.3 KiB
Python
from __future__ import annotations
|
|
|
|
import jinja2
|
|
|
|
from .base import TestProject
|
|
|
|
SPAM_C_TEMPLATE = r"""
|
|
#include <Python.h>
|
|
|
|
{{ spam_c_top_level_add }}
|
|
|
|
static PyObject *
|
|
spam_system(PyObject *self, PyObject *args)
|
|
{
|
|
const char *command;
|
|
int sts;
|
|
|
|
if (!PyArg_ParseTuple(args, "s", &command))
|
|
return NULL;
|
|
|
|
sts = system(command);
|
|
|
|
{{ spam_c_function_add | indent(4) }}
|
|
|
|
return PyLong_FromLong(sts);
|
|
}
|
|
|
|
/* Module initialization */
|
|
static PyMethodDef module_methods[] = {
|
|
{"system", (PyCFunction)spam_system, METH_VARARGS,
|
|
"Execute a shell command."},
|
|
{NULL} /* Sentinel */
|
|
};
|
|
|
|
PyMODINIT_FUNC PyInit_spam(void)
|
|
{
|
|
static struct PyModuleDef moduledef = {
|
|
PyModuleDef_HEAD_INIT, "spam", "Example module", -1, module_methods,
|
|
};
|
|
return PyModule_Create(&moduledef);
|
|
}
|
|
"""
|
|
|
|
SETUP_PY_TEMPLATE = r"""
|
|
import os
|
|
import sys
|
|
|
|
from setuptools import setup, Extension
|
|
|
|
{{ setup_py_add }}
|
|
|
|
libraries = []
|
|
# Emscripten fails if you pass -lc...
|
|
# See: https://github.com/emscripten-core/emscripten/issues/16680
|
|
if sys.platform.startswith('linux') and "emscripten" not in os.environ.get("_PYTHON_HOST_PLATFORM", ""):
|
|
libraries.extend(['m', 'c'])
|
|
|
|
|
|
setup(
|
|
ext_modules=[Extension(
|
|
'spam',
|
|
sources=['spam.c'],
|
|
libraries=libraries,
|
|
{{ setup_py_extension_args_add | indent(8) }}
|
|
)],
|
|
{{ setup_py_setup_args_add | indent(4) }}
|
|
)
|
|
"""
|
|
|
|
SETUP_CFG_TEMPLATE = r"""
|
|
[metadata]
|
|
name = spam
|
|
version = 0.1.0
|
|
|
|
{{ setup_cfg_add }}
|
|
"""
|
|
|
|
|
|
def new_c_project(
|
|
*,
|
|
spam_c_top_level_add="",
|
|
spam_c_function_add="",
|
|
setup_py_add="",
|
|
setup_py_extension_args_add="",
|
|
setup_py_setup_args_add="",
|
|
setup_cfg_add="",
|
|
):
|
|
project = TestProject()
|
|
|
|
project.files.update(
|
|
{
|
|
"spam.c": jinja2.Template(SPAM_C_TEMPLATE),
|
|
"setup.py": jinja2.Template(SETUP_PY_TEMPLATE),
|
|
"setup.cfg": jinja2.Template(SETUP_CFG_TEMPLATE),
|
|
}
|
|
)
|
|
|
|
project.template_context.update(
|
|
{
|
|
"spam_c_top_level_add": spam_c_top_level_add,
|
|
"spam_c_function_add": spam_c_function_add,
|
|
"setup_py_add": setup_py_add,
|
|
"setup_py_extension_args_add": setup_py_extension_args_add,
|
|
"setup_py_setup_args_add": setup_py_setup_args_add,
|
|
"setup_cfg_add": setup_cfg_add,
|
|
}
|
|
)
|
|
|
|
return project
|