Skip to content

Commit cabcf81

Browse files
authored
Merge pull request #40 from jdlangs/rm_0.6_deprecations
Remove deprecations from julia v0.6, drop v0.5 support
2 parents ae77284 + 045e686 commit cabcf81

File tree

10 files changed

+51
-70
lines changed

10 files changed

+51
-70
lines changed

.travis.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
language: julia
22
julia:
3-
- 0.5
43
- 0.6
54
- nightly
65
sudo: required

REQUIRE

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
julia 0.5
1+
julia 0.6
22
PyCall 1.11.0
3-
Compat 0.17.0
3+
Compat 0.34.0

src/callbacks.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ function _callback_notify(handle::Ptr{Void})
44
ccall(:uv_async_send, Cint, (Ptr{Void},), handle)
55
end
66

7-
const CB_NOTIFY_PTR = cfunction(_callback_notify, Cint, (Ptr{Void},))
7+
const CB_NOTIFY_PTR = cfunction(_callback_notify, Cint, Tuple{Ptr{Void}})
88

99
function _callback_async_loop(rosobj, cond)
1010
@debug("Spinning up callback loop...")
@@ -15,14 +15,14 @@ function _callback_async_loop(rosobj, cond)
1515
@debug("Exiting callback loop")
1616
end
1717

18-
function _run_callbacks{M}(sub::Subscriber{M})
18+
function _run_callbacks(sub::Subscriber{M}) where M
1919
while pycall(sub.queue["size"], PyAny) > 0
2020
msg = pycall(sub.queue["get"], PyObject)
2121
sub.callback(convert(M, msg), sub.callback_args...)
2222
end
2323
end
2424

25-
function _run_callbacks{T}(srv::Service{T})
25+
function _run_callbacks(srv::Service{T}) where T
2626
ReqType = _srv_reqtype(T)
2727

2828
req = pycall(srv.cb_interface["get_request"], PyObject)

src/gentypes.jl

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
11
#Generate Julia composite types for ROS messages
22

3-
using Compat
4-
import Compat: String, Symbol
53
using PyCall
64

75
export @rosimport, rostypegen, rostypereset
86

97
#Type definitions
108
#Composite types for internal use. Keeps track of the imported types and helps
119
#keep code generation orderly.
12-
@compat abstract type ROSModule end
13-
type ROSPackage
10+
abstract type ROSModule end
11+
mutable struct ROSPackage
1412
name::String
1513
msg::ROSModule
1614
srv::ROSModule
@@ -21,13 +19,13 @@ type ROSPackage
2119
pkg
2220
end
2321
end
24-
type ROSMsgModule <: ROSModule
22+
struct ROSMsgModule <: ROSModule
2523
pkg::ROSPackage
2624
members::Vector{String}
2725
deps::Set{String}
2826
ROSMsgModule(pkg) = new(pkg, String[], Set{String}())
2927
end
30-
type ROSSrvModule <: ROSModule
28+
struct ROSSrvModule <: ROSModule
3129
pkg::ROSPackage
3230
members::Vector{String}
3331
deps::Set{String}
@@ -62,9 +60,9 @@ const _ros_builtin_types = Dict{String, Symbol}(
6260
)
6361

6462
#Abstract supertypes of all generated types
65-
@compat abstract type AbstractMsg end
66-
@compat abstract type AbstractSrv end
67-
@compat abstract type AbstractService end
63+
abstract type AbstractMsg end
64+
abstract type AbstractSrv end
65+
abstract type AbstractService end
6866

6967
"""
7068
@rosimport
@@ -103,6 +101,7 @@ end
103101

104102
_get_quote_value(input::QuoteNode) = input.value
105103
_get_quote_value(input::Expr) = (@assert input.head == :quote; input.args[1])
104+
106105
#Return the pkg and types strings for a single expression of form:
107106
# pkg.[msg|srv].type or pkg.[msg|srv]:type
108107
function _pkgtype_import(input::Expr)
@@ -316,8 +315,6 @@ function modulecode(mod::ROSModule)
316315
#Common imports
317316
push!(modcode,
318317
quote
319-
using Compat
320-
import Compat: String, Symbol
321318
using PyCall
322319
import Base: convert, getindex
323320
import RobotOS
@@ -417,7 +414,7 @@ function buildtype(mod::ROSSrvModule, typename::String)
417414
reqsym = Symbol(string(typename,"Request"))
418415
respsym = Symbol(string(typename,"Response"))
419416
srvexprs = Expr[
420-
:(immutable $defsym <: AbstractService end),
417+
:(struct $defsym <: AbstractService end),
421418
:(_typerepr(::Type{$defsym}) = $(_rostypestr(mod,typename))),
422419
:(_srv_reqtype(::Type{$defsym}) = $reqsym),
423420
:(_srv_resptype(::Type{$defsym}) = $respsym),
@@ -447,7 +444,7 @@ function typecode(rosname::String, super::Symbol, members::Vector)
447444
#First the empty expressions
448445
#(1) Type declaration
449446
push!(exprs, :(
450-
type $jlsym <: $super
447+
mutable struct $jlsym <: $super
451448
#Generated code here
452449
end
453450
))
@@ -473,7 +470,7 @@ function typecode(rosname::String, super::Symbol, members::Vector)
473470
push!(exprs, :(
474471
function convert(jlt::Type{$jlsym}, o::PyObject)
475472
if convert(String, o["_type"]) != _typerepr(jlt)
476-
throw(InexactError())
473+
throw(InexactError(:convert, $jlsym, o))
477474
end
478475
jl = $jlsym()
479476
#Generated code here
@@ -557,7 +554,7 @@ end
557554

558555
#Build a String => Iterable{String} object from the individual package
559556
#dependencies.
560-
function _collectdeps{S<:AbstractString}(pkgs::Dict{S, ROSPackage})
557+
function _collectdeps(pkgs::Dict{S, ROSPackage}) where S <: AbstractString
561558
deps = Dict{S, Set{S}}()
562559
for pname in keys(pkgs)
563560
if ! haskey(deps, pname)
@@ -654,18 +651,18 @@ _jl_safe_name(name::AbstractString, suffix) = _nameconflicts(name) ?
654651
_nameconflicts(typename::String) = isdefined(Base, Symbol(typename))
655652

656653
#Get a default value for any builtin ROS type
657-
_typedefault{T<:Real}(::Type{T}) = zero(T)
654+
_typedefault(::Type{T}) where {T <: Real} = zero(T)
658655
_typedefault(::Type{String}) = ""
659656
_typedefault(::Type{Time}) = Time(0,0)
660657
_typedefault(::Type{Duration}) = Duration(0,0)
661658

662659
#Default method to get the "pkg/type" string from a generated DataType.
663660
#Extended by the generated modules.
664-
_typerepr{T}(::Type{T}) = error("Not a ROS type")
661+
_typerepr(::Type{T}) where {T} = error("Not a ROS type")
665662

666663
#Default method to get the request/response datatypes for a generated service
667-
_srv_reqtype{T}( ::Type{T}) = error("Not a ROS Service type")
668-
_srv_resptype{T}(::Type{T}) = error("Not a ROS Service type")
664+
_srv_reqtype( ::Type{T}) where {T} = error("Not a ROS Service type")
665+
_srv_resptype(::Type{T}) where {T} = error("Not a ROS Service type")
669666

670667
#Accessors for the package name
671668
_name(p::ROSPackage) = p.name

src/pubsub.jl

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,32 @@
11
#API for publishing and subscribing to message topics
22
export Publisher, Subscriber, publish
33

4-
using Compat
5-
64
"""
75
Publisher{T}(topic; kwargs...)
86
Publisher(topic, T; kwargs...)
97
108
Create an object to publish messages of type `T` on a topic. Keyword arguments are directly passed
119
to rospy.
1210
"""
13-
type Publisher{MsgType<:AbstractMsg}
11+
struct Publisher{MsgType<:AbstractMsg}
1412
o::PyObject
1513

16-
@compat function (::Type{Publisher{MT}}){MT <: AbstractMsg}(topic::AbstractString; kwargs...)
14+
function Publisher{MT}(topic::AbstractString; kwargs...) where MT <: AbstractMsg
1715
@debug("Creating <$(string(MT))> publisher on topic: '$topic'")
1816
rospycls = _get_rospy_class(MT)
1917
return new{MT}(__rospy__[:Publisher](ascii(topic), rospycls; kwargs...))
2018
end
2119
end
2220

23-
Publisher{MT<:AbstractMsg}(topic::AbstractString, ::Type{MT}; kwargs...) =
21+
Publisher(topic::AbstractString, ::Type{MT}; kwargs...) where {MT <: AbstractMsg} =
2422
Publisher{MT}(ascii(topic); kwargs...)
2523

2624
"""
2725
publish(p::Publisher{T}, msg::T)
2826
2927
Publish `msg` on `p`, a `Publisher` with matching message type.
3028
"""
31-
function publish{MT<:AbstractMsg}(p::Publisher{MT}, msg::MT)
29+
function publish(p::Publisher{MT}, msg::MT) where MT <: AbstractMsg
3230
pycall(p.o["publish"], PyAny, convert(PyObject, msg))
3331
end
3432

@@ -40,16 +38,16 @@ Create a subscription to a topic with message type `T` with a callback to use wh
4038
received, which can be any callable type. Extra arguments provided to the callback when invoked
4139
can be provided in the `cb_args` tuple. Keyword arguments are directly passed to rospy.
4240
"""
43-
type Subscriber{MsgType<:AbstractMsg}
41+
mutable struct Subscriber{MsgType<:AbstractMsg}
4442
callback
4543
callback_args::Tuple
4644
sub_obj::PyObject
4745
queue::PyObject
4846
async_loop::Task
4947

50-
@compat function (::Type{Subscriber{MT}}){MT <: AbstractMsg}(
48+
function Subscriber{MT}(
5149
topic::AbstractString, cb, cb_args::Tuple=(); kwargs...
52-
)
50+
) where MT <: AbstractMsg
5351
@debug("Creating <$(string(MT))> subscriber on topic: '$topic'")
5452
rospycls = _get_rospy_class(MT)
5553

@@ -66,6 +64,6 @@ type Subscriber{MsgType<:AbstractMsg}
6664
end
6765
end
6866

69-
function Subscriber{MT<:AbstractMsg}(topic, ::Type{MT}, cb, cb_args::Tuple=(); kwargs...)
67+
function Subscriber(topic, ::Type{MT}, cb, cb_args::Tuple=(); kwargs...) where MT <: AbstractMsg
7068
Subscriber{MT}(topic, cb, cb_args; kwargs...)
7169
end

src/services.jl

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,28 @@
11
#API for calling/creating services. Syntax is practically identical to rospy.
22
export Service, ServiceProxy, wait_for_service
33

4-
using Compat
5-
64
"""
75
ServiceProxy{T}(name; kwargs...)
86
ServiceProxy(name, T; kwargs...)
97
108
Create a proxy object used to invoke a remote service. Use `srv_proxy(msg_request)` with the object
119
to invoke the service call. Keyword arguments are directly passed to rospy.
1210
"""
13-
type ServiceProxy{SrvType <: AbstractService}
11+
struct ServiceProxy{SrvType <: AbstractService}
1412
o::PyObject
1513

16-
@compat function (::Type{ServiceProxy{ST}}){ST <: AbstractService}(
17-
name::AbstractString; kwargs...
18-
)
14+
function ServiceProxy{ST}(name::AbstractString; kwargs...) where ST <: AbstractService
1915
@debug("Creating <$ST> service proxy for '$name'")
2016
rospycls = _get_rospy_class(ST)
2117
new{ST}(__rospy__[:ServiceProxy](ascii(name), rospycls; kwargs...))
2218
end
2319
end
2420

25-
function ServiceProxy{ST<:AbstractService}(name::AbstractString, srv::Type{ST}; kwargs...)
21+
function ServiceProxy(name::AbstractString, srv::Type{ST}; kwargs...) where ST <: AbstractService
2622
ServiceProxy{ST}(ascii(name); kwargs...)
2723
end
2824

29-
@compat function (srv::ServiceProxy{ST}){ST <: AbstractService}(
30-
req::AbstractSrv
31-
)
25+
function (srv::ServiceProxy{ST})(req::AbstractSrv) where ST <: AbstractService
3226
if ! isa(req, _srv_reqtype(ST))
3327
throw(ArgumentError(
3428
string("Incorrect service request type: ", typeof(req),
@@ -46,15 +40,13 @@ end
4640
Create a service object that can receive requests and provide responses. The callback can be of
4741
any callable type. Keyword arguments are directly passed to rospy.
4842
"""
49-
type Service{SrvType <: AbstractService}
43+
mutable struct Service{SrvType <: AbstractService}
5044
handler
5145
srv_obj::PyObject
5246
cb_interface::PyObject
5347
async_loop::Task
5448

55-
@compat function (::Type{Service{ST}}){ST <: AbstractService}(
56-
name::AbstractString, handler; kwargs...
57-
)
49+
function Service{ST}(name::AbstractString, handler; kwargs...) where ST <: AbstractService
5850
@debug("Providing <$ST> service at '$name'")
5951
rospycls = _get_rospy_class(ST)
6052

@@ -81,7 +73,7 @@ type Service{SrvType <: AbstractService}
8173
end
8274
end
8375

84-
function Service{ST<:AbstractService}(name::AbstractString, srv::Type{ST}, handler; kwargs...)
76+
function Service(name::AbstractString, srv::Type{ST}, handler; kwargs...) where ST <: AbstractService
8577
Service{ST}(ascii(name), handler; kwargs...)
8678
end
8779

src/time.jl

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

3-
using Compat
4-
53
import Base: convert, isless, sleep, +, -, *, ==
64
export Time, Duration, Rate, to_sec, to_nsec, get_rostime, rossleep
75

86
#Time type definitions
9-
@compat abstract type TVal end
7+
abstract type AbstractTime end
108

119
"""
1210
Time(secs, nsecs), Time(), Time(t::Real)
@@ -17,7 +15,7 @@ Basic arithmetic can be performed on combinations of `Time` and `Duration` objec
1715
For example, if `t::Time` and `d::Duration`, `t+d` will be a `Time`, `d+d` a `Duration`, `t-d` a
1816
`Time`, `d-d` a `Duration`, and `t-t` a `Duration`.
1917
"""
20-
immutable Time <: TVal
18+
struct Time <: AbstractTime
2119
secs::Int32
2220
nsecs::Int32
2321
function Time(s::Real,n::Real)
@@ -37,7 +35,7 @@ Basic arithmetic can be performed on combinations of `Time` and `Duration` objec
3735
For example, if `t::Time` and `d::Duration`, `t+d` will be a `Time`, `d+d` a `Duration`, `t-d` a
3836
`Time`, `d-d` a `Duration`, and `t-t` a `Duration`.
3937
"""
40-
immutable Duration <: TVal
38+
struct Duration <: AbstractTime
4139
secs::Int32
4240
nsecs::Int32
4341
function Duration(s::Real,n::Real)
@@ -84,19 +82,19 @@ convert(::Type{PyObject}, t::Duration) = __rospy__[:Duration](t.secs,t.nsecs)
8482
8583
Return the value of a ROS time object in absolute seconds (with nanosecond precision)
8684
"""
87-
to_sec{T<:TVal}(t::T) = t.secs + 1e-9*t.nsecs
85+
to_sec(t::T) where {T <: AbstractTime} = t.secs + 1e-9*t.nsecs
8886

8987
"""
9088
to_nsec(t)
9189
9290
Return the value of a ROS time object in nanoseconds as an integer.
9391
"""
94-
to_nsec{T<:TVal}(t::T) = 1_000_000_000*t.secs + t.nsecs
95-
convert{T<:TVal}(::Type{Float64}, t::T) = to_sec(t)
92+
to_nsec(t::T) where {T <: AbstractTime} = 1_000_000_000*t.secs + t.nsecs
93+
convert(::Type{Float64}, t::T) where {T <: AbstractTime} = to_sec(t)
9694

9795
#Comparisons
98-
=={T<:TVal}(t1::T, t2::T) = (t1.secs == t2.secs) && (t1.nsecs == t2.nsecs)
99-
isless{T<:TVal}(t1::T, t2::T) = to_nsec(t1) < to_nsec(t2)
96+
==(t1::T, t2::T) where {T <: AbstractTime} = (t1.secs == t2.secs) && (t1.nsecs == t2.nsecs)
97+
isless(t1::T, t2::T) where {T <: AbstractTime} = to_nsec(t1) < to_nsec(t2)
10098

10199
"""
102100
Rate(hz::Real), Rate(d::Duration)
@@ -105,7 +103,7 @@ Used to allow a loop to run at a fixed rate. Construct with a frequency or `Dura
105103
`rossleep` or `sleep`. The rate object will record execution time of other work in the loop and
106104
modify the sleep time to compensate, keeping the loop rate as consistent as possible.
107105
"""
108-
type Rate
106+
mutable struct Rate
109107
duration::Duration
110108
last_time::Time
111109
end

test/pubsub.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ const ros_pub = Publisher("vectors", Vector3, queue_size = 10)
1818
rossleep(Duration(3.0))
1919

2020
function publish_messages(pubobj, msgs, rate_hz)
21-
const r = Rate(rate_hz)
21+
r = Rate(rate_hz)
2222
for msg in msgs
2323
publish(pubobj, msg)
2424
rossleep(r)

test/runtests.jl

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
1-
using Base.Test
1+
using Compat.Test
22
using PyCall
33
using RobotOS
4-
using Compat
54
RobotOS.debug(true)
65

7-
#Generally, later tests rely on things defined in previous tests, so the order
8-
#is important
6+
#Generally, later tests rely on things defined in previous tests, so the order is important
97
include("rospy.jl")
108
include("time.jl")
119
include("typegeneration.jl")

0 commit comments

Comments
 (0)