Skip to content

Commit 0514983

Browse files
committed
Keep imported python modules as PyObjects
1 parent 33925b7 commit 0514983

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

src/gentypes.jl

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ end
3636
#goes between RobotOS and rospy.
3737
const _rospy_imports = Dict{ASCIIString,ROSPackage}()
3838
const _rospy_objects = Dict{ASCIIString,PyObject}()
39+
const _rospy_modules = Dict{ASCIIString,PyObject}()
3940

4041
const _ros_builtin_types = @compat Dict{ASCIIString, Symbol}(
4142
"bool" => :Bool,
@@ -175,8 +176,8 @@ function addtype!(mod::ROSSrvModule, typ::String)
175176

176177
#Immediately import dependencies from the Request/Response classes
177178
#Repeats are OK
178-
req_obj = pymod.pymember(string(typ,"Request"))
179-
resp_obj = pymod.pymember(string(typ,"Response"))
179+
req_obj = pymod[string(typ,"Request")]
180+
resp_obj = pymod[string(typ,"Response")]
180181
deptypes = [req_obj[:_slot_types]; resp_obj[:_slot_types]]
181182
_importdeps!(mod, deptypes)
182183

@@ -192,7 +193,7 @@ end
192193
function _pyvars(modname::String, typ::String)
193194
pymod = _import_rospy_pkg(modname)
194195
pyobj =
195-
try pymod.pymember(typ)
196+
try pymod[typ]
196197
catch ex
197198
if isa(ex, KeyError)
198199
throw(KeyError("'$typ' in package '$modname'"))
@@ -234,19 +235,17 @@ end
234235

235236
#Bring in the python modules as needed
236237
function _import_rospy_pkg(package::String)
237-
pkg, ptype = split(package, '.')
238-
pypkg = symbol(string("py_",pkg,"_",ptype))
239-
if ! isdefined(RobotOS, pypkg)
238+
global _rospy_modules
239+
if ! haskey(_rospy_modules, package)
240240
@debug("Importing python package: ", package)
241-
pkgsym, mssym = symbol(pkg), symbol(ptype)
242241
try
243-
@eval @pyimport $(pkgsym).$(mssym) as $pypkg
242+
_rospy_modules[package] = pyimport(package)
244243
catch ex
245244
show(ex)
246245
error("python import error: $(ex.val[:args][1])")
247246
end
248247
end
249-
eval(pypkg)
248+
_rospy_modules[package]
250249
end
251250

252251
#The function that creates and fills the generated top-level modules

0 commit comments

Comments
 (0)