Skip to content

Commit

Permalink
only look for Project files in installed (#539)
Browse files Browse the repository at this point in the history
  • Loading branch information
KristofferC committed Aug 4, 2018
1 parent 6358631 commit ebdefc1
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 44 deletions.
3 changes: 0 additions & 3 deletions stdlib/Pkg/docs/src/index.md
@@ -1,8 +1,5 @@
# Pkg

!!! warning
This documentation is a work in progress and the information in it might be or become outdated.

## Introduction

Pkg is the standard package manager for Julia 1.0 and newer. Unlike traditional
Expand Down
3 changes: 2 additions & 1 deletion stdlib/Pkg/src/API.jl
Expand Up @@ -253,7 +253,8 @@ function test(ctx::Context, pkgs::Vector{PackageSpec}; coverage=false, kwargs...
end


function installed(mode::PackageMode=PKGMODE_MANIFEST)
installed() = __installed(PKGMODE_PROJECT)
function __installed(mode::PackageMode=PKGMODE_MANIFEST)
diffs = Display.status(Context(), mode, #=use_as_api=# true)
version_status = Dict{String, Union{VersionNumber,Nothing}}()
diffs == nothing && return version_status
Expand Down
2 changes: 1 addition & 1 deletion stdlib/Pkg/src/REPLMode.jl
Expand Up @@ -699,7 +699,7 @@ function complete_package(s, i1, i2, lastcommand, project_opt)
end

function complete_installed_package(s, i1, i2, project_opt)
pkgs = project_opt ? API.installed(PKGMODE_PROJECT) : API.installed()
pkgs = project_opt ? API.__installed(PKGMODE_PROJECT) : API.__installed()
pkgs = sort!(collect(keys(filter((p) -> p[2] != nothing, pkgs))))
cmp = filter(cmd -> startswith(cmd, s), pkgs)
return cmp, i1:i2, !isempty(cmp)
Expand Down
32 changes: 16 additions & 16 deletions stdlib/Pkg/test/pkg.jl
Expand Up @@ -136,18 +136,18 @@ temp_pkg_dir() do project_path
@testset "adding and upgrading different versions" begin
# VersionNumber
Pkg.add(PackageSpec(TEST_PKG.name, v"0.3"))
@test Pkg.installed()[TEST_PKG.name] == v"0.3"
@test Pkg.API.__installed()[TEST_PKG.name] == v"0.3"
Pkg.add(PackageSpec(TEST_PKG.name, v"0.3.1"))
@test Pkg.installed()[TEST_PKG.name] == v"0.3.1"
@test Pkg.API.__installed()[TEST_PKG.name] == v"0.3.1"
Pkg.rm(TEST_PKG.name)

# VersionRange
Pkg.add(PackageSpec(TEST_PKG.name, VersionSpec(VersionRange("0.3.0-0.3.2"))))
@test Pkg.installed()[TEST_PKG.name] == v"0.3.2"
@test Pkg.API.__installed()[TEST_PKG.name] == v"0.3.2"
Pkg.update(; level = UPLEVEL_PATCH)
@test Pkg.installed()[TEST_PKG.name] == v"0.3.3"
@test Pkg.API.__installed()[TEST_PKG.name] == v"0.3.3"
Pkg.update(; level = UPLEVEL_MINOR)
@test Pkg.installed()[TEST_PKG.name].minor != 3
@test Pkg.API.__installed()[TEST_PKG.name].minor != 3
Pkg.rm(TEST_PKG.name)
end

Expand All @@ -164,26 +164,26 @@ temp_pkg_dir() do project_path

@testset "pinning / freeing" begin
Pkg.add(TEST_PKG.name)
old_v = Pkg.installed()[TEST_PKG.name]
old_v = Pkg.API.__installed()[TEST_PKG.name]
Pkg.pin(PackageSpec(TEST_PKG.name, v"0.2"))
@test Pkg.installed()[TEST_PKG.name].minor == 2
@test Pkg.API.__installed()[TEST_PKG.name].minor == 2
Pkg.update(TEST_PKG.name)
@test Pkg.installed()[TEST_PKG.name].minor == 2
@test Pkg.API.__installed()[TEST_PKG.name].minor == 2
Pkg.free(TEST_PKG.name)
Pkg.update()
@test Pkg.installed()[TEST_PKG.name] == old_v
@test Pkg.API.__installed()[TEST_PKG.name] == old_v
Pkg.rm(TEST_PKG.name)
end

@testset "develop / freeing" begin
Pkg.add(TEST_PKG.name)
old_v = Pkg.installed()[TEST_PKG.name]
old_v = Pkg.API.__installed()[TEST_PKG.name]
Pkg.rm(TEST_PKG.name)
mktempdir() do devdir
withenv("JULIA_PKG_DEVDIR" => devdir) do
Pkg.develop(TEST_PKG.name)
@test isinstalled(TEST_PKG)
@test Pkg.installed()[TEST_PKG.name] > old_v
@test Pkg.API.__installed()[TEST_PKG.name] > old_v
test_pkg_main_file = joinpath(devdir, TEST_PKG.name, "src", TEST_PKG.name * ".jl")
@test isfile(test_pkg_main_file)
# Pkg #152
Expand All @@ -209,7 +209,7 @@ temp_pkg_dir() do project_path
@test isfile(joinpath(devdir, TEST_PKG.name, "deps", "deps.jl"))
Pkg.test(TEST_PKG.name)
Pkg.free(TEST_PKG.name)
@test Pkg.installed()[TEST_PKG.name] == old_v
@test Pkg.API.__installed()[TEST_PKG.name] == old_v
end
end
end
Expand All @@ -221,7 +221,7 @@ temp_pkg_dir() do project_path
@testset "stdlibs as direct dependency" begin
uuid_pkg = (name = "CRC32c", uuid = UUID("8bf52ea8-c179-5cab-976a-9e18b702a9bc"))
Pkg.add("CRC32c")
@test haskey(Pkg.installed(), uuid_pkg.name)
@test haskey(Pkg.API.__installed(), uuid_pkg.name)
Pkg.update()
# Disable until fixed in Base
# Pkg.test("CRC32c")
Expand Down Expand Up @@ -298,7 +298,7 @@ temp_pkg_dir() do project_path
cd(joinpath(dir, "UnregisteredWithProject")) do
with_current_env() do
Pkg.update()
@test haskey(Pkg.installed(), "Example")
@test haskey(Pkg.API.__installed(), "Example")
end
end
end
Expand All @@ -308,12 +308,12 @@ end
temp_pkg_dir() do project_path
@testset "libgit2 downloads" begin
Pkg.add(TEST_PKG.name; use_libgit2_for_all_downloads=true)
@test haskey(Pkg.installed(), TEST_PKG.name)
@test haskey(Pkg.API.__installed(), TEST_PKG.name)
Pkg.rm(TEST_PKG.name)
end
@testset "tarball downloads" begin
Pkg.add("JSON"; use_only_tarballs_for_downloads=true)
@test haskey(Pkg.installed(), "JSON")
@test haskey(Pkg.API.__installed(), "JSON")
Pkg.rm("JSON")
end
end
Expand Down
40 changes: 17 additions & 23 deletions stdlib/Pkg/test/repl.jl
Expand Up @@ -103,7 +103,7 @@ temp_pkg_dir() do project_path; cd(project_path) do; mktempdir() do tmp_pkg_path
pkg"activate ."
pkg"add Example"
@test isinstalled(TEST_PKG)
v = Pkg.installed()[TEST_PKG.name]
v = Pkg.API.__installed()[TEST_PKG.name]
pkg"rm Example"
pkg"add Example#master"

Expand All @@ -117,12 +117,12 @@ temp_pkg_dir() do project_path; cd(project_path) do; mktempdir() do tmp_pkg_path

pkg"test Example"
@test isinstalled(TEST_PKG)
@test Pkg.installed()[TEST_PKG.name] > v
@test Pkg.API.__installed()[TEST_PKG.name] > v
pkg = "UnregisteredWithoutProject"
p = git_init_package(tmp_pkg_path, joinpath(@__DIR__, "test_packages/$pkg"))
Pkg.REPLMode.pkgstr("add $p; precompile")
@eval import $(Symbol(pkg))
@test Pkg.installed()[pkg] == v"0.0"
@test Pkg.API.__installed()[pkg] == v"0.0"
Pkg.test("UnregisteredWithoutProject")

pkg2 = "UnregisteredWithProject"
Expand All @@ -133,7 +133,7 @@ temp_pkg_dir() do project_path; cd(project_path) do; mktempdir() do tmp_pkg_path
# FIXME: why isn't this testing the Pkg after importing, rather than after freeing it
#@eval import Example
#@eval import $(Symbol(pkg2))
@test Pkg.installed()[pkg2] == v"0.1.0"
@test Pkg.API.__installed()[pkg2] == v"0.1.0"
Pkg.REPLMode.pkgstr("free $pkg2")
@test_throws PkgError Pkg.REPLMode.pkgstr("free $pkg2")
Pkg.test("UnregisteredWithProject")
Expand All @@ -148,7 +148,7 @@ temp_pkg_dir() do project_path; cd(project_path) do; mktempdir() do tmp_pkg_path
LibGit2.add!(repo, "*")
LibGit2.commit(repo, "bump version"; author = TEST_SIG, committer=TEST_SIG)
pkg"update"
@test Pkg.installed()[pkg2] == v"0.2.0"
@test Pkg.API.__installed()[pkg2] == v"0.2.0"
Pkg.REPLMode.pkgstr("rm $pkg2")

c = LibGit2.commit(repo, "empty commit"; author = TEST_SIG, committer=TEST_SIG)
Expand All @@ -173,7 +173,7 @@ temp_pkg_dir() do project_path; cd(project_path) do; mktempdir() do tmp_pkg_path
mktempdir() do depot_dir
pushfirst!(DEPOT_PATH, depot_dir)
pkg"instantiate"
@test Pkg.installed()[pkg2] == v"0.2.0"
@test Pkg.API.__installed()[pkg2] == v"0.2.0"
end
finally
empty!(DEPOT_PATH)
Expand Down Expand Up @@ -207,8 +207,8 @@ temp_pkg_dir() do project_path; cd(project_path) do
Pkg.REPLMode.pkgstr("build; precompile")
@test Base.find_package("UnregisteredWithProject") == joinpath(p1_new_path, "src", "UnregisteredWithProject.jl")
@test Base.find_package("UnregisteredWithoutProject") == joinpath(p2_new_path, "src", "UnregisteredWithoutProject.jl")
@test Pkg.installed()["UnregisteredWithProject"] == v"0.1.0"
@test Pkg.installed()["UnregisteredWithoutProject"] == v"0.0.0"
@test Pkg.API.__installed()["UnregisteredWithProject"] == v"0.1.0"
@test Pkg.API.__installed()["UnregisteredWithoutProject"] == v"0.0.0"
Pkg.test("UnregisteredWithoutProject")
Pkg.test("UnregisteredWithProject")

Expand All @@ -235,8 +235,8 @@ temp_pkg_dir() do project_path; cd(project_path) do
mkdir("tests")
cd("tests")
pkg"develop ../SubModule2"
@test Pkg.installed()["SubModule1"] == v"0.1.0"
@test Pkg.installed()["SubModule2"] == v"0.1.0"
@test Pkg.API.__installed()["SubModule1"] == v"0.1.0"
@test Pkg.API.__installed()["SubModule2"] == v"0.1.0"
# make sure paths to SubModule1 and SubModule2 are relative
manifest = Pkg.Types.Context().env.manifest
@test manifest["SubModule1"][1]["path"] == "SubModule1"
Expand Down Expand Up @@ -454,7 +454,9 @@ temp_pkg_dir() do project_path
setup_package(parent_dir, pkg_name) = begin
mkdir(parent_dir)
cd(parent_dir) do
Pkg.generate(pkg_name)
withenv("USER" => "Test User") do
Pkg.generate(pkg_name)
end
cd(pkg_name) do
LibGit2.with(LibGit2.init(joinpath(project_path, parent_dir, pkg_name))) do repo
LibGit2.add!(repo, "*")
Expand Down Expand Up @@ -833,9 +835,7 @@ end
@test_throws PkgError Pkg.REPLMode.pkgstr("-x add Example")
# malformed, but registered meta option
@test_throws PkgError Pkg.REPLMode.pkgstr("--env Example")
end
end
end
end end end
end

@testset "activate" begin
Expand All @@ -847,9 +847,7 @@ end
@test Base.active_project() == joinpath(pwd(), "Foo", "Project.toml")
pkg"activate"
@test Base.active_project() == default
end
end
end
end end end
end

@testset "subcommands" begin
Expand All @@ -858,9 +856,7 @@ end
@test isinstalled(TEST_PKG)
Pkg.REPLMode.pkg"package rm Example"
@test !isinstalled(TEST_PKG)
end
end
end
end end end
end

@testset "`parse_quotes` unit tests" begin
Expand All @@ -880,9 +876,7 @@ end
@test_throws PkgError pkg"pin Example#foo"
@test_throws PkgError pkg"test Example#foo"
@test_throws PkgError pkg"test Example@v0.0.1"
end
end
end
end end end
end

end # module

0 comments on commit ebdefc1

Please sign in to comment.