Skip to content

Commit

Permalink
fold deactivate into no-arg activate (#432)
Browse files Browse the repository at this point in the history
  • Loading branch information
fredrikekre authored and StefanKarpinski committed Jun 29, 2018
1 parent f60d79e commit ab9eb80
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 31 deletions.
4 changes: 2 additions & 2 deletions stdlib/Pkg/docs/src/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -548,7 +548,7 @@ end # module
We can now activate the project and load the package:

```jl
pkg> activate
pkg> activate .

julia> import HelloWorld

Expand Down Expand Up @@ -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
```
Expand Down
35 changes: 16 additions & 19 deletions stdlib/Pkg/src/API.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 0 additions & 1 deletion stdlib/Pkg/src/Pkg.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 0 additions & 9 deletions stdlib/Pkg/src/REPLMode.jl
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ const cmds = Dict(
"instantiate" => CMD_INSTANTIATE,
"resolve" => CMD_RESOLVE,
"activate" => CMD_ACTIVATE,
"deactivate" => CMD_DEACTIVATE,
)

#################
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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 #
######################
Expand Down

0 comments on commit ab9eb80

Please sign in to comment.