Skip to content

Commit

Permalink
Remove package extensions in Pkg functions (#20681)
Browse files Browse the repository at this point in the history
* remove package extension in Pkg functions

* Run Pkg.dependents("Example") tests at a fixed METADATA commit

to avoid fragility in the case that any future package
happens to depend on Example.jl
  • Loading branch information
fredrikekre authored and KristofferC committed Feb 27, 2017
1 parent 5c61a0a commit ccb426f
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 16 deletions.
34 changes: 19 additions & 15 deletions base/pkg/pkg.jl
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ const cd = Dir.cd

dir(path...) = Dir.path(path...)

# remove extension .jl
const PKGEXT = ".jl"
splitjl(pkg::AbstractString) = endswith(pkg, PKGEXT) ? pkg[1:(end-length(PKGEXT))] : pkg

"""
dir() -> AbstractString
Expand Down Expand Up @@ -90,7 +94,7 @@ edit() = cd(Entry.edit)
Remove all requirement entries for `pkg` from `Pkg.dir("REQUIRE")` and call `Pkg.resolve()`.
"""
rm(pkg::AbstractString) = cd(Entry.rm,pkg)
rm(pkg::AbstractString) = cd(Entry.rm,splitjl(pkg))

"""
add(pkg, vers...)
Expand All @@ -99,7 +103,7 @@ Add a requirement entry for `pkg` to `Pkg.dir("REQUIRE")` and call `Pkg.resolve(
`vers` are given, they must be `VersionNumber` objects and they specify acceptable version
intervals for `pkg`.
"""
add(pkg::AbstractString, vers::VersionNumber...) = cd(Entry.add,pkg,vers...)
add(pkg::AbstractString, vers::VersionNumber...) = cd(Entry.add,splitjl(pkg),vers...)

"""
available() -> Vector{String}
Expand All @@ -113,7 +117,7 @@ available() = cd(Entry.available)
Returns the version numbers available for package `pkg`.
"""
available(pkg::AbstractString) = cd(Entry.available,pkg)
available(pkg::AbstractString) = cd(Entry.available,splitjl(pkg))

"""
installed() -> Dict{String,VersionNumber}
Expand All @@ -129,7 +133,7 @@ installed() = cd(Entry.installed)
If `pkg` is installed, return the installed version number. If `pkg` is registered,
but not installed, return `nothing`.
"""
installed(pkg::AbstractString) = cd(Entry.installed,pkg)
installed(pkg::AbstractString) = cd(Entry.installed,splitjl(pkg))

"""
status()
Expand All @@ -143,7 +147,7 @@ status(io::IO=STDOUT) = cd(Entry.status,io)
Prints out a summary of what version and state `pkg`, specifically, is in.
"""
status(pkg::AbstractString, io::IO=STDOUT) = cd(Entry.status,io,pkg)
status(pkg::AbstractString, io::IO=STDOUT) = cd(Entry.status,io,splitjl(pkg))

"""
clone(pkg)
Expand All @@ -160,7 +164,7 @@ Clone a package directly from the git URL `url`. The package does not need to be
in `Pkg.dir("METADATA")`. The package repo is cloned by the name `pkg` if provided; if not
provided, `pkg` is determined automatically from `url`.
"""
clone(url::AbstractString, pkg::AbstractString) = cd(Entry.clone,url,pkg)
clone(url::AbstractString, pkg::AbstractString) = cd(Entry.clone,url,splitjl(pkg))

"""
checkout(pkg, [branch="master"]; merge=true, pull=true)
Expand All @@ -171,7 +175,7 @@ Checkout the `Pkg.dir(pkg)` repo to the branch `branch`. Defaults to checking ou
true`, and the latest version is pulled from the upstream repo if `pull == true`.
"""
checkout(pkg::AbstractString, branch::AbstractString="master"; merge::Bool=true, pull::Bool=true) =
cd(Entry.checkout,pkg,branch,merge,pull)
cd(Entry.checkout,splitjl(pkg),branch,merge,pull)

"""
free(pkg)
Expand All @@ -183,22 +187,22 @@ to determine optimal package versions after. This is an inverse for both `Pkg.ch
You can also supply an iterable collection of package names, e.g., `Pkg.free(("Pkg1",
"Pkg2"))` to free multiple packages at once.
"""
free(pkg) = cd(Entry.free,pkg)
free(pkg) = cd(Entry.free,splitjl.(pkg))

"""
pin(pkg)
Pin `pkg` at the current version. To go back to using the newest compatible released
version, use `Pkg.free(pkg)`
"""
pin(pkg::AbstractString) = cd(Entry.pin,pkg)
pin(pkg::AbstractString) = cd(Entry.pin,splitjl(pkg))

"""
pin(pkg, version)
Pin `pkg` at registered version `version`.
"""
pin(pkg::AbstractString, ver::VersionNumber) = cd(Entry.pin,pkg,ver)
pin(pkg::AbstractString, ver::VersionNumber) = cd(Entry.pin,splitjl(pkg),ver)

"""
update(pkgs...)
Expand Down Expand Up @@ -236,7 +240,7 @@ Run the build script in `deps/build.jl` for each package in `pkgs` and all of th
dependencies in depth-first recursive order. This is called automatically by `Pkg.resolve()`
on all installed or updated packages.
"""
build(pkgs::AbstractString...) = cd(Entry.build,[pkgs...])
build(pkgs::AbstractString...) = cd(Entry.build,[splitjl.(pkgs)...])

"""
test(; coverage=false)
Expand All @@ -258,14 +262,14 @@ installed for the duration of the test. A package is tested by running its
Coverage statistics for the packages may be generated by passing `coverage=true`.
The default behavior is not to run coverage.
"""
test(pkgs::AbstractString...; coverage::Bool=false) = cd(Entry.test,AbstractString[pkgs...]; coverage=coverage)
test(pkgs::AbstractString...; coverage::Bool=false) = cd(Entry.test,AbstractString[splitjl.(pkgs)...]; coverage=coverage)

"""
dependents(packagename)
dependents(pkg)
List the packages that have `packagename` as a dependency.
List the packages that have `pkg` as a dependency.
"""
dependents(packagename::AbstractString) = Reqs.dependents(packagename)
dependents(pkg::AbstractString) = Reqs.dependents(splitjl(pkg))

"""
setprotocol!(proto)
Expand Down
9 changes: 9 additions & 0 deletions doc/src/manual/packages.md
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,15 @@ git config --global url."https://".insteadOf git://

However, this change will be system-wide and thus the use of [`Pkg.setprotocol!()`](@ref) is preferable.

!!! note
The package manager functions also accept the `.jl` suffix on package names, though the suffix is
stripped internally. For example:

```julia
Pkg.add("Distributions.jl")
Pkg.rm("Distributions.jl")
```

## Offline Installation of Packages

For machines with no Internet connection, packages may be installed by copying the package root
Expand Down
52 changes: 51 additions & 1 deletion test/pkg.jl
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,6 @@ temp_pkg_dir() do
Pkg.status("Example", iob)
str = chomp(String(take!(iob)))
@test endswith(str, string(Pkg.installed("Example")))
@test isempty(Pkg.dependents("Example"))

# 17364 - a, Pkg.checkout with specific local branch
let branch_name = "test-branch-1",
Expand Down Expand Up @@ -462,6 +461,11 @@ temp_pkg_dir() do
LibGit2.reset!(repo, LibGit2.GitHash(old_commit), LibGit2.Consts.RESET_HARD)
end

# run these at an old metadata commit where it's guaranteed no
# packages depend on Example.jl
@test isempty(Pkg.dependents("Example"))
@test isempty(Pkg.dependents("Example.jl"))

@test_warn ("INFO: Installing Colors v0.6.4",
"INFO: Installing ColorTypes v0.2.2",
"INFO: Installing FixedPointNumbers v0.1.3",
Expand Down Expand Up @@ -496,6 +500,52 @@ temp_pkg_dir() do
end
end

@testset "Pkg functions with .jl extension" begin
temp_pkg_dir() do
@test Pkg.installed("Example.jl") === nothing
Pkg.add("Example.jl")
@test [keys(Pkg.installed())...] == ["Example"]
iob = IOBuffer()
Pkg.checkout("Example.jl")
Pkg.status("Example.jl", iob)
str = chomp(String(take!(iob)))
@test startswith(str, " - Example")
@test endswith(str, "master")
Pkg.free("Example.jl")
Pkg.status("Example.jl", iob)
str = chomp(String(take!(iob)))
@test endswith(str, string(Pkg.installed("Example.jl")))
Pkg.checkout("Example.jl")
Pkg.free(("Example.jl",))
Pkg.status("Example.jl", iob)
str = chomp(String(take!(iob)))
@test endswith(str, string(Pkg.installed("Example.jl")))
Pkg.rm("Example.jl")
@test isempty(Pkg.installed())
@test !isempty(Pkg.available("Example.jl"))
@test !in("Example", keys(Pkg.installed()))
Pkg.rm("Example.jl")
@test isempty(Pkg.installed())
@test !isempty(Pkg.available("Example.jl"))
@test !in("Example", keys(Pkg.installed()))
Pkg.clone("https://github.com/JuliaLang/Example.jl.git")
@test [keys(Pkg.installed())...] == ["Example"]
Pkg.status("Example.jl", iob)
str = chomp(String(take!(iob)))
@test startswith(str, " - Example")
@test endswith(str, "master")
Pkg.free("Example.jl")
Pkg.status("Example.jl", iob)
str = chomp(String(take!(iob)))
@test endswith(str, string(Pkg.installed("Example.jl")))
Pkg.checkout("Example.jl")
Pkg.free(("Example.jl",))
Pkg.status("Example.jl", iob)
str = chomp(String(take!(iob)))
@test endswith(str, string(Pkg.installed("Example.jl")))
end
end

let io = IOBuffer()
Base.showerror(io, Base.Pkg.Entry.PkgTestError("ppp"), backtrace())
@test !contains(String(take!(io)), "backtrace()")
Expand Down

0 comments on commit ccb426f

Please sign in to comment.