aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorbnewbold <bnewbold@robocracy.org>2016-04-04 18:22:09 -0400
committerbnewbold <bnewbold@robocracy.org>2016-04-04 18:32:51 -0400
commit3a3feee057933c691e7184ef82c62ec705d4ce78 (patch)
treea92775a45787e535a7ef2f06ec11230a936b70e0
parent9b2d9f990537b8c36c0e3fd936b4ae14b88a59ab (diff)
downloadPyX.jl-3a3feee057933c691e7184ef82c62ec705d4ce78.tar.gz
PyX.jl-3a3feee057933c691e7184ef82c62ec705d4ce78.zip
pyrecwrap: skip some wrapping as an optimization
This cuts down on the number of wrapped Julia Modules by ~30%. Might not be worth it.
-rw-r--r--src/pyrecwrap.jl8
-rw-r--r--test/test_pyrecwrap.jl2
2 files changed, 7 insertions, 3 deletions
diff --git a/src/pyrecwrap.jl b/src/pyrecwrap.jl
index 9cfc5e4..d2c2b9f 100644
--- a/src/pyrecwrap.jl
+++ b/src/pyrecwrap.jl
@@ -11,8 +11,11 @@
# PyCall.
_pyrecwrap_cache = Dict{PyObject,Module}()
+_pyx_module_skiplist = Set{ASCIIString}(["math", "os", "sys", "ast", "bytearray", "random", "errno",
+ "shutil", "zlib", "copy", "base64", "array", "importlib", "glob", "email", "xml",
+ "binascii", "encodings", "io", "tarfile", "threading", "itertools", "logging", "collections"])
-function pyrecwrap(o::PyObject, mname::Symbol=:__anon__)
+function pyrecwrap(o::PyObject, mname::Symbol=:__anon__; skiplist=_pyx_module_skiplist)
members = convert(Vector{Tuple{AbstractString,PyObject}},
pycall(PyCall.inspect["getmembers"], PyObject, o))
if PyCall.pyversion >= v"3"
@@ -25,6 +28,7 @@ function pyrecwrap(o::PyObject, mname::Symbol=:__anon__)
filter!(m -> !(m[1] == PyCall.inspect), members)
end
filter!(m -> !(m[1] in PyCall.reserved), members)
+ filter!(m -> !(m[1] in skiplist), members)
m = Module(mname, false)
# Preload module cache with this (so far empty) module
_pyrecwrap_cache[o] = m
@@ -37,7 +41,7 @@ function pyrecwrap(o::PyObject, mname::Symbol=:__anon__)
end
# Before recursing, check if we've seen this python module before
if !haskey(_pyrecwrap_cache, mo)
- _pyrecwrap_cache[mo] = pyrecwrap(mo)
+ _pyrecwrap_cache[mo] = pyrecwrap(mo, skiplist=skiplist)
end
mm = _pyrecwrap_cache[mo]
push!(consts, Expr(:const, Expr(:(=), symbol(ms), mm)))
diff --git a/test/test_pyrecwrap.jl b/test/test_pyrecwrap.jl
index cef3f08..6182779 100644
--- a/test/test_pyrecwrap.jl
+++ b/test/test_pyrecwrap.jl
@@ -1,4 +1,4 @@
-os_test = PyX.pyrecwrap(pyimport("os"))
+os_test = PyX.pyrecwrap(pyimport("os"), skiplist=["asdf"])
@test os_test.path.genericpath.os.path.genericpath.os.path.genericpath != nothing