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
MyPackagefolder in VSCode made with PkgTemplates.jl. - Start REPL
- Activate
MyPackageenvironment (usually done automatically).
I should always stay inMyPackageenvironment when developingMyPackageright? - I don’t need to
addorusingRevise 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 loadingMyPackagewould also load its dependencies, but that doesn’t always seem to be true. I have also seen some tutorials notusing MyPackageat 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
MyPackageversion from my.julia/devfolder? - Write
MyPackage.jl:module MyPackage; using MyDependency; include("myfile.jl"); end
Should I useincludeorincludethere? - Start writing code in
myfile.jl - How should I debug?
If I “Run and Debug”MyPackage.jl, then breakpoints inmyfile.jlare skipped and I just see “Done!”. If I “Run and Debug”myfile.jl, thenMyPackageandMyDependencyare 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 betweenMainandMyPackageso 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.