Skip to content

Commit 9477bcc

Browse files
committed
Merge remote-tracking branch 'upstream/master'
2 parents 4759764 + d2baf02 commit 9477bcc

25 files changed

+254
-66
lines changed

Diff for: .gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,5 @@
33
*.so
44
*.pyd
55
build
6+
dist
7+
MANIFEST

Diff for: MANIFEST.in

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
include MANIFEST.in
2+
include sode/cfiles/build.sh
3+
recursive-include sode *.pxd *.c *.h
4+
include addpath.sh
5+
include addpath.bat

Diff for: scripts/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
sode-cexamples*

Diff for: scripts/sode

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
#!/bin/sh
1+
#!/usr/bin/env python
22
# copyright Oscar Benjamin 2011
33
#
44
# run sode as a python script.
5-
python -m sode.weiners $@
5+
import sys
6+
from sode.weiners import main
7+
main(sys.argv[1:])

Diff for: scripts/sode-cyexamples

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/usr/bin/env python
2+
#
3+
# executable front end to the sode.examples.cyexamples module
4+
import sys
5+
from sode.examples.cyexamples import main
6+
main(sys.argv[1:])

Diff for: scripts/sode-cyexamples.bat

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
@echo off
2+
REM copyright Oscar Benjamin 2011
3+
REM
4+
REM run sode as a python script.
5+
REM
6+
REM Because of:
7+
REM STDIN/STDOUT Redirection May Not Work If Started from a File Association
8+
REM http://support.microsoft.com/kb/321788
9+
REM http://bugs.python.org/issue1012692
10+
python -m sode.examples.cyexamples %*

Diff for: scripts/sode-pyexamples

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/usr/bin/env python
2+
#
3+
# executable front end to the sode.examples.pyexamples module
4+
import sys
5+
from sode.examples.pyexamples import main
6+
main(sys.argv[1:])

Diff for: scripts/sode-pyexamples.bat

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
@echo off
2+
REM copyright Oscar Benjamin 2011
3+
REM
4+
REM run sode as a python script.
5+
REM
6+
REM Because of:
7+
REM STDIN/STDOUT Redirection May Not Work If Started from a File Association
8+
REM http://support.microsoft.com/kb/321788
9+
REM http://bugs.python.org/issue1012692
10+
python -m sode.examples.pyexamples %*

Diff for: sode/examples/time.sh renamed to scripts/sode-time

+5-5
Original file line numberDiff line numberDiff line change
@@ -28,24 +28,24 @@ for sys in\
2828
echo ----------- Example $sys -----------
2929
echo
3030
echo ----- In Pure python $t2 secs
31-
time ./pyexamples.py solve --system-type=$sys --t1=$t1 --t2=$t2\
31+
time sode-pyexamples solve --system-type=$sys --t1=$t1 --t2=$t2\
3232
--dtmax=$dtmax --dtout=$dtout > .tmppy
3333
echo
3434
echo ----- In Cython $t2 secs
35-
time ./cyexamples.py solve --system-type=$sys --t1=$t1 --t2=$t2\
35+
time sode-cyexamples solve --system-type=$sys --t1=$t1 --t2=$t2\
3636
--dtmax=$dtmax --dtout=$dtout > .tmpcy
3737
echo
3838
echo ----- In Pure c $t2 secs
39-
time ./cexamples.exe $sys $t1 $t2 $dtmax $dtout > .tmpc
39+
time sode-cexamples $sys $t1 $t2 $dtmax $dtout > .tmpc
4040
echo
4141

4242
echo
4343
echo ----- In Cython $t2l secs
44-
time ./cyexamples.py solve --system-type=$sys --t1=$t1 --t2=$t2l\
44+
time sode-cyexamples solve --system-type=$sys --t1=$t1 --t2=$t2l\
4545
--dtmax=$dtmax --dtout=$dtout > .tmpcy
4646
echo
4747
echo ----- In Pure c $t2l secs
48-
time ./cexamples.exe $sys $t1 $t2l $dtmax $dtout > .tmpc
48+
time sode-cexamples $sys $t1 $t2l $dtmax $dtout > .tmpc
4949
echo
5050

5151
done

Diff for: setup.py

+186-24
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,204 @@
11
#!/usr/bin/env python
22
#
3-
# Copyright Oscar Benjamin 2011 under new BSD license
3+
# Copyright Oscar Benjamin 2011 under GPLv3+
44

55
import os, os.path, sys
66
from distutils.core import setup
77
from distutils.extension import Extension
8+
from distutils.command.build_ext import build_ext
9+
from distutils.cygwinccompiler import Mingw32CCompiler # ming32 fix
810

9-
from Cython.Distutils import build_ext
1011
import numpy
1112

12-
import sode
13+
14+
# Use Cython to generate the c-files if available
15+
#
16+
# The source distribution includes the generated c-files so someone can build
17+
# it without needing cython (although they still need a c-compiler).
18+
#
19+
# Ensuring that the c-files are distributed in the source distribution means
20+
# adding the c-files to MANIFEST.in and ensuring that the cython generated
21+
# c-files are up to date by remembering to do:
22+
#
23+
# $ python setup.py build_ext --inplace
24+
# $ python setup.py sdist
25+
#
26+
# See here:
27+
# http://stackoverflow.com/questions/4505747/how-should-i-structure-a-python-package-that-contains-cython-code
28+
try:
29+
from Cython.Distutils import build_ext
30+
except ImportError:
31+
use_cython = False
32+
else:
33+
use_cython = True
1334

1435

36+
# These data structures are conditional on
37+
# 1) Whether cython is installed (ext_modules, cmdclass)
38+
# 2) Whether running on Windows (scripts/*.bat)
39+
cmdclass = {}
40+
ext_modules = []
41+
scripts = []
42+
43+
44+
# :::::::::::::::::::::::::::::
45+
# Extension modules
46+
# :::::::::::::::::::::::::::::
47+
48+
# Need to add the .pyx name if compiling fully with cython or the .c name when
49+
# compiling from sdist without cython.
50+
def add_cython_ext_module(modname, cname, cnames=[], **kwargs):
51+
# Use cython to cythonise the .pyx files if possible
52+
if use_cython:
53+
cname = os.path.splitext(cname)[0] + '.pyx'
54+
ext_modules.append(Extension(modname, [cname] + cnames, **kwargs))
55+
56+
57+
# Need to link with libm and librt on posix but not on Windows.
1558
if not 'win' in sys.platform:
16-
libraries_cysode = ['m', 'rt']
17-
libraries_examples = ['m']
59+
libs_cysode = ['m', 'rt']
60+
libs_cyexamples = ['m']
61+
libs_cexamples = ['m', 'rt']
1862
else:
19-
libraries_cysode = libraries_examples = []
20-
21-
22-
ext_modules = [
23-
Extension(
24-
'sode.cysode',
25-
[os.path.join('sode', 'cysode.pyx'),
26-
os.path.join('sode', 'cfiles', 'randnorm.c')],
27-
include_dirs=[numpy.get_include(), '.'],
28-
libraries=libraries_cysode
29-
),
30-
Extension(
31-
'sode.examples.cyfiles.examples',
32-
[os.path.join('sode', 'examples', 'cyfiles', 'examples.pyx')],
33-
include_dirs=[numpy.get_include()],
34-
libraries = libraries_examples
35-
)
36-
]
63+
libs_cysode = []
64+
libs_cyexamples = []
65+
libs_cexamples = []
66+
67+
68+
# This extension module is a core part of sode
69+
add_cython_ext_module('sode.cysode',
70+
os.path.join('sode', 'cysode.c'),
71+
[os.path.join('sode', 'cfiles', 'randnorm.c')],
72+
include_dirs = [numpy.get_include(), '.'],
73+
libraries = libs_cysode,
74+
)
75+
76+
77+
# This extension module is for the examples
78+
add_cython_ext_module('sode.examples.cyexamples.examples',
79+
os.path.join('sode', 'examples', 'cyexamples', 'examples.c'),
80+
include_dirs = [numpy.get_include(), '.'],
81+
libraries = libs_cyexamples,
82+
)
83+
84+
85+
# ::::::::::::::::::::::::::::::::
86+
# Scripts
87+
# ::::::::::::::::::::::::::::::::
88+
89+
# Executable entry points in scripts
90+
scripts = ['sode', 'sode-pyexamples', 'sode-cyexamples']
91+
scripts_dir = 'scripts'
92+
93+
94+
# These .bat files are needed so that Windows users can run the scripts
95+
# without the .py extension. Giving the scripts .py extensions can cause
96+
# problems with stdin/stdout redirection on Windows
97+
# http://support.microsoft.com/default.aspx?kbid=321788
98+
if 'win' in sys.platform:
99+
scripts.extend([sname + '.bat' for sname in scripts])
100+
101+
scripts.append('sode-time')
102+
103+
scripts = [os.path.join(scripts_dir, sname) for sname in scripts]
37104

105+
106+
# ::::::::::::::::::::::::::::::::
107+
# Standalone c program
108+
# ::::::::::::::::::::::::::::::::
109+
110+
# monkey patch build_ext to also build a standalone c program
111+
# http://mail.python.org/pipermail/distutils-sig/2009-September/013216.html
112+
class MonkeyPatch_build_ext(build_ext):
113+
def run(self):
114+
global scripts
115+
build_ext.run(self)
116+
exe_name = build_examples_cprog(self.compiler)
117+
scripts.append(exe_name)
118+
119+
cmdclass['build_ext'] = MonkeyPatch_build_ext
120+
121+
122+
# We also need to build the examples c-program
123+
def build_examples_cprog(compiler):
124+
if isinstance(compiler, Mingw32CCompiler):
125+
mingw32_compiler_fix(compiler)
126+
127+
cfiles = ['main.c', 'examples.c', 'randnorm.c', 'solvers.c']
128+
cfiles = [os.path.join('sode', 'cfiles', p) for p in cfiles]
129+
exe_name = os.path.join(scripts_dir, 'sode-cexamples')
130+
131+
compiler.link_executable(cfiles, exe_name, libraries=libs_cexamples)
132+
133+
# compiler.exe_extension is None on posix, string on Windows
134+
if compiler.exe_extension is not None:
135+
exe_name += compiler.exe_extension
136+
137+
return exe_name
138+
139+
140+
# msvcr90 needs manifest etc. See:
141+
# http://developer.berlios.de/devlog/akruis/2012/06/10/msvcr90dll-and-mingw/
142+
# Since this is a standalone program we can just link against the old version
143+
# of msvcr.
144+
def mingw32_compiler_fix(compiler):
145+
for n, dllname in enumerate(compiler.dll_libraries):
146+
if dllname.startswith('msvcr'):
147+
compiler.dll_libraries[n] = min(dllname, 'msvcr71')
148+
return
149+
150+
151+
# :::::::::::::::::::::::::::::::
152+
# Bring it all together
153+
# :::::::::::::::::::::::::::::::
154+
155+
# Use the README.rst file as the front-page on PyPI
156+
#with open('README.rst') as README:
157+
# LONG_DESCRIPTION = README.read()
158+
159+
160+
# Standard distutils setup
38161
setup(
162+
# First the metadata
39163
name = 'sode',
40-
cmdclass = {'build_ext': build_ext},
164+
version = '0.0.3',
165+
author = 'Oscar Benjamin',
166+
author_email = '[email protected]',
167+
url = 'https://github.com/oscarbenjamin/sode',
168+
description = ('Python/Cython lib for solving ' +
169+
'Stochastic Ordinary Differential Equations'),
170+
# long_description = open('README.rst').read()
171+
platforms = ['linux2', 'win32', 'darwin'], # tested on these
172+
license = 'GPLv3+',
173+
174+
classifiers = [
175+
'License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+)',
176+
177+
'Intended Audience :: Science/Research',
178+
179+
'Topic :: Scientific/Engineering :: Mathematics',
180+
'Topic :: Scientific/Engineering :: Physics',
181+
'Topic :: Scientific/Engineering :: Chemistry',
182+
'Topic :: Scientific/Engineering :: Bio-Informatics',
183+
184+
'Operating System :: POSIX :: Linux',
185+
'Operating System :: Microsoft :: Windows',
186+
'Operating System :: MacOS :: MacOS X',
187+
188+
'Programming Language :: Cython',
189+
'Programming Language :: Python :: Implementation :: CPython',
190+
'Programming Language :: Python :: 2.6',
191+
'Programming Language :: Python :: 2.7',
192+
],
193+
194+
# Dependency information
195+
provides = ['sode'],
196+
requires = ['numpy (>=1.4)', 'cython (>=0.15)'],
197+
198+
# Now the content
199+
cmdclass = cmdclass,
41200
ext_modules = ext_modules,
201+
packages = ['sode', 'sode.examples', 'sode.examples.pyexamples',
202+
'sode.examples.cyexamples'],
203+
scripts = scripts
42204
)

Diff for: sode/cfiles/build.sh

-14
This file was deleted.

Diff for: sode/examples/.gitignore

-1
This file was deleted.
File renamed without changes.
File renamed without changes.

Diff for: sode/examples/cyexamples.py renamed to sode/examples/cyexamples/__init__.py

+3-4
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,9 @@
88

99
from sode.script import MultiScript
1010

11-
from cyfiles.examples import (Weiner, Weiner2, LinearAdditive2D,
12-
LinearMultiplicative,
13-
SinusoidalMultiplicative,
14-
TangentMultiplicative)
11+
from sode.examples.cyexamples.examples import (
12+
Weiner, Weiner2, LinearAdditive2D, LinearMultiplicative,
13+
SinusoidalMultiplicative, TangentMultiplicative)
1514

1615
sysdict = {
1716
None:'weiner',
File renamed without changes.

Diff for: sode/examples/pyexamples.py renamed to sode/examples/pyexamples/__init__.py

+7-7
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,18 @@
22
#
33
# Copyright, Oscar Benjamin 2011
44
#
5-
# This script brings together the example pure python SODE systems from the
5+
# This script brings together the example pure python SODE systems from the
66
# pyfiles package for comparison with the faster cython and pure-c
77
# implementations.
88

99
from sode.script import MultiScript
1010

11-
from pyfiles.weiner import Weiner
12-
from pyfiles.weiner2 import Weiner2
13-
from pyfiles.lin2d import LinearAdditive2D
14-
from pyfiles.linmult import LinearMultiplicative
15-
from pyfiles.sinmult import SinusoidalMultiplicative
16-
from pyfiles.tanmult import TangentMultiplicative
11+
from sode.examples.pyexamples.weiner import Weiner
12+
from sode.examples.pyexamples.weiner2 import Weiner2
13+
from sode.examples.pyexamples.lin2d import LinearAdditive2D
14+
from sode.examples.pyexamples.linmult import LinearMultiplicative
15+
from sode.examples.pyexamples.sinmult import SinusoidalMultiplicative
16+
from sode.examples.pyexamples.tanmult import TangentMultiplicative
1717

1818

1919
sysdict = {
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

Diff for: sode/examples/pyfiles/__init__.py

-5
This file was deleted.

0 commit comments

Comments
 (0)