Yes. Here is the documentation:
https://pkgdocs.julialang.org/v1/api/#Pkg.add
In particular, take a look at PackageSpec
which has a path
keyword argument.
https://pkgdocs.julialang.org/v1/api/#Pkg.PackageSpec
Let’s say I use PkgTemplates
and customize dir
to be ~/src
so the package lives at ~/src/MyPkg
as follows:
julia> using PkgTemplates
julia> Template(interactive=true)("MyPkg")
Template keywords to customize:
[press: d=done, a=all, n=none]
[ ] user
[ ] authors
> [X] dir
[ ] host
[ ] julia
[ ] plugins
Enter value for 'dir' (String, default="~/.julia/dev"): ~/src
[ Info: Running prehooks
[ Info: Running hooks
Activating project at `~/src/MyPkg`
...
Then I use the Pkg REPL as follows to add the package to a temporary environment:
(@v1.7) pkg> activate --temp
Activating new project at `/tmp/jl_OOV4GX`
(jl_OOV4GX) pkg> add ~/src/MyPkg
Cloning git-repo `/home/mkitti/src/MyPkg`
Updating git-repo `/home/mkitti/src/MyPkg`
Resolving package versions...
Updating `/tmp/jl_OOV4GX/Project.toml`
[6b62e0e2] + MyPkg v0.1.0 `/home/mkitti/src/MyPkg#main`
Updating `/tmp/jl_OOV4GX/Manifest.toml`
[6b62e0e2] + MyPkg v0.1.0 `/home/mkitti/src/MyPkg#main`
Precompiling project...
1 dependency successfully precompiled in 1 seconds
As Chris, mentioned, I can also dev
the package:
(jl_OOV4GX) pkg> dev ~/src/MyPkg
Resolving package versions...
Updating `/tmp/jl_OOV4GX/Project.toml`
[6b62e0e2] ~ MyPkg v0.1.0 `/home/mkitti/src/MyPkg#main` ⇒ v0.1.0 `~/src/MyPkg`
Updating `/tmp/jl_OOV4GX/Manifest.toml`
[6b62e0e2] ~ MyPkg v0.1.0 `/home/mkitti/src/MyPkg#main` ⇒ v0.1.0 `~/src/MyPkg`
If you prefer to use the Pkg
API, this is the equivalent of the above:
julia> using Pkg
julia> Pkg.activate(temp=true)
Activating new project at `/tmp/jl_xGkOLr`
julia> Pkg.add(path="/home/mkitti/src/MyPkg")
Updating git-repo `/home/mkitti/src/MyPkg`
Resolving package versions...
Updating `/tmp/jl_xGkOLr/Project.toml`
[6b62e0e2] + MyPkg v0.1.0 `/home/mkitti/src/MyPkg#main`
Updating `/tmp/jl_xGkOLr/Manifest.toml`
[6b62e0e2] + MyPkg v0.1.0 `/home/mkitti/src/MyPkg#main`
julia> Pkg.develop(path="/home/mkitti/src/MyPkg")
Resolving package versions...
Updating `/tmp/jl_xGkOLr/Project.toml`
[6b62e0e2] ~ MyPkg v0.1.0 `/home/mkitti/src/MyPkg#main` ⇒ v0.1.0 `~/src/MyPkg`
Updating `/tmp/jl_xGkOLr/Manifest.toml`
[6b62e0e2] ~ MyPkg v0.1.0 `/home/mkitti/src/MyPkg#main` ⇒ v0.1.0 `~/src/MyPkg`
If you want to use PackageSpec
directly, that is also possible:
julia> using Pkg
julia> mypkg = PackageSpec(path="/home/mkitti/src/MyPkg")
PackageSpec(
path = /home/mkitti/src/MyPkg
version = *
)
julia> Pkg.add(mypkg)
Updating git-repo `/home/mkitti/src/MyPkg`
Resolving package versions...
Updating `/tmp/jl_atZNj8/Project.toml`
[6b62e0e2] + MyPkg v0.1.0 `/home/mkitti/src/MyPkg#main`
Updating `/tmp/jl_atZNj8/Manifest.toml`
[6b62e0e2] + MyPkg v0.1.0 `/home/mkitti/src/MyPkg#main`
julia> Pkg.develop(mypkg)
Resolving package versions...
Updating `/tmp/jl_atZNj8/Project.toml`
[6b62e0e2] ~ MyPkg v0.1.0 `/home/mkitti/src/MyPkg#main` ⇒ v0.1.0 `~/src/MyPkg`
Updating `/tmp/jl_atZNj8/Manifest.toml`
[6b62e0e2] ~ MyPkg v0.1.0 `/home/mkitti/src/MyPkg#main` ⇒ v0.1.0 `~/src/MyPkg`
Just in case it is confusing, you only have to use either add
or develop
.