It seems like this should be a common work flow, but I’ve been messing with this for over an hour and none of the examples seem to be what I need or I’m messing something up.
I have a great new project I’m developing. It isn’t for github release but lives on a local gitlab. The project isn’t mature enough to include in that registry. My pluto file is saved at the same level as the Project.toml for this development directory. I could put it in a subdirectory, but since nothing was working, I didn’t want to complicate things. For now until mature, I would imagine the Pluto doc would come along with this package repo and not be pulled in separately.
When I run test cases, for example, I can just do
using mypackage.submodule1
using mypackage.submodule2
When I invoke that same logic, it can’t find mypackage in pluto, of course and says I need to add it.
I try to add it in a variety of ways that I thought were the examples in the Pluto documentation, but it complains about one thing or another.
What is the best Pluto syntax and workflow to use the Pluto Notebook to help me continue to develop the package and also show as an example of how to utilize my package?
Pluto uses it’s integrated package manager by default to simplify user experience in most cases. This avoid the need of setting up your own environment yourself but also has the caveat that you can only use packages that are registered (either in the general registry or in a custom registry).
For using packages that are not registered you have to revert back to using a local environment using Pkg.activate as mentioned in the Pluto wiki
This also allows to have Revise work for packages that are added as dev in your local environment, but you have to make sure that Revise is loaded before the devd package on Pluto. The easiest way to achieve this is to have the statement using Revise in the same cell that calls Pkg.activate, and all the other using in a separate cell.
So for example you want to have the following two cells in your Pluto notebook for loading packages:
# ╔═╡ 64a29f5e-3334-43bb-a23f-8bfda53af1a4
begin
import Pkg
# I used Base.current_project() because you mentioned that your notebook is located in the same folder of the Project.toml
Pkg.activate(Base.current_project())
using Revise # Revise must be in your LOAD_PATH
end
# ╔═╡ 21761862-acb6-4691-97f0-a756865ac1cc
begin
using PkgA
using PkgB
# Other using/import statements
end
Actually, it doesn’t work.
Perhaps it is because I have submodules. I don’t know.
begin
using mypackage.submodule1
using mypackage.submodule2
end
Gives me an error that looks like this
ArgumentError: Package mypackage not found in current path.
- Run `import Pkg; Pkg.add("mypackage")` to install the mypackage package.
macro expansion@loading.jl:1630[inlined]
macro expansion@lock.jl:267[inlined]
require(::Module, ::Symbol)@loading.jl:1611
top-level scope@Local: 2
No that shouldn’t be a problem, I used submodules of local packages in Pluto before, are you sure you activated the correct environment and that it contains the target package?
It shows the correct project and status in the command window when I run Pkg.status() in Pluto, but “mypackage” is does not appear in that status list because it is there by default since it is the package I am working on.
Thank you very much for all of your help. It’s a stupid typo.
I had multiple using in a begin-end block. One of the mypackage (not its real name) had a typo in its name that was difficult to see (which may mean it is time for new glasses). Since I could see the first couple of usings were correct it was confusing to me. I started breaking out the using into their own cells and the first few worked. That’s when I discovered I’m an idiot.
But your help assured me it was user error, so I really appreciate the explanations. It always seems easy until it isn’t.