Skip to content

Commit

Permalink
Refactor examples function
Browse files Browse the repository at this point in the history
  • Loading branch information
juliohm committed Jul 12, 2017
1 parent 36b6db7 commit 91287d2
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/GeoStats.jl
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ include("plotrecipes/theoretical_variograms.jl")
# helper function to launch examples from Julia prompt
function examples()
@eval using IJulia
@eval notebook(dir=joinpath(Pkg.dir("GeoStats"),"examples"))
@eval notebook(dir=Pkg.dir("GeoStats","examples"))
end

export
Expand Down

14 comments on commit 91287d2

@tkelman
Copy link
Contributor

Choose a reason for hiding this comment

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

this is in a .jl file not copy-pasted so @__DIR__ would work correctly here

@juliohm
Copy link
Member Author

Choose a reason for hiding this comment

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

@tkelman this is the error message that I get when I use @__DIR__:

ERROR: MethodError: no method matching joinpath(::Void, ::String)
Closest candidates are:
  joinpath(::String, ::String) at path.jl:208
  joinpath(::AbstractString, ::AbstractString) at path.jl:217
  joinpath(::AbstractString, ::AbstractString, ::AbstractString...) at path.jl:205
Stacktrace:
 [1] examples() at /home/juliohm/.julia/v0.6/GeoStats/src/GeoStats.jl:37

@tkelman
Copy link
Contributor

Choose a reason for hiding this comment

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

remove the eval on the notebook call?

@juliohm
Copy link
Member Author

Choose a reason for hiding this comment

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

ERROR: MethodError: no method matching notebook(; dir="/home/juliohm/.julia/v0.6/GeoStats/src/examples")
Closest candidates are:
  notebook(; dir, detached) at /home/juliohm/.julia/v0.6/IJulia/src/IJulia.jl:104
Stacktrace:
 [1] examples() at /home/juliohm/.julia/v0.6/GeoStats/src/GeoStats.jl:37

@juliohm
Copy link
Member Author

Choose a reason for hiding this comment

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

Should we merge this tag now and report the issue with Pkg.dir() somewhere else? As far as I remember, there are goals of fixing Pkg.dir() to work from any directory?

@tkelman
Copy link
Contributor

Choose a reason for hiding this comment

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

Was there a world age warning on that? Maybe

opennotebook(dir) = notebook(dir=dir)
Base.invokelatest(opennotebook, joinpath(@__DIR__,"..","examples"))

@juliohm
Copy link
Member Author

Choose a reason for hiding this comment

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

That one works, it is a little convoluted though? Final version looks like:

function examples()
  @eval using IJulia
  opennotebook(dir) = notebook(dir=dir)
  Base.invokelatest(opennotebook, joinpath(@__DIR__,"..","examples"))
end

@juliohm
Copy link
Member Author

Choose a reason for hiding this comment

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

I will update the PR in METADATA to include this.

@tkelman
Copy link
Contributor

@tkelman tkelman commented on 91287d2 Jul 13, 2017

Choose a reason for hiding this comment

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

It's exactly what invokelatest is for, though it doesn't support keyword arguments on 0.6 (an omission probably, there's a PR for it on master and it may make it into Compat but it's not there yet)

@juliohm
Copy link
Member Author

Choose a reason for hiding this comment

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

Thank you, I will also update the thread on Discourse.

@tkelman
Copy link
Contributor

Choose a reason for hiding this comment

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

ref JuliaLang/julia#22646 for adding support for kwargs to invokelatest

@juliohm
Copy link
Member Author

Choose a reason for hiding this comment

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

Someone also posted an alternative in Discourse that works:

function examples()
  path = joinpath(@__DIR__,"..","examples")
  @eval using IJulia
  @eval notebook(dir=$path)
end

Is that one fine? It looks cleaner to me.

@juliohm
Copy link
Member Author

Choose a reason for hiding this comment

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

Please let me know if it is not fine, I will update the PR soon.

@tkelman
Copy link
Contributor

Choose a reason for hiding this comment

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

that works too

Please sign in to comment.