In order to automate the instantiation of projects in non-standard/complex cases, I sometimes write small setup.jl scripts relying on Pkg’s programmatic API.
This is very nice, but I occasionally struggle finding the API equivalent for a given pkg> REPL command. I know about the equivalence table given in the PackageSpec docstring but, although it’s very useful in a lot of cases, it isn’t comprehensive and does not cover some corner cases (which is perfectly understandable for a docstring).
Apart from that, is there a way to find out the API call equivalent to a given REPL command?
If there is no general way to do that, would someone know the equivalent for the following REPL command?
Thanks. Yes, I know and this is what I end up using when I don’t know how to do better.
However, I’m always reluctant to use this because of the warnings it produces:
shell$ cat >setup.jl <<EOF
> using Pkg
> pkg"activate ."
> EOF
shell$ julia setup.jl
┌ Warning: The Pkg REPL mode is intended for interactive use only, and should not be used from scripts. It is recommended to use the functional API instead.
└ @ Pkg.REPLMode ~/.julia/juliaup/julia-1.10.7+0.x64.linux.gnu/share/julia/stdlib/v1.10/Pkg/src/REPLMode/REPLMode.jl:382
Activating new project at `/tmp`
I read that warning message as an indication that equivalent API exists for each REPL command and should be preferred in scripts. But maybe I’m wrong? Or maybe I shouldn’t care too much?
julia> methods(Pkg.develop)
# 7 methods for generic function "develop" from Pkg.API:
[1] develop(ctx::Pkg.Types.Context, pkgs::Vector{Pkg.Types.PackageSpec}; shared, preserve, platform, kwargs...)
shows a keyword argument shared, I would try setting that to false.
I believe that the main reason for the warning about using pkg-strings is that in the general case they involve various parsing heuristics, to e.g. guess if something is a URL, which might change without notice between versions.