I have gone through a multitude of tutorials now but still can’t seem to wrap my head around the basics of how to write and test a package as I go. I don’t understand the proper way to add my package and its dependencies to the REPL namespace or the proper way to juggle between the Main and MyPackage modules. I keep getting errors that variables, functions, or packages are undefined. I just want the simplest, foolproof workflow.
- Open
MyPackage
folder in VSCode made with PkgTemplates.jl. - Start REPL
- Activate
MyPackage
environment (usually done automatically).
I should always stay inMyPackage
environment when developingMyPackage
right? - I don’t need to
add
orusing
Revise because it is built in to the VSCode extension right? - Should I
using MyPackage
,using MyDependency
,using .MyPackage
,using .MyDependency
, or some combination?
I would assume that loadingMyPackage
would also load its dependencies, but that doesn’t always seem to be true. I have also seen some tutorials notusing MyPackage
at all and just send code to the REPL. - How do I ensure my REPL is testing with the package versions in my Project.toml and using the
MyPackage
version from my.julia/dev
folder? - Write
MyPackage.jl
:module MyPackage; using MyDependency; include("myfile.jl"); end
Should I useinclude
orincludet
here? - Start writing code in
myfile.jl
- How should I debug?
If I “Run and Debug”MyPackage.jl
, then breakpoints inmyfile.jl
are skipped and I just see “Done!”. If I “Run and Debug”myfile.jl
, thenMyPackage
andMyDependency
are not loaded and I error out. - How should I run file code and tinker in REPL?
I like to switch between writing code in file (executing with Ctrl+Enter) and writing code directly in the REPL, but that sometimes switches the current module betweenMain
andMyPackage
so things break. Do I have to stick with one or the other? Which module should my REPL be using? - How should I test sub-functions?
I can test a function in the REPL withusing MyPackage; f(x)
. However, if that function contains a sub-functionf_sub(y)
, the REPL doesn’t have access to its name so I can make sure it works. - How should I write file paths so they always point to my test data stored in
MyPackage/test/testdata/
?
I have to change the file path if I run code from the test folder or if I move the package.