Skip to content

Commit

Permalink
active project: get rid of the concept of a home project (JuliaLang#3…
Browse files Browse the repository at this point in the history
…6434)

This makes doing `julia --project` equivalent to activating the
project that the current directory is in at Julia startup. What
this means is that if you do `pkg> activate` instead of taking
you back to whatever project was initially active, it will make
it as if you had never activated a project in the first place.
  • Loading branch information
StefanKarpinski authored and simeonschaub committed Aug 11, 2020
1 parent fb2e8b6 commit 7635b12
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 12 deletions.
7 changes: 7 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@ Compiler/Runtime improvements
Command-line option changes
---------------------------

* There is no longer a concept of "home project": starting `julia --project=dir`
is now exactly equivalent to starting `julia` and then doing `pkg> activate
$dir` and `julia --project` is exactly equivalent to doing that where
`dir = Base.current_project()`. In particular, this means that if you do
`pkg> activate` after starting `julia` with the `--project` option (or with
`JULIA_PROJECT` set) it will take you to the default active project, which is
`@v1.5` unless you have modified `LOAD_PATH`. ([#36434])

Multi-threading changes
-----------------------
Expand Down
1 change: 1 addition & 0 deletions base/Base.jl
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,7 @@ function __init__()
# initialize loading
init_depot_path()
init_load_path()
init_active_project()
nothing
end

Expand Down
12 changes: 8 additions & 4 deletions base/initdefs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ function init_depot_path()
end
end

## LOAD_PATH, HOME_PROJECT & ACTIVE_PROJECT ##
## LOAD_PATH & ACTIVE_PROJECT ##

# JULIA_LOAD_PATH: split on `:` (or `;` on Windows)
# first empty entry is replaced with DEFAULT_LOAD_PATH, the rest are skipped
Expand Down Expand Up @@ -155,6 +155,7 @@ See also:
[Code Loading](@ref Code-Loading).
"""
const LOAD_PATH = copy(DEFAULT_LOAD_PATH)
# HOME_PROJECT is no longer used, here just to avoid breaking things
const HOME_PROJECT = Ref{Union{String,Nothing}}(nothing)
const ACTIVE_PROJECT = Ref{Union{String,Nothing}}(nothing)

Expand Down Expand Up @@ -211,14 +212,17 @@ function init_load_path()
paths = filter!(env -> env !== nothing,
[env == "@." ? current_project() : env for env in DEFAULT_LOAD_PATH])
end
append!(empty!(LOAD_PATH), paths)
end

function init_active_project()
project = (JLOptions().project != C_NULL ?
unsafe_string(Base.JLOptions().project) :
get(ENV, "JULIA_PROJECT", nothing))
HOME_PROJECT[] =
ACTIVE_PROJECT[] =
project === nothing ? nothing :
project == "" ? nothing :
project == "@." ? current_project() : abspath(expanduser(project))
append!(empty!(LOAD_PATH), paths)
end

## load path expansion: turn LOAD_PATH entries into concrete paths ##
Expand Down Expand Up @@ -262,7 +266,7 @@ end
load_path_expand(::Nothing) = nothing

function active_project(search_load_path::Bool=true)
for project in (ACTIVE_PROJECT[], HOME_PROJECT[])
for project in (ACTIVE_PROJECT[],)
project == "@" && continue
project = load_path_expand(project)
project === nothing && continue
Expand Down
4 changes: 2 additions & 2 deletions base/loading.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1194,7 +1194,7 @@ function load_path_setup_code(load_path::Bool=true)
code *= """
append!(empty!(Base.LOAD_PATH), $(repr(load_path)))
ENV["JULIA_LOAD_PATH"] = $(repr(join(load_path, Sys.iswindows() ? ';' : ':')))
Base.HOME_PROJECT[] = Base.ACTIVE_PROJECT[] = nothing
Base.ACTIVE_PROJECT[] = nothing
"""
end
return code
Expand All @@ -1206,7 +1206,7 @@ function include_package_for_output(input::String, depot_path::Vector{String}, d
append!(empty!(Base.DL_LOAD_PATH), dl_load_path)
append!(empty!(Base.LOAD_PATH), load_path)
ENV["JULIA_LOAD_PATH"] = join(load_path, Sys.iswindows() ? ';' : ':')
Base.HOME_PROJECT[] = Base.ACTIVE_PROJECT[] = nothing
Base.ACTIVE_PROJECT[] = nothing
Base._track_dependencies[] = true
append!(empty!(Base._concrete_dependencies), concrete_deps)

Expand Down
3 changes: 0 additions & 3 deletions stdlib/InteractiveUtils/src/InteractiveUtils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -365,12 +365,9 @@ function report_bug(kind)
mktempdir() do tmp
old_load_path = copy(LOAD_PATH)
push!(empty!(LOAD_PATH), joinpath(tmp, "Project.toml"))
old_home_project = Base.HOME_PROJECT[]
Base.HOME_PROJECT[] = nothing
Pkg.add(Pkg.PackageSpec(BugReportingId.name, BugReportingId.uuid))
BugReporting = Base.require(BugReportingId)
append!(empty!(LOAD_PATH), old_load_path)
Base.HOME_PROJECT[] = old_home_project
end
end
else
Expand Down
3 changes: 0 additions & 3 deletions test/loading.jl
Original file line number Diff line number Diff line change
Expand Up @@ -183,12 +183,10 @@ end

saved_load_path = copy(LOAD_PATH)
saved_depot_path = copy(DEPOT_PATH)
saved_home_project = Base.HOME_PROJECT[]
saved_active_project = Base.ACTIVE_PROJECT[]

push!(empty!(LOAD_PATH), "project")
push!(empty!(DEPOT_PATH), "depot")
Base.HOME_PROJECT[] = nothing
Base.ACTIVE_PROJECT[] = nothing

@test load_path() == [abspath("project","Project.toml")]
Expand Down Expand Up @@ -667,7 +665,6 @@ end

append!(empty!(LOAD_PATH), saved_load_path)
append!(empty!(DEPOT_PATH), saved_depot_path)
Base.HOME_PROJECT[] = saved_home_project
Base.ACTIVE_PROJECT[] = saved_active_project

# issue #28190
Expand Down

0 comments on commit 7635b12

Please sign in to comment.