Skip to content

Commit

Permalink
allow using a path kword arg to PackageSpec (#580)
Browse files Browse the repository at this point in the history
  • Loading branch information
KristofferC committed Aug 4, 2018
1 parent f647d70 commit e804d11
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 28 deletions.
10 changes: 5 additions & 5 deletions stdlib/Pkg/src/Pkg.jl
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ const activate = API.activate

"""
PackageSpec(name::String, [uuid::UUID, version::VersionNumber])
PackageSpec(; name, url, rev, version, mode, level)
PackageSpec(; name, url, path, rev, version, mode, level)
A `PackageSpec` is a representation of a package with various metadata.
This includes:
Expand All @@ -301,8 +301,8 @@ This includes:
* The package unique `uuid`.
* A `version` (for example when adding a package. When upgrading, can also be an instance of
the enum [`UpgradeLevel`](@ref)
* A `url` (which might also be a local path) and an optional git `rev`ision.
`rev` could be a branch name or a git commit SHA.
* A `url` and an optional git `rev`ision. `rev` could be a branch name or a git commit SHA.
* A local path `path`. This is equivalent to using the `url` argument but can be more descriptive.
* A `mode`, which is an instance of the enum [`PackageMode`](@ref) which can be either `PKGMODE_PROJECT` or
`PKGMODE_MANIFEST`, defaults to `PKGMODE_PROJECT`. Used in e.g. [`Pkg.rm`](@ref).
Expand All @@ -317,8 +317,8 @@ Below is a comparison between the REPL version and the `PackageSpec` version:
| `Package@0.2` | `PackageSpec(name="Package", version="0.2")` |
| `Package=a67d...` | `PackageSpec(name="Package", uuid="a67d..."` |
| `Package#master` | `PackageSpec(name="Package", rev="master")` |
| `local/path#feature` | `PackageSpec(url="local/path"; rev="feature)` |
| `www.mypkg.com` | `PackageSpec("url=www.mypkg.com")` |
| `local/path#feature` | `PackageSpec(path="local/path"; rev="feature)` |
| `www.mypkg.com` | `PackageSpec(url="www.mypkg.com")` |
| `--manifest Package` | `PackageSpec(name="Package", mode=PKGSPEC_MANIFEST)`|
| `--major Package` | `PackageSpec(name="Package", version=PKGLEVEL_MAJOR`)|
"""
Expand Down
18 changes: 1 addition & 17 deletions stdlib/Pkg/src/REPLMode.jl
Original file line number Diff line number Diff line change
Expand Up @@ -666,22 +666,6 @@ long_commands = []
all_options_sorted = []
long_options = []

all_commands_sorted = sort(collect(String,keys(command_specs)))
long_commands = filter(c -> length(c) > 2, all_commands_sorted)
function all_options()
all_opts = []
for command in values(command_specs)
for opt_spec in command.option_specs
push!(all_opts, opt_spec.name)
opt_spec.short_name !== nothing && push!(all_opts, opt_spec.short_name)
end
end
unique!(all_opts)
return all_opts
end
all_options_sorted = [length(opt) > 1 ? "--$opt" : "-$opt" for opt in sort!(all_options())]
long_options = filter(c -> length(c) > 2, all_options_sorted)

struct PkgCompletionProvider <: LineEdit.CompletionProvider end

function LineEdit.complete_line(c::PkgCompletionProvider, s)
Expand Down Expand Up @@ -1220,7 +1204,7 @@ is modified.
], #package
] #command_declarations

super_specs = SuperSpecs(command_declarations) # TODO should this go here ?
super_specs = SuperSpecs(command_declarations)
command_specs = super_specs["package"]
all_commands_sorted = sort(collect(String,keys(command_specs)))
long_commands = filter(c -> length(c) > 2, all_commands_sorted)
Expand Down
13 changes: 9 additions & 4 deletions stdlib/Pkg/src/Types.jl
Original file line number Diff line number Diff line change
Expand Up @@ -169,9 +169,14 @@ function PackageSpec(repo::GitRepo)
end

# kwarg constructor
function PackageSpec(;name::AbstractString="", uuid::Union{String, UUID}=UUID(0), version::Union{VersionNumber, String} = "*",
url = nothing, rev = nothing, mode::PackageMode = PKGMODE_PROJECT)
if url !== nothing || rev !== nothing
function PackageSpec(;name::AbstractString="", uuid::Union{String, UUID}=UUID(0),
version::Union{VersionNumber, String, VersionSpec} = VersionSpec(),
url = nothing, rev = nothing, path=nothing, mode::PackageMode = PKGMODE_PROJECT)
if url !== nothing || path !== nothing || rev !== nothing
if path !== nothing || url !== nothing
path !== nothing && url !== nothing && cmderror("cannot specify both path and url")
url = url == nothing ? path : url
end
repo = GitRepo(url=url, rev=rev)
else
repo = nothing
Expand All @@ -190,7 +195,7 @@ function Base.show(io::IO, pkg::PackageSpec)
f = ["name" => pkg.name, "uuid" => has_uuid(pkg) ? pkg.uuid : "", "v" => (vstr == "VersionSpec(\"*\")" ? "" : vstr)]
if pkg.repo !== nothing
if !isempty(pkg.repo.url)
push!(f, "url/path" => pkg.repo.url)
push!(f, "url/path" => string("\"", pkg.repo.url, "\""))
end
if !isempty(pkg.repo.rev)
push!(f, "rev" => pkg.repo.rev)
Expand Down
2 changes: 1 addition & 1 deletion stdlib/Pkg/test/api.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ using Pkg, Test
cd(mkdir("modules")) do
Pkg.generate("Foo")
end
Pkg.develop(Pkg.Types.PackageSpec(url="modules/Foo")) # to avoid issue #542
Pkg.develop(Pkg.Types.PackageSpec(path="modules/Foo")) # to avoid issue #542
Pkg.activate("Foo") # activate path Foo over deps Foo
@test Base.active_project() == joinpath(path, "Foo", "Project.toml")
Pkg.activate(".")
Expand Down
2 changes: 1 addition & 1 deletion stdlib/Pkg/test/pkg.jl
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ temp_pkg_dir() do project_path
@testset "inconsistent repo state" begin
package_path = joinpath(project_path, "Example")
LibGit2.with(LibGit2.clone("https://github.com/JuliaLang/Example.jl", package_path)) do repo
Pkg.add(PackageSpec(url=package_path))
Pkg.add(PackageSpec(path=package_path))
end
rm(joinpath(package_path, ".git"); force=true, recursive=true)
@test_throws CommandError Pkg.update()
Expand Down

0 comments on commit e804d11

Please sign in to comment.