Skip to content

Commit

Permalink
Try #1088:
Browse files Browse the repository at this point in the history
  • Loading branch information
bors[bot] committed Mar 29, 2019
2 parents 347260a + 6d16af8 commit 443bb5f
Show file tree
Hide file tree
Showing 8 changed files with 77 additions and 23 deletions.
41 changes: 32 additions & 9 deletions src/Operations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -224,9 +224,9 @@ function collect_project!(ctx::Context, pkg::PackageSpec, path::String, fix_deps
if haskey(compat, "julia") && !(VERSION in Types.semver_spec(compat["julia"]))
@warn("julia version requirement for package $(pkg.name) not satisfied")
end
for (deppkg_name, uuid) in project.deps
vspec = haskey(compat, deppkg_name) ? Types.semver_spec(compat[deppkg_name]) : VersionSpec()
deppkg = PackageSpec(deppkg_name, uuid, vspec)
for (name, uuid) in project.deps
vspec = haskey(compat, name) ? Types.semver_spec(compat[name]) : VersionSpec()
deppkg = PackageSpec(name, uuid, vspec)
push!(fix_deps_map[pkg.uuid], deppkg)
end
if project.version !== nothing
Expand All @@ -238,20 +238,43 @@ function collect_project!(ctx::Context, pkg::PackageSpec, path::String, fix_deps
return true
end

is_fixed(pkg::PackageSpec) = pkg.path !== nothing || pkg.repo.url !== nothing
function collect_unregistered(ctx::Context, pkg::PackageSpec, unregistered::Vector{PackageSpec})
path = project_rel_path(ctx, source_path(pkg))
isdir(path) ||
pkgerror("`$(pkg.name) = $(pkg.uuid)` does not exist at `$path`")
manifest_file = manifestfile_path(path; strict=true)
# no manifest -> stop looking early
manifest_file !== nothing || return
manifest = read_manifest(manifest_file)
for (uuid, entry) in manifest
entry.path !== nothing || entry.repo.url !== nothing || continue
unreg_pkg = PackageSpec(;uuid=uuid, name=entry.name,
path=entry.path, repo=entry.repo, tree_hash=entry.tree_hash)
# TODO does this need a version? (I don't think so)
push!(unregistered, unreg_pkg)
collect_unregistered(ctx, unreg_pkg, unregistered)
end
end

function collect_unregistered(ctx::Context, pkgs::Vector{PackageSpec})
unregistered = PackageSpec[]
foreach(pkg -> collect_unregistered(ctx, pkg, unregistered),
filter(is_unregistered, pkgs))
return unregistered
end

function collect_fixed!(ctx::Context, pkgs::Vector{PackageSpec}, names::Dict{UUID, String})
fix_deps_map = Dict{UUID,Vector{PackageSpec}}()
for pkg in pkgs
# collect developed indirect deps
append!(pkgs, collect_unregistered(ctx, pkgs))
for pkg in filter(is_unregistered, pkgs)
path = project_rel_path(ctx, source_path(pkg))
if !isdir(path)
pkgerror("path $(path) for package $(pkg.name) no longer exists. Remove the package or `develop` it at a new path")
end

found_project = collect_project!(ctx, pkg, path, fix_deps_map)
if !found_project
collect_project!(ctx, pkg, path, fix_deps_map) ||
collect_require!(ctx, pkg, path, fix_deps_map)
end
end

fixed = Dict{UUID,Fixed}()
Expand Down Expand Up @@ -288,7 +311,7 @@ function resolve_versions!(ctx::Context, pkgs::Vector{PackageSpec})

# construct data structures for resolver and call it
# this also sets pkg.version for fixed packages
fixed = collect_fixed!(ctx, filter(is_fixed, pkgs), names)
fixed = collect_fixed!(ctx, pkgs, names)

# non fixed packages are `add`ed by version: their version is either restricted or free
# fixed packages are `dev`ed or `add`ed by repo
Expand Down
2 changes: 2 additions & 0 deletions src/Types.jl
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export UUID, pkgID, SHA1, VersionRange, VersionSpec, empty_versionspec,
PackageSpecialAction, PKGSPEC_NOTHING, PKGSPEC_PINNED, PKGSPEC_FREED, PKGSPEC_DEVELOPED, PKGSPEC_TESTED, PKGSPEC_REPO_ADDED,
printpkgstyle,
projectfile_path, manifestfile_path,
is_unregistered,
RegistrySpec

include("versions.jl")
Expand Down Expand Up @@ -251,6 +252,7 @@ Base.@kwdef mutable struct PackageEntry
other::Union{Dict,Nothing} = nothing
end
const Manifest = Dict{UUID,PackageEntry}
is_unregistered(pkg) = pkg.path !== nothing || pkg.repo.url !== nothing

function Base.show(io::IO, pkg::PackageEntry)
f = []
Expand Down
2 changes: 1 addition & 1 deletion src/generate.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ function generate(ctx::Context, path::String; kwargs...)
uuid = project(pkg, dir; preview=ctx.preview)
entrypoint(pkg, dir; preview=ctx.preview)
ctx.preview && preview_info()
return Dict(pkg => uuid)
return uuid
end

function genfile(f::Function, pkg::String, dir::String, file::String; preview::Bool)
Expand Down
2 changes: 1 addition & 1 deletion src/project.jl
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ function read_project_deps(raw::Dict{String,Any}, section_name::String)
uuid = UUID(uuid)
catch err
err isa ArgumentError || rethrow()
pkgerror("Malfomed value for `$name` in `$(section_name)` section.")
pkgerror("Malformed value for `$name` in `$(section_name)` section.")
end
deps[name] = uuid
end
Expand Down
8 changes: 4 additions & 4 deletions test/api.jl
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,10 @@ end
# explicit relative path
with_temp_env() do env_path
cd(env_path) do
uuids = Pkg.generate("Foo")
foo_uuid = Pkg.generate("Foo")
Pkg.develop(PackageSpec(;path="Foo"))
manifest = Pkg.Types.read_manifest(joinpath(env_path, "Manifest.toml"))
entry = manifest[uuids["Foo"]]
entry = manifest[foo_uuid]
end
@test entry.path == "Foo"
@test entry.name == "Foo"
Expand All @@ -85,11 +85,11 @@ end
# explicit absolute path
with_temp_env() do env_path
cd_tempdir() do temp_dir
uuids = Pkg.generate("Foo")
foo_uuid = Pkg.generate("Foo")
absolute_path = abspath(joinpath(temp_dir, "Foo"))
Pkg.develop(PackageSpec(;path=absolute_path))
manifest = Pkg.Types.read_manifest(joinpath(env_path, "Manifest.toml"))
entry = manifest[uuids["Foo"]]
entry = manifest[foo_uuid]
@test entry.name == "Foo"
@test entry.path == absolute_path
@test isdir(entry.path)
Expand Down
25 changes: 25 additions & 0 deletions test/pkg.jl
Original file line number Diff line number Diff line change
Expand Up @@ -747,6 +747,31 @@ end
end end
end

@testset "Pkg automatically detects unregistered packages" begin
temp_pkg_dir() do project_path; cd_tempdir() do tempdir
# Target dependency graph: A --> B -->C
# +---> D -->E
uuids = Dict(map(projname -> (projname => Pkg.generate(projname)),
["A", "B", "C", "D", "E"]))
git_init_package("E")
Pkg.activate("B")
Pkg.develop(Pkg.PackageSpec(path=joinpath(tempdir, "C")))
Pkg.activate("D")
Pkg.add(Pkg.PackageSpec(path=joinpath(tempdir, "E"), rev="master"))
Pkg.activate("A")
Pkg.develop(Pkg.PackageSpec(path="B"))
Pkg.develop(Pkg.PackageSpec(path="D"))
manifest = Pkg.Types.Context().env.manifest
c = get(manifest, uuids["C"], nothing)
@test c !== nothing
@test c.path == joinpath(tempdir, "C")
e = get(manifest, uuids["E"], nothing)
@test e !== nothing
@test e.repo.url == joinpath(tempdir, "E")
@test e.repo.rev == "master"
end end
end

include("repl.jl")
include("api.jl")
include("registry.jl")
Expand Down
12 changes: 6 additions & 6 deletions test/repl.jl
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,8 @@ temp_pkg_dir() do project_path; cd(project_path) do
pkg"generate HelloWorld"
cd("HelloWorld") do
with_current_env() do
uuid1 = Pkg.generate("SubModule1")["SubModule1"]
uuid2 = Pkg.generate("SubModule2")["SubModule2"]
uuid1 = Pkg.generate("SubModule1")
uuid2 = Pkg.generate("SubModule2")
pkg"develop SubModule1"
mkdir("tests")
cd("tests")
Expand Down Expand Up @@ -280,9 +280,9 @@ end

# test relative dev paths (#490)
cd_tempdir() do tmp
uuid1 = Pkg.generate("HelloWorld")["HelloWorld"]
uuid1 = Pkg.generate("HelloWorld")
cd("HelloWorld")
uuid2 = Pkg.generate("SubModule")["SubModule"]
uuid2 = Pkg.generate("SubModule")
cd(mkdir("tests"))
pkg"activate ."
pkg"develop .." # HelloWorld
Expand Down Expand Up @@ -314,9 +314,9 @@ end
# test relative dev paths (#490) without existing Project.toml
temp_pkg_dir() do depot; cd_tempdir() do tmp
pkg"activate NonExistent"
uuid= nothing
uuid = nothing
withenv("USER" => "Test User") do
uuid = Pkg.generate("Foo")["Foo"]
uuid = Pkg.generate("Foo")
end
# this dev should not error even if NonExistent/Project.toml file is non-existent
@test !isdir("NonExistent")
Expand Down
8 changes: 6 additions & 2 deletions test/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -127,11 +127,15 @@ function git_init_package(tmp, path)
base = basename(path)
pkgpath = joinpath(tmp, base)
cp(path, pkgpath)
LibGit2.with(LibGit2.init(pkgpath)) do repo
git_init_package(pkgpath)
return pkgpath
end

function git_init_package(path)
LibGit2.with(LibGit2.init(path)) do repo
LibGit2.add!(repo, "*")
LibGit2.commit(repo, "initial commit"; author=TEST_SIG, committer=TEST_SIG)
end
return pkgpath
end

copy_test_package(tmpdir::String, name::String) =
Expand Down

0 comments on commit 443bb5f

Please sign in to comment.