From ab9eb806783c7550ff08b7a32076126595a19fde Mon Sep 17 00:00:00 2001 From: Fredrik Ekre Date: Tue, 26 Jun 2018 21:12:17 +0200 Subject: [PATCH] fold deactivate into no-arg activate (#432) --- stdlib/Pkg/docs/src/index.md | 4 ++-- stdlib/Pkg/src/API.jl | 35 ++++++++++++++++------------------- stdlib/Pkg/src/Pkg.jl | 1 - stdlib/Pkg/src/REPLMode.jl | 9 --------- 4 files changed, 18 insertions(+), 31 deletions(-) diff --git a/stdlib/Pkg/docs/src/index.md b/stdlib/Pkg/docs/src/index.md index 0f08a5c2d55d6..6b88225fbb800 100644 --- a/stdlib/Pkg/docs/src/index.md +++ b/stdlib/Pkg/docs/src/index.md @@ -548,7 +548,7 @@ end # module We can now activate the project and load the package: ```jl -pkg> activate +pkg> activate . julia> import HelloWorld @@ -773,7 +773,7 @@ However, nothing would be installed and your `Project.toml` and `Manifest.toml` Simply clone their project using e.g. `git clone`, `cd` to the project directory and call ``` -(v0.7) pkg> activate +(v0.7) pkg> activate . (SomeProject) pkg> instantiate ``` diff --git a/stdlib/Pkg/src/API.jl b/stdlib/Pkg/src/API.jl index 6284a13f908b2..4797644f8a2f2 100644 --- a/stdlib/Pkg/src/API.jl +++ b/stdlib/Pkg/src/API.jl @@ -550,29 +550,26 @@ end const ACTIVE_ENV = Ref{Union{String,Nothing}}(nothing) -function _activate(env::Union{String,Nothing}) - if env === nothing - @warn "Current directory is not in a project, nothing activated." - else +function activate(path::Union{String,Nothing}=nothing) + if path === nothing # reset to default LOAD_PATH if !isempty(LOAD_PATH) && ACTIVE_ENV[] === LOAD_PATH[1] - LOAD_PATH[1] = env + popfirst!(LOAD_PATH) + end + ACTIVE_ENV[] = nothing + else # activate the env found in path + env = Base.current_env(path) + if env === nothing + @warn "Current directory is not in a project, nothing activated." else - # TODO: warn if ACTIVE_ENV !== nothing ? - pushfirst!(LOAD_PATH, env) + if !isempty(LOAD_PATH) && ACTIVE_ENV[] === LOAD_PATH[1] + LOAD_PATH[1] = env + else + pushfirst!(LOAD_PATH, env) + end + ACTIVE_ENV[] = env end - ACTIVE_ENV[] = env - end -end -activate() = _activate(Base.current_env()) -activate(path::String) = _activate(Base.current_env(path)) - -function deactivate() - if !isempty(LOAD_PATH) && ACTIVE_ENV[] === LOAD_PATH[1] - popfirst!(LOAD_PATH) - else - # warn if ACTIVE_ENV !== nothing ? end - ACTIVE_ENV[] = nothing + return ACTIVE_ENV[] end end # module diff --git a/stdlib/Pkg/src/Pkg.jl b/stdlib/Pkg/src/Pkg.jl index a12382a77a172..c54d1921eeb47 100644 --- a/stdlib/Pkg/src/Pkg.jl +++ b/stdlib/Pkg/src/Pkg.jl @@ -44,7 +44,6 @@ const resolve = API.resolve const status = Display.status const update = up const activate = API.activate -const deactivate = API.deactivate # legacy CI script support import .API: clone, dir diff --git a/stdlib/Pkg/src/REPLMode.jl b/stdlib/Pkg/src/REPLMode.jl index aa517e4c0f35d..3fc0dea103f81 100644 --- a/stdlib/Pkg/src/REPLMode.jl +++ b/stdlib/Pkg/src/REPLMode.jl @@ -49,7 +49,6 @@ const cmds = Dict( "instantiate" => CMD_INSTANTIATE, "resolve" => CMD_RESOLVE, "activate" => CMD_ACTIVATE, - "deactivate" => CMD_DEACTIVATE, ) ################# @@ -279,7 +278,6 @@ function do_cmd!(tokens::Vector{Token}, repl) cmd.kind == CMD_PRECOMPILE ? Base.invokelatest( do_precompile!, ctx, tokens) : cmd.kind == CMD_INSTANTIATE ? Base.invokelatest( do_instantiate!, ctx, tokens) : cmd.kind == CMD_ACTIVATE ? Base.invokelatest( do_activate!, ctx, tokens) : - cmd.kind == CMD_DEACTIVATE ? Base.invokelatest( do_deactivate!, ctx, tokens) : cmderror("`$cmd` command not yet implemented") return end @@ -345,8 +343,6 @@ developed packages `gc`: garbage collect packages not used for a significant time `activate`: set the primary environment the package manager manipulates - -`deactivate`: unset the primary environment the package manager manipulates """ const helps = Dict( @@ -794,11 +790,6 @@ function do_activate!(ctx::Context, tokens::Vector{Token}) end end -function do_deactivate!(ctx::Context, tokens::Vector{Token}) - !isempty(tokens) && cmderror("`deactivate` does not take any arguments") - API.deactivate() -end - ###################### # REPL mode creation # ######################