Skip to content

Commit

Permalink
Info interface
Browse files Browse the repository at this point in the history
  • Loading branch information
00vareladavid committed Feb 25, 2019
1 parent d40f370 commit 0625c7b
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 24 deletions.
17 changes: 13 additions & 4 deletions src/API.jl
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,22 @@ 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
@show ctx.env.pkg
ctx.env.pkg !== nothing || pkgerror("Active environment is not a project")
pkg = deepcopy(ctx.env.pkg)
pkg.path = dirname(ctx.env.project_file)
push!(pkgs, pkg)
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
Expand Down
25 changes: 8 additions & 17 deletions src/Operations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -64,22 +64,14 @@ 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))
end
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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -1269,19 +1260,19 @@ 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)
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
5 changes: 2 additions & 3 deletions src/Types.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 0625c7b

Please sign in to comment.