Skip to content

Commit

Permalink
update USE_CYTHON logic in setup (#39)
Browse files Browse the repository at this point in the history
* update USE_CYTHON logic in setup

* scalar atol

* tweak path under setup

* pep8 warning

* py3

* wkhtmltopdf

* strip Qt5

* rendering

* chmod+x

* imagemagick-6 secuirty policy...

* skip git repo zip install test
  • Loading branch information
bjodah authored Mar 5, 2020
1 parent d106e5c commit be8b5ce
Show file tree
Hide file tree
Showing 8 changed files with 71 additions and 21 deletions.
6 changes: 3 additions & 3 deletions .drone.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ clone:
external/anyode: git://github.com/bjodah/anyode.git

build:
image: bjodah/bjodahimg18dev:v4.0.1
image: bjodah/bjodahimg20dev:v1.0.2
environment:
- ASAN_SYMBOLIZER_PATH=/usr/lib/llvm-8/bin/llvm-symbolizer
- ASAN_SYMBOLIZER_PATH=/usr/lib/llvm-10/bin/llvm-symbolizer
- ASAN_OPTIONS=symbolize=1
- CPLUS_INCLUDE_PATH=/opt/boost_1_72_p/include
commands:
- strip --remove-section=.note.ABI-tag /usr/lib/x86_64-linux-gnu/libQt5Core.so.5 # stackoverflow.com/questions/54582864/
- ./scripts/ci.sh pyodeint
- ./scripts/prepare_deploy.sh
- PATH=/opt/miniconda3/bin:$PATH conda build conda-recipe
- bash -c '[[ $(python3 setup.py --version) =~ ^[0-9]+.* ]]'
- if grep "DO-NOT-MERGE!" -R . --exclude ".drone.yml"; then exit 1; fi

Expand Down
16 changes: 7 additions & 9 deletions scripts/ci.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,14 @@ if [[ "$CI_BRANCH" =~ ^v[0-9]+.[0-9]?* ]]; then
echo ${CI_BRANCH} | tail -c +2 > __conda_version__.txt
fi

cd tests/; make CXX=clang++-10 EXTRA_FLAGS=-fsanitize=address; make clean; cd -
cd tests/; make CXX=clang++-10 EXTRA_FLAGS=-fsanitize=undefined; make clean; cd -

export CC=gcc-10
export CXX=g++-10

cd tests/; make EXTRA_FLAGS=-D_GLIBCXX_DEBUG; make clean; cd -
cd tests/; make EXTRA_FLAGS=-DNDEBUG; make clean; cd -
cd tests/; make CXX=clang++-8 EXTRA_FLAGS=-fsanitize=address; make clean; cd -
cd tests/; make CXX=clang++-8 EXTRA_FLAGS=-fsanitize=undefined; make clean; cd -

python3 setup.py sdist
python3 -m pip install --ignore-installed dist/*.tar.gz
Expand All @@ -17,12 +21,6 @@ python3 -m pip install --user -e .[all]
PYTHON=python3 ./scripts/run_tests.sh --cov $PKG_NAME --cov-report html
./scripts/coverage_badge.py htmlcov/ htmlcov/coverage.svg

(cd examples/; jupyter nbconvert --debug --to=html --ExecutePreprocessor.enabled=True --ExecutePreprocessor.timeout=300 *.ipynb)
./scripts/render_notebooks.sh examples/
(cd examples/; ../scripts/render_index.sh *.html)
./scripts/generate_docs.sh


# Make sure repo is pip installable from git-archive zip
git archive -o /tmp/$PKG_NAME.zip HEAD
python3 -m pip install --force-reinstall /tmp/$PKG_NAME.zip
(cd /; python3 -c "from ${PKG_NAME} import get_include as gi; import os; assert 'odeint_anyode_nogil.pxd' in os.listdir(gi())")
2 changes: 1 addition & 1 deletion scripts/coverage_badge.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

"""
Expand Down
2 changes: 1 addition & 1 deletion scripts/generate_docs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
NARGS=$#
PKG=$(find . -maxdepth 2 -name __init__.py -print0 | xargs -0 -n1 dirname | xargs basename)
AUTHOR=$(head -n 1 AUTHORS)
sphinx-apidoc --full --force -A "$AUTHOR" --module-first --doc-version=$(python setup.py --version) -F -o doc $PKG/ $(find . -type d -name tests)
sphinx-apidoc --full --force -A "$AUTHOR" --module-first --doc-version=$(python3 setup.py --version) -F -o doc $PKG/ $(find . -type d -name tests)
#sed -i 's/Contents/.. include:: ..\/README.rst\n\nContents/g' doc/index.rst
#echo ".. include:: ../README.rst" >>doc/index.rst
cat <<EOF >>doc/index.rst
Expand Down
2 changes: 1 addition & 1 deletion scripts/render_index.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ cat <<EOF>index.html
EOF
for f in $@; do
img=$(basename $f .html).png
QT_QPA_PLATFORM=offscreen phantomjs $(unset CDPATH && cd "$(dirname "$0")" && echo $PWD)/rasterize.js $f $tmpdir/$img 1200px*900px
wkhtmltopdf $f $tmpdir/$img # --crop-w 1200px --crop-h 900px
convert $tmpdir/$img -resize 400x300 thumbs/$img
cat <<EOF>>index.html
<p style='text-align: center'>
Expand Down
37 changes: 37 additions & 0 deletions scripts/render_notebooks.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/bin/bash -e
QUIET_EXIT_CODE=0
function quiet_unless_fail {
# suppresses function output unless exit status is != 0
OUTPUT_FILE=$(tempfile)
#/bin/rm --force /tmp/suppress.out 2>/dev/null
EXECMD=${1+"$@"}
$EXECMD > ${OUTPUT_FILE} 2>&1
QUIET_EXIT_CODE=$?
if [ ${QUIET_EXIT_CODE} -ne 0 ]; then
cat ${OUTPUT_FILE}
echo "The following command exited with exit status ${QUIET_EXIT_CODE}: ${EXECMD}"
/bin/rm ${OUTPUT_FILE}
fi
/bin/rm ${OUTPUT_FILE}
}

if [ -f index.ipynb ]; then
sed -i.bak0 's/ipynb/html/' index.ipynb
sed -i.bak1 's/filepath=index.html/filepath=index.ipynb/' index.ipynb # mybinder link fix
fi
set +e
for dir in $@; do
cd $dir
for fname in *.ipynb; do
echo "rendering ${fname}..."
quiet_unless_fail jupyter nbconvert --debug --to=html --ExecutePreprocessor.enabled=True --ExecutePreprocessor.timeout=300 "${fname}" \
| grep -v -e "^\[NbConvertApp\] content: {'data':.*'image/png'"
if [ ${QUIET_EXIT_CODE} -ne 0 ]; then
exit ${QUIET_EXIT_CODE}
fi
done
cd -
done
set -e
cd examples/
../scripts/render_index.sh *.html
25 changes: 20 additions & 5 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,38 @@
import warnings
from setuptools import setup
from setuptools.extension import Extension

try:
import cython
except ImportError:
_HAVE_CYTHON = False
else:
_HAVE_CYTHON = True
assert cython # silence pep8

pkg_name = 'pyodeint'


def _path_under_setup(*args):
return os.path.join(os.path.dirname(__file__), *args)
return os.path.join(*args)

_src = {ext: _path_under_setup(pkg_name, '_odeint.' + ext) for ext in "cpp pyx".split()}
if _HAVE_CYTHON and os.path.exists(_src["pyx"]):
# Possible that a new release of Python needs a re-rendered Cython source,
# or that we want to include possible bug-fix to Cython, disable by manually
# deleting .pyx file from source distribution.
USE_CYTHON = True
if os.path.exists(_src['cpp']):
os.unlink(_src['cpp']) # ensure c++ source is re-generated.
else:
USE_CYTHON = False

USE_CYTHON = not os.path.exists(_path_under_setup('pyodeint', '_odeint.cpp'))
package_include = os.path.join(pkg_name, 'include')

ext_modules = []
if len(sys.argv) > 1 and '--help' not in sys.argv[1:] and sys.argv[1] not in (
'--help-commands', 'egg_info', 'clean', '--version'):
import numpy as np
ext = '.pyx' if USE_CYTHON else '.cpp'
sources = [os.path.join(pkg_name, '_odeint' + ext)]
sources = [_src["pyx" if USE_CYTHON else "cpp"]]
ext_modules = [Extension('%s._odeint' % pkg_name, sources)]
if USE_CYTHON:
from Cython.Build import cythonize
Expand Down
2 changes: 1 addition & 1 deletion tests/test_odeint_anyode_parallel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ TEST_CASE( "decay_adaptive", "[multi_adaptive]" ) {
std::vector<double> dx_max {{ 2.0, 2.0 }};

auto result = odeint_anyode_parallel::multi_adaptive(
systems, {1e-10}, 1e-10, odeint_anyode::StepType::bulirsch_stoer, &y0[0], &t0[0],
systems, 1e-10, 1e-10, odeint_anyode::StepType::bulirsch_stoer, &y0[0], &t0[0],
&tend[0], mxsteps, &dx0[0], &dx_max[0]);
for (int idx=0; idx<2; ++idx){
const auto& tout = result[idx].first;
Expand Down

0 comments on commit be8b5ce

Please sign in to comment.