Skip to content

Commit

Permalink
Merge pull request JuliaLang#150 from JuliaLang/kc/stdlib_merge
Browse files Browse the repository at this point in the history
upstream fixes from stdlib merge
  • Loading branch information
KristofferC authored Feb 23, 2018
2 parents 1cf3d4b + f8058e4 commit b8c5d0a
Show file tree
Hide file tree
Showing 11 changed files with 331 additions and 24 deletions.
2 changes: 1 addition & 1 deletion ext/TOML/src/print.jl
Original file line number Diff line number Diff line change
Expand Up @@ -94,4 +94,4 @@ function _print(io::IO, a::AbstractDict, ks=String[]; sorted=false)
end

print(io::IO, a::AbstractDict; sorted=false) = _print(io, a, sorted=sorted)
print(a::AbstractDict; sorted=false) = print(STDOUT, a, sorted=sorted)
print(a::AbstractDict; sorted=false) = print(stdout, a, sorted=sorted)
12 changes: 11 additions & 1 deletion src/API.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import Dates
import LibGit2

import Pkg3
import Pkg3: depots, logdir, devdir
import Pkg3: depots, logdir, devdir, print_first_command_header
using Pkg3.Types
using Pkg3.TOML

Expand All @@ -19,6 +19,7 @@ add(pkgs::Vector{String}; kwargs...) = add([PackageSpec(pkg) for pkg in pkg
add(pkgs::Vector{PackageSpec}; kwargs...) = add(Context(), pkgs; kwargs...)

function add(ctx::Context, pkgs::Vector{PackageSpec}; kwargs...)
print_first_command_header()
Context!(ctx; kwargs...)
ctx.preview && preview_info()
project_resolve!(ctx.env, pkgs)
Expand All @@ -33,6 +34,7 @@ rm(pkgs::Vector{String}; kwargs...) = rm([PackageSpec(pkg) for pkg in pkgs]
rm(pkgs::Vector{PackageSpec}; kwargs...) = rm(Context(), pkgs; kwargs...)

function rm(ctx::Context, pkgs::Vector{PackageSpec}; kwargs...)
print_first_command_header()
Context!(ctx; kwargs...)
ctx.preview && preview_info()
project_resolve!(ctx.env, pkgs)
Expand All @@ -48,6 +50,7 @@ up(pkgs::Vector{PackageSpec}; kwargs...) = up(Context(), pkgs; kwargs...)

function up(ctx::Context, pkgs::Vector{PackageSpec};
level::UpgradeLevel=UPLEVEL_MAJOR, mode::PackageMode=PKGMODE_PROJECT, kwargs...)
print_first_command_header()
Context!(ctx; kwargs...)
ctx.preview && preview_info()

Expand Down Expand Up @@ -126,6 +129,7 @@ pin(pkgs::Vector{String}; kwargs...) = pin([PackageSpec(pkg) for pkg
pin(pkgs::Vector{PackageSpec}; kwargs...) = pin(Context(), pkgs; kwargs...)

function pin(ctx::Context, pkgs::Vector{PackageSpec}; kwargs...)
print_first_command_header()
Context!(ctx; kwargs...)
ctx.preview && preview_info()
project_resolve!(ctx.env, pkgs)
Expand All @@ -139,6 +143,7 @@ free(pkgs::Vector{String}; kwargs...) = free([PackageSpec(pkg) for pk
free(pkgs::Vector{PackageSpec}; kwargs...) = free(Context(), pkgs; kwargs...)

function free(ctx::Context, pkgs::Vector{PackageSpec}; kwargs...)
print_first_command_header()
Context!(ctx; kwargs...)
ctx.preview && preview_info()
project_resolve!(ctx.env, pkgs)
Expand All @@ -155,6 +160,7 @@ checkout(pkgs::Vector{PackageSpec}; kwargs...) = checkout([(pkg, nothing)
checkout(pkgs_branches::Vector; kwargs...) = checkout(Context(), pkgs_branches; kwargs...)

function checkout(ctx::Context, pkgs_branches::Vector; path = devdir(), kwargs...)
print_first_command_header()
Context!(ctx; kwargs...)
ctx.preview && preview_info()
pkgs = [p[1] for p in pkgs_branches]
Expand All @@ -171,6 +177,7 @@ test(pkgs::Vector{String}; kwargs...) = test([PackageSpec(pkg) for p
test(pkgs::Vector{PackageSpec}; kwargs...) = test(Context(), pkgs; kwargs...)

function test(ctx::Context, pkgs::Vector{PackageSpec}; coverage=false, kwargs...)
print_first_command_header()
Context!(ctx; kwargs...)
ctx.preview && preview_info()
project_resolve!(ctx.env, pkgs)
Expand All @@ -192,6 +199,7 @@ end


function gc(ctx::Context=Context(); period = Dates.Week(6), kwargs...)
print_first_command_header()
function recursive_dir_size(path)
sz = 0
for (root, dirs, files) in walkdir(path)
Expand Down Expand Up @@ -310,6 +318,7 @@ build(pkg::PackageSpec) = build([pkg])
build(pkgs::Vector{PackageSpec}) = build(Context(), pkgs)

function build(ctx::Context, pkgs::Vector{PackageSpec}; kwargs...)
print_first_command_header()
Context!(ctx; kwargs...)
if isempty(pkgs)
for (name, infos) in ctx.env.manifest, info in infos
Expand All @@ -329,6 +338,7 @@ function build(ctx::Context, pkgs::Vector{PackageSpec}; kwargs...)
end

function init(path::String)
print_first_command_header()
ctx = Context(env = EnvCache(joinpath(path, "Project.toml")))
Pkg3.Operations.init(ctx)
end
Expand Down
4 changes: 2 additions & 2 deletions src/Display.jl
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ function git_file_stream(repo::LibGit2.GitRepo, spec::String; fakeit::Bool=false
blob = try LibGit2.GitBlob(repo, spec)
catch err
err isa LibGit2.GitError && err.code == LibGit2.Error.ENOTFOUND || rethrow(err)
fakeit && return DevNull
fakeit && return devnull
end
return IOBuffer(LibGit2.rawcontent(blob))
end
Expand Down Expand Up @@ -154,7 +154,7 @@ function print_diff(io::IO, diff::Vector{DiffEntry})
printstyled(color = colors[verb], "$v $(x.name) $vstr\n")
end
end
print_diff(diff::Vector{DiffEntry}) = print_diff(STDOUT, diff)
print_diff(diff::Vector{DiffEntry}) = print_diff(stdout, diff)

function manifest_by_uuid(manifest::Dict)
entries = Dict{UUID,Dict}()
Expand Down
10 changes: 5 additions & 5 deletions src/GraphType.jl
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ mutable struct GraphData
versions::Dict{UUID,Set{VersionNumber}},
deps::Dict{UUID,Dict{VersionRange,Dict{String,UUID}}},
compat::Dict{UUID,Dict{VersionRange,Dict{String,VersionSpec}}},
uuid_to_name::Dict{UUID,String};
uuid_to_name::Dict{UUID,String},
verbose::Bool = false
)
# generate pkgs
Expand Down Expand Up @@ -246,15 +246,15 @@ mutable struct Graph
compat::Dict{UUID,Dict{VersionRange,Dict{String,VersionSpec}}},
uuid_to_name::Dict{UUID,String},
reqs::Requires = Requires(),
fixed::Dict{UUID,Fixed} = Dict{UUID,Fixed}(uuid_julia=>Fixed(VERSION));
fixed::Dict{UUID,Fixed} = Dict{UUID,Fixed}(uuid_julia=>Fixed(VERSION)),
verbose::Bool = false
)

extra_uuids = union(keys(reqs), keys(fixed), map(fx->keys(fx.requires), values(fixed))...)
extra_uuids keys(versions) || error("unknown UUID found in reqs/fixed") # TODO?

# Type assert below due to https://github.com/JuliaLang/julia/issues/25918
data = GraphData(versions, deps, compat, uuid_to_name, verbose = verbose)::GraphData
data = GraphData(versions, deps, compat, uuid_to_name, verbose)::GraphData
pkgs, np, spp, pdict, pvers, vdict, rlog = data.pkgs, data.np, data.spp, data.pdict, data.pvers, data.vdict, data.rlog

local extended_deps
Expand Down Expand Up @@ -825,9 +825,9 @@ get_resolve_log(graph::Graph) = deepcopy(graph.data.rlog)

const _logindent = " "

showlog(graph::Graph, args...; kw...) = showlog(STDOUT, graph, args...; kw...)
showlog(graph::Graph, args...; kw...) = showlog(stdout, graph, args...; kw...)
showlog(io::IO, graph::Graph, args...; kw...) = showlog(io, graph.data.rlog, args...; kw...)
showlog(rlog::ResolveLog, args...; kw...) = showlog(STDOUT, rlog, args...; kw...)
showlog(rlog::ResolveLog, args...; kw...) = showlog(stdout, rlog, args...; kw...)

"""
Show the full resolution log. The `view` keyword controls how the events are displayed/grouped:
Expand Down
12 changes: 3 additions & 9 deletions src/Operations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ function deps_graph(ctx::Context, uuid_to_name::Dict{UUID,String}, reqs::Require
uuid_to_name[UUID(info["uuid"])] = info["name"]
end

return Graph(all_versions, all_deps, all_compat, uuid_to_name, reqs, fixed; verbose=ctx.graph_verbose)
return Graph(all_versions, all_deps, all_compat, uuid_to_name, reqs, fixed, #=verbose=# ctx.graph_verbose)
end

# Resolve a set of versions given package version specs
Expand Down Expand Up @@ -318,7 +318,7 @@ function install_archive(
url_success = true
try
cmd = BinaryProvider.gen_download_cmd(archive_url, path);
run(cmd, (DevNull, DevNull, DevNull))
run(cmd, (devnull, devnull, devnull))
catch e
e isa InterruptException && rethrow(e)
url_success = false
Expand All @@ -327,7 +327,7 @@ function install_archive(
dir = joinpath(tempdir(), randstring(12))
mkpath(dir)
cmd = BinaryProvider.gen_unpack_cmd(path, dir);
run(cmd, (DevNull, DevNull, DevNull))
run(cmd, (devnull, devnull, devnull))
dirs = readdir(dir)
# 7z on Win might create this spurious file
filter!(x -> x != "pax_global_header", dirs)
Expand Down Expand Up @@ -621,8 +621,6 @@ function build_versions(ctx::Context, uuids::Vector{UUID})
append!(Base.LOAD_PATH, $(repr(Base.load_path())))
empty!(Base.DEPOT_PATH)
append!(Base.DEPOT_PATH, $(repr(map(abspath, DEPOT_PATH))))
empty!(Base.LOAD_CACHE_PATH)
append!(Base.LOAD_CACHE_PATH, $(repr(map(abspath, Base.LOAD_CACHE_PATH))))
empty!(Base.DL_LOAD_PATH)
append!(Base.DL_LOAD_PATH, $(repr(map(abspath, Base.DL_LOAD_PATH))))
m = Base.require(Base.PkgId(Base.UUID($(repr(string(uuid)))), $(repr(name))))
Expand Down Expand Up @@ -871,15 +869,11 @@ function test(ctx::Context, pkgs::Vector{PackageSpec}; coverage=false)
@info("In preview mode, skipping tests for $(pkg.name)")
continue
end
# TODO, cd to test folder (need to be careful with getting the same EnvCache
# as for this session in that case
code = """
empty!(Base.LOAD_PATH)
append!(Base.LOAD_PATH, $(repr(Base.load_path())))
empty!(Base.DEPOT_PATH)
append!(Base.DEPOT_PATH, $(repr(map(abspath, DEPOT_PATH))))
empty!(Base.LOAD_CACHE_PATH)
append!(Base.LOAD_CACHE_PATH, $(repr(map(abspath, Base.LOAD_CACHE_PATH))))
empty!(Base.DL_LOAD_PATH)
append!(Base.DL_LOAD_PATH, $(repr(map(abspath, Base.DL_LOAD_PATH))))
m = Base.require(Base.PkgId(Base.UUID($(repr(string(pkg.uuid)))), $(repr(pkg.name))))
Expand Down
30 changes: 30 additions & 0 deletions src/Pkg3.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,24 @@ depots() = Base.DEPOT_PATH
logdir() = joinpath(depots()[1], "logs")
devdir() = get(ENV, "JULIA_PKG_DEVDIR", joinpath(homedir(), ".julia", "dev"))

have_warned_session = false
function print_first_command_header()
global have_warned_session
have_warned_session && return
isinteractive() || return
@info """
Pkg3 is still under development, please file issues at `https://github.com/JuliaLang/Pkg3.jl`.
"""
if !PKG3_IS_PRECOMPILED && !haskey(ENV, "JULIA_PKG3_DISABLE_PRECOMPILE_WARNING")
@info """
Pkg3 is running without precompile statements, first action will be slow.
Rebuild julia with the environment variable `JULIA_PKG3_PRECOMPILE` set to enable precompilation of PKG3.
This message can be disabled by setting the env variable `JULIA_PKG3_DISABLE_PRECOMPILE_WARNING`.
"""
end
have_warned_session = true
end

# load snapshotted dependencies
include("../ext/TOML/src/TOML.jl")

Expand Down Expand Up @@ -38,4 +56,16 @@ function __init__()
end
end

using Pkg3.Types
using UUIDs
import LibGit2
# This crashes low memory systems and some of Julia's CI
# so keep it disabled by default for now.
if haskey(ENV, "JULIA_PKG3_PRECOMPILE")
const PKG3_IS_PRECOMPILED = true
include("precompile.jl")
else
const PKG3_IS_PRECOMPILED = false
end

end # module
3 changes: 2 additions & 1 deletion src/REPLMode.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import REPL
import REPL: LineEdit, REPLCompletions

import Pkg3
import Pkg3: devdir
import Pkg3: devdir, print_first_command_header
using Pkg3.Types
using Pkg3.Display
using Pkg3.Operations
Expand Down Expand Up @@ -151,6 +151,7 @@ const lex_re = r"^[\?\./\+\-](?!\-) | [^@\s]+\s*=\s*[^@\s]+ | @\s*[^@\s]* | [^@\
const Token = Union{Command, Option, VersionRange, String}

function tokenize(cmd::String)::Vector{Token}
print_first_command_header()
tokens = Token[]
words = map(m->m.match, eachmatch(lex_re, cmd))
help_mode = false
Expand Down
2 changes: 1 addition & 1 deletion src/Resolve.jl
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ end
Scan the graph for (explicit or implicit) contradictions. Returns a list of problematic
(package,version) combinations.
"""
function sanity_check(graph::Graph, sources::Set{UUID} = Set{UUID}(); verbose = true)
function sanity_check(graph::Graph, sources::Set{UUID} = Set{UUID}(), verbose::Bool = true)
req_inds = graph.req_inds
fix_inds = graph.fix_inds

Expand Down
4 changes: 2 additions & 2 deletions src/Types.jl
Original file line number Diff line number Diff line change
Expand Up @@ -516,7 +516,7 @@ function read_project(io::IO)
return project
end
function read_project(file::String)
isfile(file) ? open(read_project, file) : read_project(DevNull)
isfile(file) ? open(read_project, file) : read_project(devnull)
end

function read_manifest(io::IO)
Expand All @@ -537,7 +537,7 @@ function read_manifest(io::IO)
return manifest
end
function read_manifest(file::String)
try isfile(file) ? open(read_manifest, file) : read_manifest(DevNull)
try isfile(file) ? open(read_manifest, file) : read_manifest(devnull)
catch err
err isa ErrorException && startswith(err.msg, "ambiguious dependency") || rethrow(err)
err.msg *= "In manifest file: $file"
Expand Down
Loading

0 comments on commit b8c5d0a

Please sign in to comment.