Skip to content

Commit

Permalink
Refactor activate to avoid complexity in the main method (#559)
Browse files Browse the repository at this point in the history
  • Loading branch information
00vareladavid authored and KristofferC committed Aug 4, 2018
1 parent 0ecaf2d commit fcb1e4f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 22 deletions.
40 changes: 19 additions & 21 deletions stdlib/Pkg/src/API.jl
Original file line number Diff line number Diff line change
Expand Up @@ -547,29 +547,27 @@ function status(ctx::Context, mode=PKGMODE_PROJECT)
return
end

function activate(path::Union{String,Nothing}=nothing)
if path !== nothing
devpath = nothing
env = Base.active_project() === nothing ? nothing : EnvCache()
if env !== nothing && haskey(env.project["deps"], path)
uuid = UUID(env.project["deps"][path])
info = manifest_info(env, uuid)
devpath = haskey(info, "path") ? joinpath(dirname(env.project_file), info["path"]) : nothing
end
# `pkg> activate path`/`Pkg.activate(path)` does the following
# 1. if path exists, activate that
# 2. if path exists in deps, and the dep is deved, activate that path (`devpath` above)
# 3. activate the non-existing directory (e.g. as in `pkg> activate .` for initing a new env)
if Types.isdir_windows_workaround(path)
path = abspath(path)
elseif devpath !== nothing
path = abspath(devpath)
else
path = abspath(path)
end
activate() = (Base.ACTIVE_PROJECT[] = Base.load_path_expand(nothing))
function activate(path::String)
devpath = nothing
env = Base.active_project() === nothing ? nothing : EnvCache()
if env !== nothing && haskey(env.project["deps"], path)
uuid = UUID(env.project["deps"][path])
info = manifest_info(env, uuid)
devpath = haskey(info, "path") ? joinpath(dirname(env.project_file), info["path"]) : nothing
end
# `pkg> activate path`/`Pkg.activate(path)` does the following
# 1. if path exists, activate that
# 2. if path exists in deps, and the dep is deved, activate that path (`devpath` above)
# 3. activate the non-existing directory (e.g. as in `pkg> activate .` for initing a new env)
if Types.isdir_windows_workaround(path)
path = abspath(path)
elseif devpath !== nothing
path = abspath(devpath)
else
path = abspath(path)
end
Base.ACTIVE_PROJECT[] = Base.load_path_expand(path)
return
end

"""
Expand Down
2 changes: 1 addition & 1 deletion stdlib/Pkg/src/REPLMode.jl
Original file line number Diff line number Diff line change
Expand Up @@ -603,7 +603,7 @@ do_up!(ctx::APIOptions, args::PkgArguments, api_opts::APIOptions) =

function do_activate!(args::PkgArguments, api_opts::APIOptions)
if isempty(args)
return API.activate(nothing)
return API.activate()
else
return API.activate(args[1])
end
Expand Down

0 comments on commit fcb1e4f

Please sign in to comment.