Folder Navigation for Activating Environments in Package Manager

I am a Mac user. Let’s say I have a package under development, Foo.jl, that is present under the folder ~/github/Foo.jl on my machine (here the tilde is the home directory, standard for Macs). I am writing another script elsewhere, say under ~/scripts/script.jl that needs to include the package Foo.jl.

To make sure I don’t get an error when trying using Foo, I would like to activate the environment for the package, which I would normally do with ] activate . while in the highest level of the package. I know that you can specify a path to activate environments other than the standard Julia one and whichever folder you are currently in, but running ] activate "~/github/Foo.jl" creates a new environment inside of ~/scripts/~/github/Foo.jl, which is obviously not my intention.

Is there a way to express that I am giving the absolute path of the directory, i.e., to recognize that the ~ character means “home directory”?

I know, of course, that I can do a series of ../../.. for as long as it takes to get back to ~, but I’m sure it’s understandable that this can become cumbersome the farther I am from ~. I could also do ; cd ~/github/Foo.jl and then ] activate ., but I am hoping there is something a little nicer than that.

Thanks in advance!

Hi, I believe that must methods do not expand the ~ by default (maybe to enforce cross-platform consistency).

Ex:

julia> abspath("~") == abspath(homedir())
false

julia> abspath(expanduser("~")) == abspath(homedir())
true

You can use joinpath(homedir(), "github", "Foo.jl") instead.

1 Like

Also it is maybe better for you to use the Pkg API not the REPL.

import Pkg
Pkg.activate(here_a_path)
1 Like

When you quote the path it is taken literally, and e.g. ~ is not expanded (this behavior is likely the same in your shell). If you use

] activate ~/github/Foo.jl

it should work.

1 Like

That was silly of me, it works now! Thanks so much!