Creating package with PkgTemplate: Stuck following video tutorial

I’m following this video (Developing Julia Packages) and I’m getting stuck when doing using MyExample in my runtests.jl file in the test folder (around 8m30s onwards in the video).

I’m using Mac so the file structure is slightly different but otherwise I have followed all the steps. I think only 2 differences in the setup between me and the video.
1: I put the package folder in ./julia/dev (I had to create the dev folder but .julia was already there).
2: When I run generate("MyExample", t) there is a warning that unrecognised keywords were supplied (relating to license="MIT") and a warning that generate("MyExample", t) is deprecated and I should use t("MyExample") instead. (This is after running t = Template(; ... ))

Everything appears to be in place in the folder on my computer and in the GitHub repository. In my src folder I have two files as in the video, myExample.jl with contents

module MyExample

# Write your package code here.

include("extra_file.jl")

end

and extra_file.jl with contents

my_f(x,y) = 2x+y

In the test folder I have the file runtests.jl with contents

using MyExample
using Test

my_f(2,1)

@testset "MyExample.jl" begin
    my_f(2,1)
end

If I do cmd+enter on the line my_f(x,y)=2x+y in extra_file.jl then I can do cmd+enter on my_f(2,1) in runtests.jl and the little popup has a 5 in it. But if I try to cmd+enter using MyExample in run_tests.jl, I get an error message in the popup ArgumentError: Package MyExample not found in current path. Doing cmd+enter on using Test works. I don’t think the video does anything path related so I’m not sure what to do here.

I also tried using .MyExample in runtests.jl which didn’t work (the error is UndefVarError: MyExample not defined).

If I run MyExample.jl in src then I can do using .MyExample but this is quite different to what is done in the video (the dot isn’t used and the file is not executed). Doing using MyExample after running MyExample.jl does not work.

If I restart the Julia process in the REPL then again doing cmd+enter on using MyExample gives the same ArgumentError as previously.

I can’t work out what is happening here. The only logical thing I can think of is a path issue but I don’t think I have done anything with my Julia path and the video doesn’t mention anything to with path either. Any help would be appreciated.

As someone who has recently struggled with all this myself, I feel for you.

I think the missing step here is activating the package. In the repl, type ] to go into package mode and then type:


activate ~/.julia/dev/MyExample

tests should then work. Replace ~/.julia/dev/MyExample as needed, of course.

That’s an excellent video but it’s easy to miss steps following along a video - I certainly did.

Graham

4 Likes

That was it, thank you!

Thanks a lot @grahamstark and @DavidA! I struggled with the same problem for hours… I will link this post to the video’s comments.

1 Like