diff --git a/test/13_subdir_package/bin/before_build.sh b/test/13_subdir_package/bin/before_build.sh new file mode 100755 index 00000000..3f77a8c5 --- /dev/null +++ b/test/13_subdir_package/bin/before_build.sh @@ -0,0 +1,3 @@ +#!/bin/bash + +echo 'before_build.sh executed.' diff --git a/test/13_subdir_package/cibuildwheel_test.py b/test/13_subdir_package/cibuildwheel_test.py new file mode 100644 index 00000000..27dc5842 --- /dev/null +++ b/test/13_subdir_package/cibuildwheel_test.py @@ -0,0 +1,23 @@ +import os +import platform + +import utils + +project_dir = os.path.dirname(__file__) + + +def test(): + package_dir = os.path.join(project_dir, 'src', 'spam') + # build the wheels + actual_wheels = utils.cibuildwheel_run(project_dir, package_dir=package_dir, add_env={ + 'CIBW_BEFORE_BUILD': '{project}/bin/before_build.sh', + 'CIBW_TEST_COMMAND': 'python {package}/test/run_tests.py', + # this shouldn't depend on the version of python, so build only + # CPython 3.6 + 'CIBW_BUILD': 'cp36-*', + }) + + # check that the expected wheels are produced + expected_wheels = [w for w in utils.expected_wheels('spam', '0.1.0') + if 'cp36' in w] + assert set(actual_wheels) == set(expected_wheels) diff --git a/test/13_subdir_package/src/spam/setup.py b/test/13_subdir_package/src/spam/setup.py new file mode 100644 index 00000000..637d7ff0 --- /dev/null +++ b/test/13_subdir_package/src/spam/setup.py @@ -0,0 +1,8 @@ +from setuptools import Extension, setup + + +setup( + name="spam", + ext_modules=[Extension('spam', sources=['spam.c'])], + version="0.1.0", +) diff --git a/test/13_subdir_package/src/spam/spam.c b/test/13_subdir_package/src/spam/spam.c new file mode 100644 index 00000000..d1ab0f22 --- /dev/null +++ b/test/13_subdir_package/src/spam/spam.c @@ -0,0 +1,48 @@ +#include + +static PyObject * +spam_system(PyObject *self, PyObject *args) +{ + const char *command; + int sts; + + if (!PyArg_ParseTuple(args, "s", &command)) + return NULL; + sts = system(command); + return PyLong_FromLong(sts); +} + +/* Module initialization */ + +#if PY_MAJOR_VERSION >= 3 + #define MOD_INIT(name) PyMODINIT_FUNC PyInit_##name(void) + #define MOD_DEF(m, name, doc, methods, module_state_size) \ + static struct PyModuleDef moduledef = { \ + PyModuleDef_HEAD_INIT, name, doc, module_state_size, methods, }; \ + m = PyModule_Create(&moduledef); + #define MOD_RETURN(m) return m; +#else + #define MOD_INIT(name) PyMODINIT_FUNC init##name(void) + #define MOD_DEF(m, name, doc, methods, module_state_size) \ + m = Py_InitModule3(name, methods, doc); + #define MOD_RETURN(m) return; +#endif + +static PyMethodDef module_methods[] = { + {"system", (PyCFunction)spam_system, METH_VARARGS, + "Execute a shell command."}, + {NULL} /* Sentinel */ +}; + +MOD_INIT(spam) +{ + PyObject* m; + + MOD_DEF(m, + "spam", + "Example module", + module_methods, + -1) + + MOD_RETURN(m) +} diff --git a/test/13_subdir_package/src/spam/test/run_tests.py b/test/13_subdir_package/src/spam/test/run_tests.py new file mode 100644 index 00000000..abaa183d --- /dev/null +++ b/test/13_subdir_package/src/spam/test/run_tests.py @@ -0,0 +1 @@ +print('run_tests.py called!') diff --git a/test/shared/utils.py b/test/shared/utils.py index d1e1f0a1..609ab9d7 100644 --- a/test/shared/utils.py +++ b/test/shared/utils.py @@ -41,13 +41,15 @@ def cibuildwheel_get_build_identifiers(project_path, env=None): return cmd_output.strip().split('\n') -def cibuildwheel_run(project_path, env=None, add_env=None, output_dir=None): +def cibuildwheel_run(project_path, package_dir='.', env=None, add_env=None, output_dir=None): ''' Runs cibuildwheel as a subprocess, building the project at project_path. Uses the current Python interpreter. :param project_path: path of the project to be built. + :param package_dir: path of the package to be built. Can be absolute, or + relative to project_path. :param env: full environment to be used, os.environ if None :param add_env: environment used to update env :param output_dir: directory where wheels are saved. If None, a temporary @@ -64,7 +66,7 @@ def cibuildwheel_run(project_path, env=None, add_env=None, output_dir=None): with TemporaryDirectoryIfNone(output_dir) as _output_dir: subprocess.check_call( - [sys.executable, '-m', 'cibuildwheel', '--output-dir', str(_output_dir)], + [sys.executable, '-m', 'cibuildwheel', '--output-dir', str(_output_dir), package_dir], env=env, cwd=project_path, )