Error in command line arg --project with "~"

I was testing a package and want to set the package as my project directory for test.
When I pass my relative path ~/.julia/dev/Gym/ as --project=, the following error occurs.

vish@eliteone:~/.julia/dev/Gym$ julia --project=~/.julia/dev/Gym/ -e "using Pkg; Pkg.test(\"Gym\")" --color=yes
ERROR: The following package names could not be resolved:
 * Gym (not found in project or manifest)
Please specify by known `name=uuid`.
Stacktrace:
 [1] pkgerror(::String) at /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.1/Pkg/src/Types.jl:120
 [2] #ensure_resolved#72(::Bool, ::Function, ::Pkg.Types.EnvCache, ::Array{Pkg.Types.PackageSpec,1}) at /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.1/Pkg/src/Types.jl:1010
 [3] ensure_resolved at /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.1/Pkg/src/Types.jl:981 [inlined]
 [4] #test#44(::Bool, ::Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}}, ::Function, ::Pkg.Types.Context, ::Array{Pkg.Types.PackageSpec,1}) at /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.1/Pkg/src/API.jl:189
 [5] test at /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.1/Pkg/src/API.jl:178 [inlined]
 [6] #test#43 at /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.1/Pkg/src/API.jl:175 [inlined]
 [7] test at /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.1/Pkg/src/API.jl:175 [inlined]
 [8] #test#42 at /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.1/Pkg/src/API.jl:174 [inlined]
 [9] test at /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.1/Pkg/src/API.jl:174 [inlined]
 [10] #test#41(::Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}}, ::Function, ::String) at /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.1/Pkg/src/API.jl:173
 [11] test(::String) at /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.1/Pkg/src/API.jl:173
 [12] top-level scope at none:0

However if I specify the full path, it works.

vish@eliteone:~/.julia/dev/Gym$ julia --project=/home/vish/.julia/dev/Gym/ -e "using Pkg; Pkg.test(\"Gym\")" --color=yes
   Testing Gym
 Resolving package versions...
Test Summary: | Pass  Broken  Total
Spaces        |   82      12     94
   Testing Gym tests passed 

How can I expand “~” for setting project automatically?

Only your shell knows what ~ means; to Julia it’s just another character. However, you can tell your shell to expand it to your actual home directory using the $HOME environment variable. For example:

julia --project="$HOME/.julia/dev/Gym" ...
2 Likes

Thanks :slight_smile: It works!

Note that you don’t need an absolute path to --project, so from the example above where you already are in the same folder as your project you can just use

julia --project=.

or use

julia --project

which makes julia look for a project file in $PWD and upwards.

2 Likes

Julia could also address this issue internally,

by calling expanduser on the string.

Sure, but calling that a “fix” is already making a judgment call about which behavior is correct. I’m not saying we shouldn’t do it but it’s not obviously the right thing to do.

If we agree that ~ is a fairly universal way of indicating user’s home directory and the variable correspond to a directory, then i would think it’s reasonable to expand the character. The drawback is that it would never recognize ~ itself as part of a directory path without escaping it.

I did not understand this part. Why escape it?

It would be an edge case that some crazy person could still use the ~ character as part of a directory name. If we always expand on it then this directory can never be referenced. Honestly I don’t think that’s a big deal.

You could avoid that edge case by only matching the ~ character at the beginning of the path?

1 Like

That’s a great point!

Seems like a good idea. Would one of you mind opening an issue about changing the project option to expand the user name?

1 Like