From 33fa85f2aa11b6b2afdab72da22c08517f196e24 Mon Sep 17 00:00:00 2001 From: David Varela <00.varela.david@gmail.com> Date: Sun, 24 Feb 2019 17:31:21 -0800 Subject: [PATCH] Info interface --- src/API.jl | 19 +++++++++++++++---- src/Operations.jl | 26 +++++++++----------------- src/Types.jl | 5 ++--- 3 files changed, 26 insertions(+), 24 deletions(-) diff --git a/src/API.jl b/src/API.jl index 858319b11f..dd862e24bc 100644 --- a/src/API.jl +++ b/src/API.jl @@ -19,13 +19,24 @@ preview_info() = printstyled("───── Preview mode ─────\n"; c include("generate.jl") info(; kwargs...) = info(Context(), PackageSpec[]; kwargs...) +info(uuid::UUID; kwargs...) = info([uuid]; kwargs...) info(uuids::Vector{UUID}; kwargs...) = info(Context(), [PackageSpec(;uuid=uuid) for uuid in uuids]; kwargs...) -function info(ctx::Context, pkgs::Vector{PackageSpec}; table=false, all=false, kwargs...) - isempty(pkgs) && Operations.load_direct_deps!(ctx, pkgs) - all && Operations.load_all_deps!(ctx, pkgs) +function info(ctx::Context, pkgs::Vector{PackageSpec}; active=false, direct=false, all=false, kwargs...) + if active + if ctx.env.pkg === nothing + @warn "Active environment is not a project" + else + pkg = deepcopy(ctx.env.pkg) + pkg.path = dirname(ctx.env.project_file) + push!(pkgs, pkg) + end + end + direct && Operations.load_direct_deps!(ctx, pkgs) + all && Operations.load_all_deps!(ctx, pkgs) + data = Dict{UUID, Dict{String, Any}}() for pkg in pkgs - Operations.load_info_data!(pkg, data; kwargs...) + Operations.load_info_data!(ctx, pkg, data; kwargs...) end return data end diff --git a/src/Operations.jl b/src/Operations.jl index fd053f72c1..75afa52eea 100644 --- a/src/Operations.jl +++ b/src/Operations.jl @@ -64,6 +64,7 @@ end function load_all_deps!(ctx::Context, pkgs::Vector{PackageSpec}; version::Bool=true) for (uuid, entry) in ctx.env.manifest + pkgs[uuid] === nothing || continue # dont duplicate packages push!(pkgs, PackageSpec(name=entry.name, uuid=uuid, path=entry.path, version = version ? something(entry.version, VersionSpec()) : VersionSpec(), repo=entry.repo, tree_hash=entry.tree_hash)) @@ -71,15 +72,6 @@ function load_all_deps!(ctx::Context, pkgs::Vector{PackageSpec}; version::Bool=t load_direct_deps!(ctx, pkgs; version=version) end -function load_all_deps!(ctx::Context, pkgs::Vector{PackageSpec}) - for (uuid, entry) in ctx.env.manifest - pkgs[uuid] === nothing || continue # dont duplicate packages - push!(pkgs, PackageSpec(name=entry.name, uuid=uuid, path=entry.path, - version = something(entry.version, VersionSpec()), - repo=entry.repo, tree_hash=entry.tree_hash)) - end -end - function update_manifest!(ctx::Context, pkgs::Vector{PackageSpec}) manifest = ctx.env.manifest empty!(manifest) @@ -961,7 +953,6 @@ function develop(ctx::Context, pkgs::Vector{PackageSpec}, new_git::Vector{UUID}; end keep_manifest ? load_all_deps!(ctx, pkgs) : load_direct_deps!(ctx, pkgs) check_registered(ctx, pkgs) - load_direct_deps!(ctx, pkgs) # resolve & apply package versions resolve_versions!(ctx, pkgs) @@ -1269,19 +1260,20 @@ function test(ctx::Context, pkgs::Vector{PackageSpec}; coverage=false, test_fn=n end end -function load_info_data!(pkg::PackageSpec, data::Dict; - name=true, version=true, pinned=false, rev=false, dev=false, - source=false) +function load_info_data!(ctx::Context, pkg::PackageSpec, data::Dict; + name=true, version=false, pinned=false, url=false, rev=false, + dev=false, source=false) x = get!(data, pkg.uuid, Dict{String,Any}()) if version ver = pkg.version x["version"] = ver == VersionSpec() ? nothing : ver end pinned && (x["pinned"] = pkg.pinned) - name && (x["name"] = pkg.name) - rev && (x["rev"] = pkg.repo.rev) - dev && (x["DEV"] = pkg.path !== nothing) - source && (x["source path"] = Base.contractuser(source_path(pkg))) + name && (x["name"] = pkg.name) + url && (x["url"] = pkg.repo.url) + rev && (x["rev"] = pkg.repo.rev) + dev && (x["dev"] = pkg.path !== nothing) + source && (x["source"] = Base.contractuser(project_rel_path(ctx, source_path(pkg)))) end end # module diff --git a/src/Types.jl b/src/Types.jl index c83003b242..1b553bb063 100644 --- a/src/Types.jl +++ b/src/Types.jl @@ -674,12 +674,11 @@ function instantiate_pkg_repo!(pkg::PackageSpec, cached_repo::Union{Nothing,Stri clone = clone_path!(pkg.repo.url) pkg.tree_hash = tree_hash(clone, pkg.repo.rev) version_path = Pkg.Operations.find_installed(pkg.name, pkg.uuid, pkg.tree_hash) - isdir(version_path) && return false - - mkpath(version_path) if cached_repo === nothing cached_repo = repo_checkout(clone, string(pkg.tree_hash)) end + isdir(version_path) && return false + mkpath(version_path) mv(cached_repo, version_path; force=true) return true end