Skip to content

Commit fcb1e4f

Browse files
00vareladavidKristofferC
authored andcommitted
Refactor activate to avoid complexity in the main method (#559)
1 parent 0ecaf2d commit fcb1e4f

File tree

2 files changed

+20
-22
lines changed

2 files changed

+20
-22
lines changed

stdlib/Pkg/src/API.jl

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -547,29 +547,27 @@ function status(ctx::Context, mode=PKGMODE_PROJECT)
547547
return
548548
end
549549

550-
function activate(path::Union{String,Nothing}=nothing)
551-
if path !== nothing
552-
devpath = nothing
553-
env = Base.active_project() === nothing ? nothing : EnvCache()
554-
if env !== nothing && haskey(env.project["deps"], path)
555-
uuid = UUID(env.project["deps"][path])
556-
info = manifest_info(env, uuid)
557-
devpath = haskey(info, "path") ? joinpath(dirname(env.project_file), info["path"]) : nothing
558-
end
559-
# `pkg> activate path`/`Pkg.activate(path)` does the following
560-
# 1. if path exists, activate that
561-
# 2. if path exists in deps, and the dep is deved, activate that path (`devpath` above)
562-
# 3. activate the non-existing directory (e.g. as in `pkg> activate .` for initing a new env)
563-
if Types.isdir_windows_workaround(path)
564-
path = abspath(path)
565-
elseif devpath !== nothing
566-
path = abspath(devpath)
567-
else
568-
path = abspath(path)
569-
end
550+
activate() = (Base.ACTIVE_PROJECT[] = Base.load_path_expand(nothing))
551+
function activate(path::String)
552+
devpath = nothing
553+
env = Base.active_project() === nothing ? nothing : EnvCache()
554+
if env !== nothing && haskey(env.project["deps"], path)
555+
uuid = UUID(env.project["deps"][path])
556+
info = manifest_info(env, uuid)
557+
devpath = haskey(info, "path") ? joinpath(dirname(env.project_file), info["path"]) : nothing
558+
end
559+
# `pkg> activate path`/`Pkg.activate(path)` does the following
560+
# 1. if path exists, activate that
561+
# 2. if path exists in deps, and the dep is deved, activate that path (`devpath` above)
562+
# 3. activate the non-existing directory (e.g. as in `pkg> activate .` for initing a new env)
563+
if Types.isdir_windows_workaround(path)
564+
path = abspath(path)
565+
elseif devpath !== nothing
566+
path = abspath(devpath)
567+
else
568+
path = abspath(path)
570569
end
571570
Base.ACTIVE_PROJECT[] = Base.load_path_expand(path)
572-
return
573571
end
574572

575573
"""

stdlib/Pkg/src/REPLMode.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -603,7 +603,7 @@ do_up!(ctx::APIOptions, args::PkgArguments, api_opts::APIOptions) =
603603

604604
function do_activate!(args::PkgArguments, api_opts::APIOptions)
605605
if isempty(args)
606-
return API.activate(nothing)
606+
return API.activate()
607607
else
608608
return API.activate(args[1])
609609
end

0 commit comments

Comments
 (0)