Skip to content

Commit

Permalink
Merge pull request #28443 from JuliaLang/kc/bump_pkg
Browse files Browse the repository at this point in the history
Bump Pkg
  • Loading branch information
ararslan authored Aug 5, 2018
2 parents 696700f + fee0392 commit 5d43217
Show file tree
Hide file tree
Showing 23 changed files with 1,971 additions and 951 deletions.
19 changes: 6 additions & 13 deletions contrib/generate_precompile.jl
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,12 @@ cd("complet_path\t\t$CTRL_C
julia_cmd() = (julia = joinpath(Sys.BINDIR, Base.julia_exename()); `$julia`)
have_repl = haskey(Base.loaded_modules,
Base.PkgId(Base.UUID("3fa0cd96-eef1-5676-8a61-b3b8758bbffb"), "REPL"))
have_pkg = haskey(Base.loaded_modules,
Base.PkgId(Base.UUID("44cfe95a-1eb2-52ea-b672-e2afdf69b78f"), "Pkg"))

if have_pkg
precompile_script *= """
tmp = mktempdir()
cd(tmp)
touch("Project.toml")
] activate .
st
$CTRL_C
rm(tmp; recursive=true)
"""
Pkg = get(Base.loaded_modules,
Base.PkgId(Base.UUID("44cfe95a-1eb2-52ea-b672-e2afdf69b78f"), "Pkg"),
nothing)

if Pkg !== nothing
precompile_script *= Pkg.precompile_script
end

function generate_precompile_statements()
Expand Down
2 changes: 1 addition & 1 deletion stdlib/Pkg/bin/generate.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ write_toml(prefix, "Registry") do io
println(io, "repo = ", repr(repo))
println(io, "\ndescription = \"\"\"")
print(io, """
Official uncurated Julia package registry where people can
Official general Julia package registry where people can
register any package they want without too much debate about
naming and without enforced standards on documentation or
testing. We nevertheless encourage documentation, testing and
Expand Down
9 changes: 3 additions & 6 deletions stdlib/Pkg/docs/src/index.md
Original file line number Diff line number Diff line change
@@ -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 Expand Up @@ -350,13 +347,13 @@ If we try to `dev` a package at some branch that already exists at `~/.julia/dev
For example:

```
(v0.7) pkg> dev Example#master
(v0.7) pkg> dev Example
Updating git-repo `https://github.com/JuliaLang/Example.jl.git`
[ Info: Path `/Users/kristoffer/.julia/dev/Example` exists and looks like the correct package, using existing path instead of cloning
```

Note the info message saying that it is using the existing path. This means that you cannot use `dev` to e.g. change branches of
an already developed package.
Note the info message saying that it is using the existing path. As a general rule, the package manager will
never touch files that are tracking a path.

If `dev` is used on a local path, that path to that package is recorded and used when loading that package.
The path will be recorded relative to the project file, unless it is given as an absolute path.
Expand Down
89 changes: 73 additions & 16 deletions stdlib/Pkg/src/API.jl
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ include("generate.jl")

function check_package_name(x::String)
if !(occursin(Pkg.REPLMode.name_re, x))
cmderror("$x is not a valid packagename")
pkgerror("$x is not a valid packagename")
end
return PackageSpec(x)
end
Expand All @@ -28,22 +28,28 @@ add_or_develop(pkg::Union{String, PackageSpec}; kwargs...) = add_or_develop([pkg
add_or_develop(pkgs::Vector{String}; kwargs...) = add_or_develop([check_package_name(pkg) for pkg in pkgs]; kwargs...)
add_or_develop(pkgs::Vector{PackageSpec}; kwargs...) = add_or_develop(Context(), pkgs; kwargs...)

function add_or_develop(ctx::Context, pkgs::Vector{PackageSpec}; mode::Symbol, devdir::Union{String,Nothing}=nothing, kwargs...)
function add_or_develop(ctx::Context, pkgs::Vector{PackageSpec}; mode::Symbol, shared::Bool=true, kwargs...)
Context!(ctx; kwargs...)

# All developed packages should go through handle_repos_develop so just give them an empty repo
for pkg in pkgs
mode == :develop && pkg.repo == nothing && (pkg.repo = Types.GitRepo())
if mode == :develop
pkg.repo == nothing && (pkg.repo = Types.GitRepo())
if !isempty(pkg.repo.rev)
pkgerror("git revision cannot be given to `develop`")
end
end
end

# if julia is passed as a package the solver gets tricked;
# this catches the error early on
any(pkg->(pkg.name == "julia"), pkgs) &&
cmderror("Trying to $mode julia as a package")
pkgerror("Trying to $mode julia as a package")

ctx.preview && preview_info()
if mode == :develop
new_git = handle_repos_develop!(ctx, pkgs, something(devdir, Pkg.devdir()))
devdir = shared ? Pkg.devdir() : joinpath(dirname(ctx.env.project_file), "dev")
new_git = handle_repos_develop!(ctx, pkgs, devdir)
else
new_git = handle_repos_add!(ctx, pkgs; upgrade_or_add=true)
end
Expand All @@ -53,21 +59,26 @@ function add_or_develop(ctx::Context, pkgs::Vector{PackageSpec}; mode::Symbol, d
ensure_resolved(ctx.env, pkgs, registry=true)

any(pkg -> Types.collides_with_project(ctx.env, pkg), pkgs) &&
cmderror("Cannot $mode package with the same name or uuid as the project")
pkgerror("Cannot $mode package with the same name or uuid as the project")

Operations.add_or_develop(ctx, pkgs; new_git=new_git)
ctx.preview && preview_info()
return
end

add(args...; kwargs...) = add_or_develop(args...; mode = :add, kwargs...)
develop(args...; kwargs...) = add_or_develop(args...; mode = :develop, kwargs...)
develop(args...; shared=true, kwargs...) = add_or_develop(args...; mode = :develop, shared = shared, kwargs...)

rm(pkg::Union{String, PackageSpec}; kwargs...) = rm([pkg]; kwargs...)
rm(pkgs::Vector{String}; kwargs...) = rm([PackageSpec(pkg) for pkg in pkgs]; kwargs...)
rm(pkgs::Vector{PackageSpec}; kwargs...) = rm(Context(), pkgs; kwargs...)

function rm(ctx::Context, pkgs::Vector{PackageSpec}; kwargs...)
function rm(ctx::Context, pkgs::Vector{PackageSpec}; mode=PKGMODE_PROJECT, kwargs...)
for pkg in pkgs
#TODO only overwrite pkg.mode is default value ?
pkg.mode = mode
end

Context!(ctx; kwargs...)
ctx.preview && preview_info()
project_deps_resolve!(ctx.env, pkgs)
Expand Down Expand Up @@ -101,7 +112,7 @@ function update_registry(ctx)
try
GitTools.fetch(repo; refspecs=["+refs/heads/$branch:refs/remotes/origin/$branch"])
catch e
e isa CommandError || rethrow(e)
e isa PkgError || rethrow(e)
push!(errors, (reg, "failed to fetch from repo"))
return
end
Expand Down Expand Up @@ -144,6 +155,12 @@ up(pkgs::Vector{PackageSpec}; kwargs...) = up(Context(), pkgs; kwargs...)

function up(ctx::Context, pkgs::Vector{PackageSpec};
level::UpgradeLevel=UPLEVEL_MAJOR, mode::PackageMode=PKGMODE_PROJECT, do_update_registry=true, kwargs...)
for pkg in pkgs
# TODO only override if they are not already set
pkg.mode = mode
pkg.version = level
end

Context!(ctx; kwargs...)
ctx.preview && preview_info()
do_update_registry && update_registry(ctx)
Expand Down Expand Up @@ -207,7 +224,7 @@ function free(ctx::Context, pkgs::Vector{PackageSpec}; kwargs...)
for pkg in pkgs
info = manifest_info(ctx.env, pkg.uuid)
if !get(info, "pinned", false) && !(pkg.uuid in uuids_in_registry)
cmderror("cannot free an unpinned package that does not exist in a registry")
pkgerror("cannot free an unpinned package that does not exist in a registry")
end
end
Operations.free(ctx, pkgs)
Expand All @@ -226,7 +243,7 @@ function test(ctx::Context, pkgs::Vector{PackageSpec}; coverage=false, kwargs...
ctx.preview && preview_info()
if isempty(pkgs)
# TODO: Allow this?
ctx.env.pkg == nothing && cmderror("trying to test unnamed project")
ctx.env.pkg == nothing && pkgerror("trying to test unnamed project")
push!(pkgs, ctx.env.pkg)
end
project_resolve!(ctx.env, pkgs)
Expand All @@ -241,7 +258,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 Expand Up @@ -456,7 +474,7 @@ function precompile(ctx::Context)
sourcepath = Base.locate_package(pkg)
if sourcepath == nothing
# XXX: this isn't supposed to be fatal
cmderror("couldn't find path to $(pkg.name) when trying to precompilie project")
pkgerror("couldn't find path to $(pkg.name) when trying to precompilie project")
end
stale = true
for path_to_try in paths::Vector{String}
Expand Down Expand Up @@ -492,7 +510,7 @@ function instantiate(ctx::Context; manifest::Union{Bool, Nothing}=nothing, kwarg
return
end
if !isfile(ctx.env.manifest_file) && manifest == true
cmderror("manifest at $(ctx.env.manifest) does not exist")
pkgerror("manifest at $(ctx.env.manifest_file) does not exist")
end
update_registry(ctx)
urls = Dict{}
Expand Down Expand Up @@ -534,8 +552,47 @@ function status(ctx::Context, mode=PKGMODE_PROJECT)
return
end

function activate(path::Union{String,Nothing}=nothing)
Base.ACTIVE_PROJECT[] = Base.load_path_expand(path)
activate() = (Base.ACTIVE_PROJECT[] = nothing)
function activate(path::String; shared::Bool=false)
if !shared
devpath = nothing
env = Base.active_project() === nothing ? nothing : EnvCache()
if env !== nothing && haskey(env.project["deps"], path)
uuid = UUID(env.project["deps"][path])
info = manifest_info(env, uuid)
devpath = haskey(info, "path") ? joinpath(dirname(env.project_file), info["path"]) : nothing
end
# `pkg> activate path`/`Pkg.activate(path)` does the following
# 1. if path exists, activate that
# 2. if path exists in deps, and the dep is deved, activate that path (`devpath` above)
# 3. activate the non-existing directory (e.g. as in `pkg> activate .` for initing a new env)
if Types.isdir_windows_workaround(path)
fullpath = abspath(path)
elseif devpath !== nothing
fullpath = abspath(devpath)
else
fullpath = abspath(path)
isdir(fullpath) || @info("new environment will be placed at $fullpath")
end
else
# initialize `fullpath` in case of empty `Pkg.depots()`
fullpath = ""
# loop over all depots to check if the shared environment already exists
for depot in Pkg.depots()
fullpath = joinpath(Pkg.envdir(depot), path)
isdir(fullpath) && break
end
# this disallows names such as "Foo/bar", ".", "..", etc
if basename(abspath(fullpath)) != path
pkgerror("not a valid name for a shared environment: $(path)")
end
# unless the shared environment already exists, place it in the first depots
if !isdir(fullpath)
fullpath = joinpath(Pkg.envdir(Pkg.depots1()), path)
@info("new shared environment \"$path\" will be placed at $fullpath")
end
end
Base.ACTIVE_PROJECT[] = Base.load_path_expand(fullpath)
end

"""
Expand Down
8 changes: 4 additions & 4 deletions stdlib/Pkg/src/GitTools.jl
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,9 @@ function clone(url, source_path; header=nothing, kwargs...)
err isa LibGit2.GitError || rethrow(err)
if (err.class == LibGit2.Error.Net && err.code == LibGit2.Error.EINVALIDSPEC) ||
(err.class == LibGit2.Error.Repository && err.code == LibGit2.Error.ENOTFOUND)
Pkg.Types.cmderror("Git repository not found at '$(url)'")
Pkg.Types.pkgerror("Git repository not found at '$(url)'")
else
Pkg.Types.cmderror("failed to clone from $(url), error: $err")
Pkg.Types.pkgerror("failed to clone from $(url), error: $err")
end
finally
print(stdout, "\033[2K") # clear line
Expand Down Expand Up @@ -128,9 +128,9 @@ function fetch(repo::LibGit2.GitRepo, remoteurl=nothing; header=nothing, kwargs.
catch err
err isa LibGit2.GitError || rethrow(err)
if (err.class == LibGit2.Error.Repository && err.code == LibGit2.Error.ERROR)
Pkg.Types.cmderror("Git repository not found at '$(remoteurl)'")
Pkg.Types.pkgerror("Git repository not found at '$(remoteurl)'")
else
Pkg.Types.cmderror("failed to fetch from $(remoteurl), error: $err")
Pkg.Types.pkgerror("failed to fetch from $(remoteurl), error: $err")
end
finally
print(stdout, "\033[2K") # clear line
Expand Down
Loading

1 comment on commit 5d43217

@nanosoldier
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Executing the daily benchmark build, I will reply here when finished:

@nanosoldier runbenchmarks(ALL, isdaily = true)

Please sign in to comment.