Julia: Tildes in the --project argument

Created on 14 Aug 2018  Â·  6Comments  Â·  Source: JuliaLang/julia

The --project command line argument does not expand tildes. Perhaps it should?

/tmp$ julia --project=~/Foo -e'using Pkg; Pkg.status()'
    Status `/tmp/~/Foo/Project.toml`

Would expect:

/tmp$ julia --project=~/Foo -e'using Pkg; Pkg.status()'
    Status `/home/user/Foo/Project.toml`

cc @fredrikekre since #28625 might be related?

good first issue help wanted

All 6 comments

Yes, seems like a good idea.

That's where the option is parsed but it's better to handle the user expansion later, e.g.:

diff --git a/base/initdefs.jl b/base/initdefs.jl
index 479f3bd447..0eef60b01c 100644
--- a/base/initdefs.jl
+++ b/base/initdefs.jl
@@ -214,6 +214,9 @@ function init_load_path()
     project = (JLOptions().project != C_NULL ?
         unsafe_string(Base.JLOptions().project) :
         get(ENV, "JULIA_PROJECT", nothing))
+    if project != nothing
+        project = expanduser(project)
+    end
     HOME_PROJECT[] =
         project === nothing ? nothing :
         project == "" ? nothing :

You'll need to verify that this works and test it.

Apparently Base.JLOptions().project is already expanded:

$/tmp julia --project=~/Documents -e'@show unsafe_string(Base.JLOptions().project)'                                                                                        
unsafe_string((Base.JLOptions()).project) = "/tmp/~/Documents"

With https://github.com/JuliaLang/julia/pull/31932 :

 ~/Doc…/git…/julia ./julia$ pwd
/home/akako/Documents/github/julia

 ~/Doc…/git…/julia$ ./julia --project= -e'using Pkg; Pkg.status()'                                                                                          
    Status `~/.julia/environments/v1.3/Project.toml`
  (empty environment)

 ~/Doc…/git…/julia$ ./julia --project=~ -e'using Pkg; Pkg.status()'                                                                                         
    Status `~/Project.toml`
  (no changes since last commit)

 ~/Doc…/git…/julia$ ./julia --project=~/Documents/github/Telegrambot.jl -e'using Pkg; Pkg.status()'                                                         
Project Telegrambot v0.1.3
    Status `~/Documents/github/Telegrambot.jl/Project.toml`
  [cd3eb016] HTTP v0.8.0
  [682c06a0] JSON v0.20.0
  [8dfed614] Test 
  [cf7118a7] UUIDs 

31932

Was this page helpful?
0 / 5 - 0 ratings

Related issues

omus picture omus  Â·  3Comments

Keno picture Keno  Â·  3Comments

i-apellaniz picture i-apellaniz  Â·  3Comments

StefanKarpinski picture StefanKarpinski  Â·  3Comments

dpsanders picture dpsanders  Â·  3Comments