Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add open_documentation() #17

Merged
merged 4 commits into from
May 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,14 @@ The code bindings within this package are autogenerated from the following
* `LibraryProduct`: `libgurobi`
* `ExecutableProduct`: `gurobi_cl`
* `ExecutableProduct`: `grbgetkey`

## Documentationn

Use `Gurobi_jll.open_documentation()` to open a local copy of the Gurobi
documentation in your browser.

```julia
julia> import Gurobi_jll

julia> Gurobi_jll.open_documentation()
```
27 changes: 27 additions & 0 deletions src/Gurobi_jll.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,31 @@ JLLWrappers.@generate_main_file_header("Gurobi")

JLLWrappers.@generate_main_file("Gurobi", UUID("c018c7e6-a5b0-4aea-8f80-9c1ef9991411"))

function get_documentation_path()
path = @static if Sys.iswindows()
joinpath("Doc", "Gurobi", "refman", "index.html")
else
joinpath("share", "doc", "gurobi", "refman", "index.html")
end
return joinpath(artifact_dir, path)
end

function _browser_command(path::String)
@static if Sys.isapple()
return `open $path`
elseif Sys.iswindows()
return `cmd /c start $path`
else
@assert Sys.islinux()
return `xdg-open $path`
end
end

"""
open_documentation()

Open a local copy of the Gurobi documentation in your browser.
"""
open_documentation() = run(_browser_command(get_documentation_path()))

end # module Gurobi_jll
22 changes: 19 additions & 3 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,23 @@ end
error = @ccall libgurobi.GRBemptyenv(envptr::Ptr{Ptr{Cvoid}})::Cint
@test error == 0
error = @ccall libgurobi.GRBstartenv(envptr[]::Ptr{Cvoid})::Cint
@test error == 10009
msg = unsafe_string(@ccall libgurobi.GRBgeterrormsg(envptr[]::Ptr{Cvoid})::Ptr{Cchar})
@test startswith(msg, "No Gurobi license found")
@test error == 10009 || error == 0
if error == 10009
ret = @ccall libgurobi.GRBgeterrormsg(envptr[]::Ptr{Cvoid})::Ptr{Cchar}
@test startswith(unsafe_string(ret), "No Gurobi license found")
end
end

@testset "open_documentation" begin
@test isfile(Gurobi_jll.get_documentation_path())
if Sys.isapple()
@test Gurobi_jll._browser_command("abc") == `open abc`
Gurobi_jll.open_documentation()
elseif Sys.iswindows()
@test Gurobi_jll._browser_command("abc") == `cmd /c start abc`
Gurobi_jll.open_documentation()
else
@test Gurobi_jll._browser_command("abc") == `xdg-open abc`
# Gurobi_jll.open_documentation() # Errors in CI
end
end
Loading