Skip to content
This repository was archived by the owner on Jun 24, 2022. It is now read-only.

Commit 16d7ab3

Browse files
Merge pull request #6 from tkf/evil
A dirty hack to force importing PyDSTool
2 parents 3421a83 + adb051c commit 16d7ab3

File tree

3 files changed

+54
-0
lines changed

3 files changed

+54
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
*.jl.cov
22
*.jl.*.cov
33
*.jl.mem
4+
*.pyc

src/PyDSTool.jl

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,25 @@ using PyCall, DataStructures, DiffEqBase, RecipesBase
77
const ds = PyNULL()
88

99
function __init__()
10+
try
11+
copy!(ds, pyimport_conda("PyDSTool", "pydstool", "conda-forge"))
12+
return
13+
catch err
14+
if err isa PyCall.PyError
15+
# A dirty hack to force importing PyDSTool:
16+
# https://github.com/JuliaDiffEq/PyDSTool.jl/issues/5
17+
#
18+
# At this point, we assume that "import PyDSTool" was failed due
19+
# to the bug in how it checks SciPy version number. We
20+
# workaround it by monkey-patching `scipy.__version__` while
21+
# importing PyDSTool. We make ./_pydstool_jl_hack.py importable
22+
# and execute it by importing it.
23+
unshift!(PyVector(pyimport("sys")["path"]), @__DIR__)
24+
pyimport("_pydstool_jl_hack")
25+
else
26+
rethrow()
27+
end
28+
end
1029
copy!(ds, pyimport_conda("PyDSTool", "pydstool", "conda-forge"))
1130
end
1231

src/_pydstool_jl_hack.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import scipy.special
2+
3+
# Old sph_* removed in SciPy 1.0:
4+
# https://docs.scipy.org/doc/scipy/reference/release.1.0.0.html#backwards-incompatible-changes
5+
old_special_funcs = [
6+
'sph_jn',
7+
'sph_yn',
8+
'sph_jnyn',
9+
'sph_in',
10+
'sph_kn',
11+
'sph_inkn',
12+
]
13+
14+
15+
original_version = scipy.__version__
16+
try:
17+
18+
# Fool how PyDSTool checks SciPy's version number:
19+
scipy.__version__ = '0.9'
20+
21+
# PyDSTool tries to access `scipy.special.sph_*`; let's not fail
22+
# by that by setting them to None. Those functions won't be
23+
# usable, but at least (hopefully) other PyDSTool functionalities
24+
# are usable:
25+
for name in old_special_funcs:
26+
if not hasattr(scipy.special, name):
27+
setattr(scipy.special, name, None)
28+
29+
import PyDSTool
30+
finally:
31+
scipy.__version__ = original_version
32+
for name in old_special_funcs:
33+
if getattr(scipy.special, name) is None:
34+
delattr(scipy.special, name)

0 commit comments

Comments
 (0)