Skip to content

Commit

Permalink
adding JuliaVersionNumber
Browse files Browse the repository at this point in the history
  • Loading branch information
aminya committed Jun 10, 2020
1 parent f859488 commit 541b8ec
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 0 deletions.
32 changes: 32 additions & 0 deletions src/bot/botutils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -280,3 +280,35 @@ julia> VersionFloat(v"1.4.2")
```
"""
VersionFloat(v::VersionNumber) = join(split(string(v),'.')[1:2],'.')

# https://github.com/JuliaLang/julia/pull/36223:
"""
JuliaVersionNumber(v::String)
JuliaVersionNumber(v::VersionNumber)
returns the Julia version number by following the same specifications as VersionNumber.
`JuliaVersionNumber` will fetch the latest nightly version number if `"nightly"` or `"latest"` is given as the input.
# Examples
```julia
julia> JuliaVersionNumber("nightly")
v"1.6.0-DEV"
```
```jldoctest
julia> JuliaVersionNumber("1.2.3")
v"1.2.3"
julia> JuliaVersionNumber(v"1.2.3")
v"1.2.3"
```
"""
JuliaVersionNumber(v::VersionNumber) = v
function JuliaVersionNumber(v::String)
if in(v, ["nightly", "latest"])
version_path = download(
"https://raw.githubusercontent.com/JuliaLang/julia/master/VERSION",
joinpath(tempdir(), "VERSION.txt"),
)
version_str = replace(Base.read(version_path, String), "\n" => "")
return VersionNumber(version_str)
else
return VersionNumber(v)
end
end
2 changes: 2 additions & 0 deletions test/bot/bot.jl
Original file line number Diff line number Diff line change
Expand Up @@ -421,3 +421,5 @@ bottestdir = GoodPath(@__DIR__)
# just in case
cd(snoopcompiledir)
end

include("bot/botutils.jl")
8 changes: 8 additions & 0 deletions test/bot/botutils.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# JuliaVersionNumber

# https://github.com/JuliaLang/julia/pull/36223:
# @test JuliaVersionNumber("nightly") ==
# VersionNumber(replace(Base.read("VERSION", String), "\n" => ""))
# @test thispatch(JuliaVersionNumber("nightly")) == thispatch(VERSION)
@test JuliaVersionNumber("1.2.3") == v"1.2.3"
@test JuliaVersionNumber(v"1.2.3") == v"1.2.3"

0 comments on commit 541b8ec

Please sign in to comment.