Skip to content

Commit c7ecdc9

Browse files
committed
Deprecation fixes for julia 0.6
1 parent 3855cc7 commit c7ecdc9

File tree

8 files changed

+71
-68
lines changed

8 files changed

+71
-68
lines changed

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ language: julia
22
julia:
33
- 0.4
44
- 0.5
5+
- 0.6
56
- nightly
67
sudo: required
78
dist: trusty

REQUIRE

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
julia 0.4
2-
PyCall
3-
Compat 0.8.0
2+
PyCall 1.11.0
3+
Compat 0.17.0

src/gentypes.jl

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export @rosimport, rostypegen, rostypereset, gentypes, cleartypes
88
#Type definitions
99
#Composite types for internal use. Keeps track of the imported types and helps
1010
#keep code generation orderly.
11-
abstract ROSModule
11+
@compat abstract type ROSModule end
1212
type ROSPackage
1313
name::String
1414
msg::ROSModule
@@ -33,7 +33,7 @@ type ROSSrvModule <: ROSModule
3333
ROSSrvModule(pkg) = new(pkg, String[], Set{String}())
3434
end
3535

36-
#These two global objects maintain the hierarchy from multiple calls to
36+
#These global objects maintain the hierarchy from multiple calls to
3737
#`@rosimport` and keep the link to the Python objects whenever communication
3838
#goes between RobotOS and rospy.
3939
const _rospy_imports = Dict{String,ROSPackage}()
@@ -61,9 +61,9 @@ const _ros_builtin_types = Dict{String, Symbol}(
6161
)
6262

6363
#Abstract supertypes of all generated types
64-
abstract MsgT
65-
abstract SrvT
66-
abstract ServiceDefinition
64+
@compat abstract type AbstractMsg end
65+
@compat abstract type AbstractSrv end
66+
@compat abstract type AbstractService end
6767

6868
#Rearranges the expression into a RobotOS._rosimport call. Input comes in as a
6969
#single package qualified expression, or as a tuple expression where the first
@@ -317,15 +317,15 @@ end
317317

318318
#The imports specific to each module, including dependant packages
319319
function _importexprs(mod::ROSMsgModule)
320-
imports = Expr[Expr(:import, :RobotOS, :MsgT)]
320+
imports = Expr[Expr(:import, :RobotOS, :AbstractMsg)]
321321
othermods = filter(d -> d != _name(mod), mod.deps)
322322
append!(imports, [Expr(:using,Symbol(m),:msg) for m in othermods])
323323
imports
324324
end
325325
function _importexprs(mod::ROSSrvModule)
326326
imports = Expr[
327-
Expr(:import, :RobotOS, :SrvT),
328-
Expr(:import, :RobotOS, :ServiceDefinition),
327+
Expr(:import, :RobotOS, :AbstractSrv),
328+
Expr(:import, :RobotOS, :AbstractService),
329329
Expr(:import, :RobotOS, :_srv_reqtype),
330330
Expr(:import, :RobotOS, :_srv_resptype),
331331
]
@@ -362,7 +362,7 @@ function buildtype(mod::ROSMsgModule, typename::String)
362362
memtypes = pyobj[:_slot_types]
363363
members = collect(zip(memnames, memtypes))
364364

365-
typecode(fulltypestr, :MsgT, members)
365+
typecode(fulltypestr, :AbstractMsg, members)
366366
end
367367

368368
#All the generated code for a generated service type
@@ -376,21 +376,21 @@ function buildtype(mod::ROSSrvModule, typename::String)
376376
memtypes = reqobj[:_slot_types]
377377
reqmems = collect(zip(memnames, memtypes))
378378
pyreq = :(RobotOS._rospy_objects[$req_typestr])
379-
reqexprs = typecode(req_typestr, :SrvT, reqmems)
379+
reqexprs = typecode(req_typestr, :AbstractSrv, reqmems)
380380

381381
resp_typestr = _rostypestr(mod, string(typename,"Response"))
382382
respobj = _rospy_objects[resp_typestr]
383383
memnames = respobj[:__slots__]
384384
memtypes = respobj[:_slot_types]
385385
respmems = collect(zip(memnames, memtypes))
386386
pyresp = :(RobotOS._rospy_objects[$resp_typestr])
387-
respexprs = typecode(resp_typestr, :SrvT, respmems)
387+
respexprs = typecode(resp_typestr, :AbstractSrv, respmems)
388388

389389
defsym = Symbol(typename)
390390
reqsym = Symbol(string(typename,"Request"))
391391
respsym = Symbol(string(typename,"Response"))
392392
srvexprs = Expr[
393-
:(immutable $defsym <: ServiceDefinition end),
393+
:(immutable $defsym <: AbstractService end),
394394
:(_typerepr(::Type{$defsym}) = $(_rostypestr(mod,typename))),
395395
:(_srv_reqtype(::Type{$defsym}) = $reqsym),
396396
:(_srv_resptype(::Type{$defsym}) = $respsym),
@@ -411,8 +411,8 @@ function typecode(rosname::String, super::Symbol, members::Vector)
411411

412412
#generated code should not conflict with julia built-ins
413413
#some messages need renaming
414-
suffix = if super == :MsgT; "Msg"
415-
elseif super == :SrvT; "Srv"
414+
suffix = if super == :AbstractMsg; "Msg"
415+
elseif super == :AbstractSrv; "Srv"
416416
else; "ROS" end
417417
jlsym = Symbol(_jl_safe_name(tname,suffix))
418418

src/pubsub.jl

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,38 +3,41 @@ export Publisher, Subscriber, publish
33

44
using Compat
55

6-
type Publisher{MsgType<:MsgT}
6+
type Publisher{MsgType<:AbstractMsg}
77
o::PyObject
88

9-
function Publisher(topic::AbstractString; kwargs...)
10-
@debug("Creating <$(string(MsgType))> publisher on topic: '$topic'")
11-
rospycls = _get_rospy_class(MsgType)
12-
return new(__rospy__[:Publisher](ascii(topic), rospycls; kwargs...))
9+
@compat function (::Type{Publisher{MT}}){MT <: AbstractMsg}(topic::AbstractString; kwargs...)
10+
@debug("Creating <$(string(MT))> publisher on topic: '$topic'")
11+
rospycls = _get_rospy_class(MT)
12+
return new{MT}(__rospy__[:Publisher](ascii(topic), rospycls; kwargs...))
1313
end
1414
end
15-
Publisher{MsgType<:MsgT}(topic::AbstractString, ::Type{MsgType}; kwargs...) =
16-
Publisher{MsgType}(ascii(topic); kwargs...)
1715

18-
function publish{MsgType<:MsgT}(p::Publisher{MsgType}, msg::MsgType)
16+
Publisher{MT<:AbstractMsg}(topic::AbstractString, ::Type{MT}; kwargs...) =
17+
Publisher{MT}(ascii(topic); kwargs...)
18+
19+
function publish{MT<:AbstractMsg}(p::Publisher{MT}, msg::MT)
1920
pycall(p.o["publish"], PyAny, convert(PyObject, msg))
2021
end
2122

22-
type Subscriber{MsgType<:MsgT}
23+
type Subscriber{MsgType<:AbstractMsg}
2324
callback
2425
callback_args::Tuple
2526
sub_obj::PyObject
2627
queue::PyObject
2728
async_loop::Task
2829

29-
function Subscriber(topic::AbstractString, cb, cb_args::Tuple=(); kwargs...)
30-
@debug("Creating <$(string(MsgType))> subscriber on topic: '$topic'")
31-
rospycls = _get_rospy_class(MsgType)
30+
@compat function (::Type{Subscriber{MT}}){MT <: AbstractMsg}(
31+
topic::AbstractString, cb, cb_args::Tuple=(); kwargs...
32+
)
33+
@debug("Creating <$(string(MT))> subscriber on topic: '$topic'")
34+
rospycls = _get_rospy_class(MT)
3235

3336
cond = Compat.AsyncCondition()
3437
mqueue = _py_ros_callbacks["MessageQueue"](CB_NOTIFY_PTR, cond.handle)
3538
subobj = __rospy__[:Subscriber](ascii(topic), rospycls, mqueue["storemsg"]; kwargs...)
3639

37-
rosobj = new(cb, cb_args, subobj, mqueue)
40+
rosobj = new{MT}(cb, cb_args, subobj, mqueue)
3841
cbloop = Task(() -> _callback_async_loop(rosobj, cond))
3942
schedule(cbloop)
4043

@@ -43,7 +46,6 @@ type Subscriber{MsgType<:MsgT}
4346
end
4447
end
4548

46-
function Subscriber{MsgType<:MsgT}(topic, ::Type{MsgType}, cb, cb_args::Tuple=(); kwargs...)
47-
Subscriber{MsgType}(topic, cb, cb_args; kwargs...)
49+
function Subscriber{MT<:AbstractMsg}(topic, ::Type{MT}, cb, cb_args::Tuple=(); kwargs...)
50+
Subscriber{MT}(topic, cb, cb_args; kwargs...)
4851
end
49-

src/services.jl

Lines changed: 26 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -3,44 +3,46 @@ export Service, ServiceProxy, wait_for_service
33

44
using Compat
55

6-
type ServiceProxy{SrvType <: ServiceDefinition}
6+
type ServiceProxy{SrvType <: AbstractService}
77
o::PyObject
88

9-
function ServiceProxy(name::AbstractString; kwargs...)
10-
@debug("Creating <$SrvType> service proxy for '$name'")
11-
rospycls = _get_rospy_class(SrvType)
12-
new(__rospy__[:ServiceProxy](ascii(name), rospycls; kwargs...))
9+
@compat function (::Type{ServiceProxy{ST}}){ST <: AbstractService}(
10+
name::AbstractString; kwargs...
11+
)
12+
@debug("Creating <$ST> service proxy for '$name'")
13+
rospycls = _get_rospy_class(ST)
14+
new{ST}(__rospy__[:ServiceProxy](ascii(name), rospycls; kwargs...))
1315
end
1416
end
15-
function ServiceProxy{SrvType<:ServiceDefinition}(
16-
name::AbstractString,
17-
srv::Type{SrvType};
18-
kwargs...
19-
)
20-
ServiceProxy{SrvType}(ascii(name); kwargs...)
17+
18+
function ServiceProxy{ST<:AbstractService}(name::AbstractString, srv::Type{ST}; kwargs...)
19+
ServiceProxy{ST}(ascii(name); kwargs...)
2120
end
2221

23-
@compat function (srv::ServiceProxy{SrvType}){SrvType <: ServiceDefinition}(
24-
req::SrvT
22+
@compat function (srv::ServiceProxy{ST}){ST <: AbstractService}(
23+
req::AbstractSrv
2524
)
26-
if ! isa(req, _srv_reqtype(SrvType))
25+
if ! isa(req, _srv_reqtype(ST))
2726
throw(ArgumentError(
28-
string("Incorrect service request type: ",typeof(req))))
27+
string("Incorrect service request type: ", typeof(req),
28+
", expected: ", _srv_reqtype(ST))))
2929
end
3030
pyresp = pycall(srv.o, PyObject, convert(PyObject, req))
31-
resp = convert(_srv_resptype(SrvType), pyresp)
31+
resp = convert(_srv_resptype(ST), pyresp)
3232
resp
3333
end
3434

35-
type Service{SrvType <: ServiceDefinition}
35+
type Service{SrvType <: AbstractService}
3636
handler
3737
srv_obj::PyObject
3838
cb_interface::PyObject
3939
async_loop::Task
4040

41-
function Service(name::AbstractString, handler; kwargs...)
42-
@debug("Providing <$SrvType> service at '$name'")
43-
rospycls = _get_rospy_class(SrvType)
41+
@compat function (::Type{Service{ST}}){ST <: AbstractService}(
42+
name::AbstractString, handler; kwargs...
43+
)
44+
@debug("Providing <$ST> service at '$name'")
45+
rospycls = _get_rospy_class(ST)
4446

4547
cond = Compat.AsyncCondition()
4648
pysrv = _py_ros_callbacks["ServiceCallback"](CB_NOTIFY_PTR, cond.handle)
@@ -55,7 +57,7 @@ type Service{SrvType <: ServiceDefinition}
5557
end
5658
end
5759

58-
rosobj = new(handler, srvobj, pysrv)
60+
rosobj = new{ST}(handler, srvobj, pysrv)
5961

6062
cbloop = Task(() -> _callback_async_loop(rosobj, cond))
6163
schedule(cbloop)
@@ -64,13 +66,9 @@ type Service{SrvType <: ServiceDefinition}
6466
return rosobj
6567
end
6668
end
67-
function Service{SrvType<:ServiceDefinition}(
68-
name::AbstractString,
69-
srv::Type{SrvType},
70-
handler;
71-
kwargs...
72-
)
73-
Service{SrvType}(ascii(name), handler; kwargs...)
69+
70+
function Service{ST<:AbstractService}(name::AbstractString, srv::Type{ST}, handler; kwargs...)
71+
Service{ST}(ascii(name), handler; kwargs...)
7472
end
7573

7674
function wait_for_service(service::AbstractString; kwargs...)

src/time.jl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
#All time related types and functions
22

3+
using Compat
4+
35
import Base: convert, isless, sleep, +, -, *, ==
46
export Time, Duration, Rate, to_sec, to_nsec, get_rostime, rossleep
57

68
#Time type definitions
7-
abstract TVal
9+
@compat abstract type TVal end
810

911
immutable Time <: TVal
1012
secs::Int32

test/pubsub.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ using geometry_msgs.msg
77
const Nmsgs = 10
88
const rate = 20. #Hz
99
const msgs = PoseStamped[]
10-
const refs = Array(Vector3, Nmsgs)
10+
const refs = Array{Vector3}(Nmsgs)
1111
const t0 = to_nsec(get_rostime())
1212

1313
for i=1:Nmsgs
@@ -50,8 +50,8 @@ println("Received ",length(msgs)," / ",Nmsgs)
5050

5151
@test length(msgs) == Nmsgs
5252
for i=1:Nmsgs
53-
@test_approx_eq msgs[i].pose.position.x refs[i].x
54-
@test_approx_eq msgs[i].pose.position.y refs[i].y
55-
@test_approx_eq msgs[i].pose.position.z refs[i].z
53+
@test msgs[i].pose.position.x refs[i].x
54+
@test msgs[i].pose.position.y refs[i].y
55+
@test msgs[i].pose.position.z refs[i].z
5656
end
5757
empty!(msgs)

test/services.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ const Nposes = 5
1313

1414
function srv_cb(req::GetPlanRequest)
1515
println("GetPlan call received")
16-
@test_approx_eq(req.start.pose.position.x, 1.0)
17-
@test_approx_eq(req.goal.pose.position.y, 1.0)
16+
@test req.start.pose.position.x 1.0
17+
@test req.goal.pose.position.y 1.0
1818

1919
resp = GetPlanResponse()
2020
for i=1:Nposes
@@ -45,7 +45,7 @@ if flag[1]
4545
rossleep(Duration(2.0))
4646
@test length(msgs) == Nposes
4747
for i=1:Nposes
48-
@test_approx_eq(msgs[i].pose.position.z, i)
48+
@test msgs[i].pose.position.z i
4949
end
5050
end
5151
empty!(msgs)

0 commit comments

Comments
 (0)