Skip to content

Commit

Permalink
Merge pull request #18 from bjodah/cythonize-rel-path
Browse files Browse the repository at this point in the history
Tweak setup.py
  • Loading branch information
bjodah authored Dec 14, 2016
2 parents de1462d + 454d4b0 commit d89c63f
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 22 deletions.
6 changes: 3 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ dist: trusty
language: generic
before_install:
- sudo apt-get install -qq gfortran g++ python-pip python-numpy python-argh python-pytest python-pip python-dev
- sudo pip install pycompilation
- sudo pip install Cython --install-option="--no-cython-compile"
- python -m pip install --user pycompilation
- python -m pip install --user Cython --install-option="--no-cython-compile"
install:
- python setup.py build_ext --inplace
- export PYTHONPATH=.:$PYTHONPATH
# command to run tests
script:
- PYTHONPATH=$(pwd) py.test
- PYTHONPATH=$(pwd) python -m pytest
- FINITEDIFF_USE_FORTRAN=1 python setup.py build_ext --inplace
- rm finitediff/*templated*.so
- PYTHONPATH=$(pwd) py.test
Expand Down
2 changes: 1 addition & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
graft finitediff/external
recursive-include finitediff/include *.hpp *.h *.pxd
recursive-include finitediff/external *.c *.h
include AUTHORS
include CHANGES.rst
include LICENSE
Expand Down
1 change: 1 addition & 0 deletions finitediff/_finitediff_fort.pyx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# -*- coding: utf-8 -*-
# distutils: sources = ['src/finitediff_fort.f90', 'src/c_finitediff_fort.f90', 'finitediff/external/newton_interval/src/newton_interval.c']

# For wrapping src/finitediff_fort.f90

Expand Down
1 change: 1 addition & 0 deletions finitediff/_finitediff_templated.pyx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# -*- coding: utf-8 -*-
# distutils: language = c++
# distutils: sources = ['finitediff/external/newton_interval/src/newton_interval.c']

# For wrapping finitediff_templated.h

Expand Down
35 changes: 17 additions & 18 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
import os
import pprint
import re
import sys
import shutil
import subprocess
import sys
import warnings

from setuptools import setup
Expand Down Expand Up @@ -64,24 +64,23 @@ def _path_under_setup(*args):

if _USE_FORTRAN:
interface = 'fort'
sources = [
other_sources = [
os.path.join('src', 'finitediff_fort.f90'),
os.path.join('src', 'c_finitediff_fort.f90'),
]
else:
interface = 'templated'
sources = []
other_sources = []

USE_CYTHON = os.path.exists(_path_under_setup('finitediff', '_finitediff_'+interface+'.pyx'))
ext = '.pyx' if USE_CYTHON else ('.c' if _USE_FORTRAN else '.cpp')


sources += [
'finitediff/external/newton_interval/src/newton_interval.c',
'finitediff/_finitediff_' + interface + ext
modname = 'finitediff._finitediff_' + interface
srcname = os.path.join('finitediff', '_finitediff_' + interface)
other_sources += [
os.path.join('finitediff', 'external', 'newton_interval', 'src', 'newton_interval.c')
]


cmdclass = {}
ext_modules = []
if len(sys.argv) > 1 and '--help' not in sys.argv[1:] and sys.argv[1] not in (
Expand All @@ -101,8 +100,8 @@ def _path_under_setup(*args):
cmdclass = {'build_ext': pc_build_ext}
ext_modules = [
PCExtension(
'finitediff._finitediff_'+interface,
sources=sources,
modname,
sources=[srcname+ext] + other_sources,
pycompilation_compile_kwargs={
'per_file_kwargs': {
ArbitraryDepthGlob(b'*.c'): {'std': 'c99'}
Expand All @@ -116,17 +115,17 @@ def _path_under_setup(*args):
else:
# default path (no external dependencies):
from setuptools.extension import Extension
modname = '_finitediff_'+interface
ext_modules = [
Extension('finitediff.'+modname,
sources,
language='c++',
include_dirs=include_dirs)
Extension(modname, [srcname+ext], include_dirs=include_dirs)
]
if USE_CYTHON:
from Cython.Build import cythonize
ext_modules = cythonize(ext_modules, include_path=include_dirs,
gdb_debug=True)
ext_modules = cythonize(ext_modules, include_path=include_dirs, gdb_debug=True)
else:
ext_modules[0].sources += other_sources

if ext_modules[0].sources[0].startswith('/'):
raise ValueError("Absolute path not allowed: %s" % ext_modules[0].sources[0])

tests = [
pkg_name + '.tests',
Expand Down Expand Up @@ -166,7 +165,7 @@ def _path_under_setup(*args):
cmdclass=cmdclass,
ext_modules=ext_modules,
classifiers=classifiers,
setup_requires=['cython'] if USE_CYTHON else [],
setup_requires=['numpy'] + (['cython'] if USE_CYTHON else []),
install_requires=['numpy'],
extras_require={'all': ['pytest', 'sphinx', 'sphinx_rtd_theme', 'numpydoc']}
)
Expand Down

0 comments on commit d89c63f

Please sign in to comment.