Skip to content

Commit

Permalink
Add a package extension for ArrowTypes (#61)
Browse files Browse the repository at this point in the history
* Add a package extension for ArrowTypes

Onda currently defines ArrowTypes methods for `TimeSpan`, likely a
holdover from before TimeSpans was its own package. The ArrowTypes
interoperability should instead be managed here, and we can do that
using a package extension.

* Add ArrowTypes to [extras]

Maybe this will fix 1.6 support?

* Move ArrowTypes from [extras] to [deps]

Should fix a warning on 1.6

* Apparently ArrowTypes needs to be in like every section
  • Loading branch information
ararslan authored Feb 20, 2024
1 parent 58a24ec commit a364982
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 3 deletions.
15 changes: 12 additions & 3 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,19 +1,28 @@
name = "TimeSpans"
uuid = "bb34ddd2-327f-4c4a-bfb0-c98fc494ece1"
authors = ["Beacon Biosignals, Inc."]
version = "1.0.0"
version = "1.1.0"

[deps]
ArrowTypes = "31f734f8-188a-4ce0-8406-c8a06bd891cd"
Compat = "34da2185-b29b-5c13-b0c7-acf172513d20"
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"
Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"

[weakdeps]
ArrowTypes = "31f734f8-188a-4ce0-8406-c8a06bd891cd"

[extensions]
TimeSpansArrowTypesExt = "ArrowTypes"

[compat]
Compat = "3.38,4"
ArrowTypes = "2"
Compat = "3.38, 4"
julia = "1.6"

[extras]
ArrowTypes = "31f734f8-188a-4ce0-8406-c8a06bd891cd"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[targets]
test = ["Test"]
test = ["ArrowTypes", "Test"]
11 changes: 11 additions & 0 deletions ext/TimeSpansArrowTypesExt.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module TimeSpansArrowTypesExt

using ArrowTypes
using TimeSpans

const TIME_SPAN_ARROW_NAME = Symbol("JuliaLang.TimeSpan")

ArrowTypes.arrowname(::Type{TimeSpan}) = TIME_SPAN_ARROW_NAME
ArrowTypes.JuliaType(::Val{TIME_SPAN_ARROW_NAME}) = TimeSpan

end
8 changes: 8 additions & 0 deletions src/TimeSpans.jl
Original file line number Diff line number Diff line change
Expand Up @@ -399,4 +399,12 @@ function invert_spans(spans, parent_span)
return gaps
end

#####
##### Package extensions (TODO: remove this section once we require Julia 1.9+)
#####

if !isdefined(Base, :get_extension)
include(joinpath(dirname(@__DIR__), "ext", "TimeSpansArrowTypesExt.jl"))
end

end # module
7 changes: 7 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -263,3 +263,10 @@ end
test_vec .= TimeSpan(0, 300)
@test test_vec == []
end

@testset "extensions" begin
@testset "ArrowTypes" begin
using ArrowTypes
@test ArrowTypes.JuliaType(Val(ArrowTypes.arrowname(TimeSpan))) === TimeSpan
end
end

6 comments on commit a364982

@ararslan
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ararslan
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ararslan
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ararslan
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

juliaregistrator pls

@ararslan
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/101295

Tip: Release Notes

Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.

@JuliaRegistrator register

Release notes:

## Breaking changes

- blah

To add them here just re-invoke and the PR will be updated.

Tagging

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v1.1.0 -m "<description of version>" a364982297dc374f0f5d47bd508fbc201574975b
git push origin v1.1.0

Please sign in to comment.