Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pkg.activate() doesn't seem to activate the home package #3127

Closed
jishnub opened this issue Jul 7, 2022 · 4 comments · Fixed by #3547
Closed

Pkg.activate() doesn't seem to activate the home package #3127

jishnub opened this issue Jul 7, 2022 · 4 comments · Fixed by #3547

Comments

@jishnub
Copy link
Contributor

jishnub commented Jul 7, 2022

In a project directory at

abcd/ $ pwd
/home/jishnu/Dropbox/JuliaPackages/abcd

I launch julia using

abcd/ $ julia-1.8 --project=.

In julia

julia> LOAD_PATH
4-element Vector{String}:
 "@"
 "/tmp/jl_ztlVMr"
 "@v#.#"
 "@stdlib"

julia> Base.active_project()
"/home/jishnu/Dropbox/JuliaPackages/abcd/Project.toml"

julia> using OffsetArrays
 │ Package OffsetArrays not found, but a package named OffsetArrays is available from a registry. 
 │ Install package?
 │   (abcd) pkg> add OffsetArrays 
 └ Select environment:
   1: `~/Dropbox/JuliaPackages/abcd/Project.toml` (@)
 > 2: `/tmp/jl_ztlVMr` (/tmp/jl_ztlVMr)
   3: `~/.julia/environments/v1.8/Project.toml` (@v#.#)
    Updating registry at `~/.julia/registries/General.toml`
   Resolving package versions...
    Updating `/tmp/jl_ztlVMr/Project.toml`
  [6fe1bfb0] + OffsetArrays v1.12.7
    Updating `/tmp/jl_ztlVMr/Manifest.toml`
  [79e6a3ab] + Adapt v3.3.3
  [6fe1bfb0] + OffsetArrays v1.12.7
  [56f22d72] + Artifacts
  [8f399da3] + Libdl
  [37e2e46d] + LinearAlgebra
  [e66e0078] + CompilerSupportLibraries_jll v0.5.2+0
  [4536629a] + OpenBLAS_jll v0.3.20+0
  [8e850b90] + libblastrampoline_jll v5.1.0+0

julia> Base.active_project()
"/home/jishnu/Dropbox/JuliaPackages/abcd/Project.toml"

julia> Base.current_project()
"/home/jishnu/Dropbox/JuliaPackages/abcd/Project.toml"

julia> using Pkg; Pkg.activate()
  Activating project at `/tmp/jl_ztlVMr`

julia> Base.active_project()
"/tmp/jl_ztlVMr/Project.toml"

julia> versioninfo()
Julia Version 1.8.0-rc1
Commit 6368fdc656 (2022-05-27 18:33 UTC)
Platform Info:
  OS: Linux (x86_64-pc-linux-gnu)
  CPU: 8 × 11th Gen Intel(R) Core(TM) i5-1135G7 @ 2.40GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-13.0.1 (ORCJIT, tigerlake)
  Threads: 1 on 8 virtual cores
Environment:
  LD_LIBRARY_PATH = :/usr/lib/x86_64-linux-gnu/gtk-3.0/modules
  JULIA_EDITOR = vim

The docstring says "If no argument is given to activate, then activate the home project. The home project is specified by either the --project command line option to the julia executable, or the JULIA_PROJECT environment variable.". In this case, the specified --project flag is not being activated anymore, and JULIA_PROJECT is not set. In this case, Pkg.activate() should not change the path at all, as the home project is already activated.

@danielwe
Copy link

Here's another and perhaps simpler MWE:

user@host:~/myenv$ julia --project=.
julia> using Pkg

julia> Pkg.status()
Status `~/myenv/Project.toml` (empty project)

julia> Pkg.activate(; temp=true)
  Activating new project at `/tmp/jl_gmivnG`

julia> Pkg.status()
Status `/tmp/jl_gmivnG/Project.toml` (empty project)

julia> Pkg.activate()
  Activating project at `~/.julia/environments/v1.8`

julia> Pkg.status()
Status `~/.julia/environments/v1.8/Project.toml`
  [...]

Clearly Pkg.activate() activates the default environment @v#.#, not the environment specified on the command line as claimed in the docs.

@kleinschmidt
Copy link

Noticed this too, with JULIA_PROJECT env, both 1.9:

➜ JULIA_PROJECT=~/.julia/dev/Example julia
               _
   _       _ _(_)_     |  Documentation: https://docs.julialang.org
  (_)     | (_) (_)    |
   _ _   _| |_  __ _   |  Type "?" for help, "]?" for Pkg help.
  | | | | | | |/ _` |  |
  | | |_| | | | (_| |  |  Version 1.9.0 (2023-05-07)
 _/ |\__'_|_|_|\__'_|  |  Official https://julialang.org/ release
|__/                   |

julia> using Pkg

julia> Pkg.project().path
"/Users/dkleinschmidt/.julia/dev/Example/Project.toml"

julia> ENV["JULIA_PROJECT"]
"/Users/dkleinschmidt/.julia/dev/Example"

julia> Pkg.activate()
  Activating project at `~/.julia/environments/v1.9`

julia> Pkg.project().path
"/Users/dkleinschmidt/.julia/environments/v1.9/Project.toml"

and 1.8:

➜ JULIA_PROJECT=~/.julia/dev/Example julia +1.8
               _
   _       _ _(_)_     |  Documentation: https://docs.julialang.org
  (_)     | (_) (_)    |
   _ _   _| |_  __ _   |  Type "?" for help, "]?" for Pkg help.
  | | | | | | |/ _` |  |
  | | |_| | | | (_| |  |  Version 1.8.5 (2023-01-08)
 _/ |\__'_|_|_|\__'_|  |  Official https://julialang.org/ release
|__/                   |

julia> using Pkg

julia> Pkg.project().path
"/Users/dkleinschmidt/.julia/dev/Example/Project.toml"

julia> ENV["JULIA_PROJECT"]
"/Users/dkleinschmidt/.julia/dev/Example"

julia> Pkg.activate()
  Activating project at `~/.julia/environments/v1.8`

julia> Pkg.project().path
"/Users/dkleinschmidt/.julia/environments/v1.8/Project.toml"

@kleinschmidt
Copy link

kleinschmidt commented May 12, 2023

It looks like in this case, we're calling into Base.active_project(), so I think this may actually be a base issue

Pkg.jl/src/API.jl

Line 1820 in daf02a4

p = Base.active_project()

@kleinschmidt
Copy link

Okay, the relevant bits in base AFAICT are:

julia> LOAD_PATH
3-element Vector{String}:
 "@"
 "@v#.#"
 "@stdlib"

julia> ENV["JULIA_PROJECT"]
"/Users/dkleinschmidt/.julia/dev/Example"
  • expand_load_path calls back into active_project for @, with search_load_path=false (I guess to avoid infinite loop?)

So what this all comes down to is that active_project ends up completely ignoring @, which corresponds to the "home project"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants