Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bump Pkg #28443

Merged
merged 22 commits into from
Aug 5, 2018
Merged

Bump Pkg #28443

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
3e88964
[RFC] Make command spec more declarative (#509)
00vareladavid Jul 31, 2018
e9e320b
Make `Pkg.activate(path)` behave like `pkg> activate path`. (#543)
fredrikekre Jul 31, 2018
5b6fbb0
Refactor some REPL issues (#552)
00vareladavid Aug 1, 2018
85d2a7e
Fix `instantiate` error message (#560)
00vareladavid Aug 2, 2018
0ecaf2d
Replace depots()[1] with depots1() where depots1 throws (#563)
fredrikekre Aug 2, 2018
fcb1e4f
Refactor `activate` to avoid complexity in the main method (#559)
00vareladavid Aug 2, 2018
484deaf
rename Uncurated to General (#564)
Evizero Aug 2, 2018
f4d0411
Fix parser (lexer) (#553)
00vareladavid Aug 2, 2018
94eec9b
Change devdir kwarg to shared in REPL mode, add the kwarg to the API …
fredrikekre Aug 2, 2018
e5da183
use full path for local paths when determining package name (#571)
KristofferC Aug 3, 2018
4b43e63
stop using PkgError (#577)
KristofferC Aug 3, 2018
855ea64
ignore julia in test/REQUIRE (#578)
KristofferC Aug 3, 2018
917b1e7
Also collect manifest entries from target deps when testing / buildin…
KristofferC Aug 3, 2018
ff586ed
Propagate track-allocation option to test process. (#579)
tkoolen Aug 3, 2018
f647d70
add --shared option for activate (#558)
Evizero Aug 3, 2018
e804d11
allow using a path kword arg to PackageSpec (#580)
KristofferC Aug 3, 2018
eed9ea7
rename CommandError to PkgError (#475)
KristofferC Aug 3, 2018
d738134
only look for Project files in installed (#539)
KristofferC Aug 4, 2018
43a0285
remove ability to give a git revision to devved packages (#581)
KristofferC Aug 4, 2018
afbba1a
update precompilation for Pkg
KristofferC Aug 4, 2018
d5890e6
add licenses to files
KristofferC Aug 4, 2018
fee0392
increase isolation of test
KristofferC Aug 4, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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