Skip to content

Commit

Permalink
Implement --local and --shared (default) options for develop. (#519)
Browse files Browse the repository at this point in the history
The --shared option places the package in Pkg.devdir(),
and the --local option places the package in a dev sub-directory
of the current project.
  • Loading branch information
fredrikekre authored and KristofferC committed Feb 11, 2019
1 parent 8d58928 commit b745759
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 10 deletions.
4 changes: 2 additions & 2 deletions stdlib/Pkg/src/API.jl
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ add_or_develop(pkg::Union{String, PackageSpec}; kwargs...) = add_or_develop([pkg
add_or_develop(pkgs::Vector{String}; kwargs...) = add_or_develop([check_package_name(pkg) for pkg in pkgs]; kwargs...)
add_or_develop(pkgs::Vector{PackageSpec}; kwargs...) = add_or_develop(Context(), pkgs; kwargs...)

function add_or_develop(ctx::Context, pkgs::Vector{PackageSpec}; mode::Symbol, kwargs...)
function add_or_develop(ctx::Context, pkgs::Vector{PackageSpec}; mode::Symbol, devdir::Union{String,Nothing}=nothing, kwargs...)
Context!(ctx; kwargs...)

# All developed packages should go through handle_repos_develop so just give them an empty repo
Expand All @@ -43,7 +43,7 @@ function add_or_develop(ctx::Context, pkgs::Vector{PackageSpec}; mode::Symbol, k

ctx.preview && preview_info()
if mode == :develop
new_git = handle_repos_develop!(ctx, pkgs)
new_git = handle_repos_develop!(ctx, pkgs, something(devdir, Pkg.devdir()))
else
new_git = handle_repos_add!(ctx, pkgs; upgrade_or_add=true)
end
Expand Down
25 changes: 19 additions & 6 deletions stdlib/Pkg/src/REPLMode.jl
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ end
# Options #
###########
@enum(OptionKind, OPT_ENV, OPT_PROJECT, OPT_MANIFEST, OPT_MAJOR, OPT_MINOR,
OPT_PATCH, OPT_FIXED, OPT_COVERAGE, OPT_NAME)
OPT_PATCH, OPT_FIXED, OPT_COVERAGE, OPT_NAME,
OPT_LOCAL, OPT_SHARED)

function Types.PackageMode(opt::OptionKind)
opt == OPT_MANIFEST && return PKGMODE_MANIFEST
Expand Down Expand Up @@ -107,6 +108,8 @@ const opts = Dict(
"fixed" => OPT_FIXED,
"coverage" => OPT_COVERAGE,
"name" => OPT_NAME,
"local" => OPT_LOCAL,
"shared" => OPT_SHARED,
)

function parse_option(word::AbstractString)::Option
Expand Down Expand Up @@ -547,11 +550,13 @@ const helps = Dict(
Free a pinned package `pkg`, which allows it to be upgraded or downgraded again. If the package is checked out (see `help develop`) then this command
makes the package no longer being checked out.
""", CMD_DEVELOP => md"""
develop pkg[=uuid] [#rev] ...
develop [--shared|--local] pkg[=uuid] [#rev] ...
Make a package available for development. If `pkg` is an existing local path that path will be recorded in
the manifest and used. Otherwise, a full git clone of `pkg` at rev `rev` is made. The clone is stored in `devdir`,
which defaults to `~/.julia/dev` and is set by the environment variable `JULIA_PKG_DEVDIR`.
the manifest and used. Otherwise, a full git clone of `pkg` at rev `rev` is made. The location of the clone is
controlled by the `--shared` (default) and `--local` arguments. The `--shared` location defaults to
`~/.julia/dev`, but can be controlled with the `JULIA_PKG_DEVDIR` environment variable. When `--local` is given,
the clone is placed in a `dev` folder in the current project.
This operation is undone by `free`.
*Example*
Expand All @@ -560,6 +565,7 @@ const helps = Dict(
pkg> develop Example#master
pkg> develop Example#c37b675
pkg> develop https://github.com/JuliaLang/Example.jl#master
pkg> develop --local Example
```
""", CMD_PRECOMPILE => md"""
precompile
Expand Down Expand Up @@ -638,6 +644,7 @@ function do_add_or_develop!(ctx::Context, tokens::Vector{Token}, cmd::CommandKin
isempty(tokens) &&
cmderror("`$mode` – list packages to $mode")
pkgs = PackageSpec[]
dev_mode = OPT_SHARED # TODO: Make this default configurable
while !isempty(tokens)
token = popfirst!(tokens)
if token isa String
Expand All @@ -653,10 +660,16 @@ function do_add_or_develop!(ctx::Context, tokens::Vector{Token}, cmd::CommandKin
pkgs[end].repo.rev = token.rev
end
elseif token isa Option
cmderror("`$mode` doesn't take options: $token")
if mode === :develop && token.kind in (OPT_LOCAL, OPT_SHARED)
dev_mode = token.kind
else
cmderror("`$mode` doesn't take options: $token")
end
end
end
return API.add_or_develop(ctx, pkgs, mode=mode)
dev_dir = mode === :add ? nothing : dev_mode == OPT_LOCAL ?
joinpath(dirname(ctx.env.project_file), "dev") : nothing
return API.add_or_develop(ctx, pkgs, mode=mode, devdir=dev_dir)
end

function do_up!(ctx::Context, tokens::Vector{Token})
Expand Down
4 changes: 2 additions & 2 deletions stdlib/Pkg/src/Types.jl
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,7 @@ end

casesensitive_isdir(dir::String) = isdir_windows_workaround(dir) && dir in readdir(joinpath(dir, ".."))

function handle_repos_develop!(ctx::Context, pkgs::AbstractVector{PackageSpec})
function handle_repos_develop!(ctx::Context, pkgs::AbstractVector{PackageSpec}, devdir::String)
Base.shred!(LibGit2.CachedCredentials()) do creds
env = ctx.env
new_uuids = UUID[]
Expand Down Expand Up @@ -547,7 +547,7 @@ function handle_repos_develop!(ctx::Context, pkgs::AbstractVector{PackageSpec})
end

parse_package!(ctx, pkg, project_path)
dev_pkg_path = joinpath(Pkg.devdir(), pkg.name)
dev_pkg_path = joinpath(devdir, pkg.name)
if isdir(dev_pkg_path)
if !isfile(joinpath(dev_pkg_path, "src", pkg.name * ".jl"))
cmderror("Path `$(dev_pkg_path)` exists but it does not contain `src/$(pkg.name).jl")
Expand Down
13 changes: 13 additions & 0 deletions stdlib/Pkg/test/repl.jl
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,19 @@ cd(mktempdir()) do
@test Base.active_project() == joinpath(path, "Example", "Project.toml")
end

# develop with --shared and --local
using Pkg.Types: manifest_info, EnvCache
cd(mktempdir()) do
uuid = UUID("7876af07-990d-54b4-ab0e-23690620f79a") # Example
pkg"activate ."
pkg"develop Example" # test --shared default
@test manifest_info(EnvCache(), uuid)["path"] == joinpath(Pkg.devdir(), "Example")
pkg"develop --shared Example"
@test manifest_info(EnvCache(), uuid)["path"] == joinpath(Pkg.devdir(), "Example")
pkg"develop --local Example"
@test manifest_info(EnvCache(), uuid)["path"] == joinpath("dev", "Example")
end

test_complete(s) = Pkg.REPLMode.completions(s,lastindex(s))
apply_completion(str) = begin
c, r, s = test_complete(str)
Expand Down

0 comments on commit b745759

Please sign in to comment.