Added test for environment and a script for local running
This commit is contained in:
+2
-2
@@ -9,9 +9,9 @@ script:
|
|||||||
- |
|
- |
|
||||||
if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then
|
if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then
|
||||||
pip install .
|
pip install .
|
||||||
python ./run_tests.py
|
python ./bin/run_tests.py
|
||||||
else
|
else
|
||||||
# linux test requires root to clean up the wheelhouse (docker runs as root)
|
# linux test requires root to clean up the wheelhouse (docker runs as root)
|
||||||
sudo pip install .
|
sudo pip install .
|
||||||
sudo python ./run_tests.py
|
sudo python ./bin/run_tests.py
|
||||||
fi
|
fi
|
||||||
|
|||||||
+1
-1
@@ -1,3 +1,3 @@
|
|||||||
build_script:
|
build_script:
|
||||||
- pip install .
|
- pip install .
|
||||||
- python ./run_tests.py
|
- python ./bin/run_tests.py
|
||||||
|
|||||||
Executable
+6
@@ -0,0 +1,6 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
cd "$(dirname "$0")"
|
||||||
|
cd ..
|
||||||
|
|
||||||
|
CIBW_PLATFORM=linux ./bin/run_test.py $1
|
||||||
Executable
+45
@@ -0,0 +1,45 @@
|
|||||||
|
#!/usr/bin/python
|
||||||
|
|
||||||
|
from __future__ import print_function
|
||||||
|
import os, sys, subprocess, shutil, json, argparse
|
||||||
|
from glob import glob
|
||||||
|
|
||||||
|
def main():
|
||||||
|
parser = argparse.ArgumentParser()
|
||||||
|
parser.add_argument("test_project_dir")
|
||||||
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
test_project = os.path.abspath(args.test_project_dir)
|
||||||
|
|
||||||
|
# move cwd to the project root
|
||||||
|
os.chdir(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
||||||
|
|
||||||
|
if not os.path.exists(test_project):
|
||||||
|
print('No test project not found.', file=sys.stderr)
|
||||||
|
exit(2)
|
||||||
|
|
||||||
|
# load project settings into environment
|
||||||
|
env_file = os.path.join(test_project, 'environment.json')
|
||||||
|
project_env = {}
|
||||||
|
if os.path.exists(env_file):
|
||||||
|
with open(env_file) as f:
|
||||||
|
project_env = json.load(f)
|
||||||
|
|
||||||
|
# run the build
|
||||||
|
env = os.environ.copy()
|
||||||
|
project_env = {str(k): str(v) for k, v in project_env.items()} # unicode not allowed in env
|
||||||
|
env.update(project_env)
|
||||||
|
print('Building %s with environment %s' % (test_project, project_env))
|
||||||
|
subprocess.check_call(['cibuildwheel', test_project], env=env)
|
||||||
|
wheels = glob('wheelhouse/*.whl')
|
||||||
|
print('%s built successfully. %i wheels built.' % (test_project, len(wheels)))
|
||||||
|
|
||||||
|
# check some wheels were actually built
|
||||||
|
assert len(wheels) >= 4
|
||||||
|
|
||||||
|
# clean up
|
||||||
|
shutil.rmtree('wheelhouse')
|
||||||
|
|
||||||
|
print('Project built successfully.')
|
||||||
|
|
||||||
|
main()
|
||||||
Regular → Executable
+3
-1
@@ -1,9 +1,11 @@
|
|||||||
|
#!/usr/bin/python
|
||||||
|
|
||||||
from __future__ import print_function
|
from __future__ import print_function
|
||||||
import os, sys, subprocess, shutil, json
|
import os, sys, subprocess, shutil, json
|
||||||
from glob import glob
|
from glob import glob
|
||||||
|
|
||||||
# move cwd to the project root
|
# move cwd to the project root
|
||||||
os.chdir(os.path.dirname(os.path.abspath(__file__)))
|
os.chdir(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
||||||
|
|
||||||
test_projects = glob('test/??_*')
|
test_projects = glob('test/??_*')
|
||||||
|
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"CIBW_ENVIRONMENT": "CIBW_TEST_VAR=\"a b c\" CIBW_TEST_VAR_2=1"
|
||||||
|
}
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
from setuptools import setup, Extension
|
||||||
|
import sys, os
|
||||||
|
|
||||||
|
if sys.argv[-1] != '--name':
|
||||||
|
# explode if environment isn't correct, as set in CIBW_ENVIRONMENT
|
||||||
|
CIBW_TEST_VAR = os.environ.get('CIBW_TEST_VAR')
|
||||||
|
CIBW_TEST_VAR_2 = os.environ.get('CIBW_TEST_VAR_2')
|
||||||
|
|
||||||
|
if CIBW_TEST_VAR != 'a b c':
|
||||||
|
raise Exception('CIBW_TEST_VAR should equal "a b c". It was "%s"' % CIBW_TEST_VAR)
|
||||||
|
if CIBW_TEST_VAR_2 != '1':
|
||||||
|
raise Exception('CIBW_TEST_VAR_2 should equal "1". It was "%s"' % CIBW_TEST_VAR_2)
|
||||||
|
|
||||||
|
setup(
|
||||||
|
name="spam",
|
||||||
|
ext_modules=[Extension('spam', sources=['spam.c'])],
|
||||||
|
version="0.1.0",
|
||||||
|
)
|
||||||
@@ -0,0 +1,48 @@
|
|||||||
|
#include <Python.h>
|
||||||
|
|
||||||
|
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)
|
||||||
|
}
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
3.6.0 (default, Feb 7 2017, 23:55:32)
|
||||||
|
[GCC 4.8.2 20140120 (Red Hat 4.8.2-15)]
|
||||||
Reference in New Issue
Block a user