Skip to content

Commit

Permalink
Merge #1055
Browse files Browse the repository at this point in the history
1055: Backports for Pkg 1.1.3 r=KristofferC a=fredrikekre



Co-authored-by: David Varela <00.varela.david@gmail.com>
Co-authored-by: Florian Heiderich <florian@heiderich.org>
Co-authored-by: Fredrik Ekre <ekrefredrik@gmail.com>
Co-authored-by: Curtis Vogt <curtis.vogt@gmail.com>
Co-authored-by: Nicholas Bauer <nicholasbauer@outlook.com>
Co-authored-by: Tamas K. Papp <tkpapp@gmail.com>
Co-authored-by: Kristoffer Carlsson <kcarlsson89@gmail.com>
  • Loading branch information
8 people committed Feb 27, 2019
2 parents 853b3f1 + c784ab4 commit e0407bf
Show file tree
Hide file tree
Showing 18 changed files with 261 additions and 56 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@
docs/build
/Manifest.toml
/docs/Manifest.toml
/docs/src/repl.md
.DS_Store
/test/registries/*
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ desc = "The next-generation Julia package manager."
keywords = ["package", "management"]
license = "MIT"
name = "Pkg"
version = "1.1.2"
version = "1.1.3"
uuid = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"

[deps]
Expand Down
49 changes: 49 additions & 0 deletions docs/generate.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# This file is a part of Julia. License is MIT: https://julialang.org/license

## generate repl-docs ##

function generate(io, command)
println(io, """
```@raw html
<section class="docstring">
<div class="docstring-header">
<a class="docstring-binding" id="repl-$(command)" href="#repl-$(command)">
<code>$(replace(command, "-" => " "))</code>
</a>
<span class="docstring-category">REPL command</span>
.
</div>
```
```@eval
using Pkg
Pkg.REPLMode.CommandSpec("$(command)").help
```
```@raw html
</section>
```
""")
end
function generate()
io = IOBuffer()
println(io, """
# [**9.** REPL Mode Reference](@id REPL-Mode-Reference)
This section describes available commands in the Pkg REPL.
The REPL mode is mostly meant for interactive use,
and for non-interactive use it is recommended to use the
"API mode", see [API Reference](@ref API-Reference).
""")
# list commands
println(io, "## `package` commands")
foreach(command -> generate(io, command), ["add", "build", "develop", "free", "generate", "pin", "remove", "test", "update"])
println(io, "## `registry` commands")
foreach(command -> generate(io, command), ["registry-add", "registry-remove", "registry-status", "registry-update"])
println(io, "## Other commands")
foreach(command -> generate(io, command), ["activate", "gc", "help", "instantiate", "precompile", "resolve", "status"])
# write to file
write(joinpath(@__DIR__, "src", "repl.md"), seekstart(io))
return
end

generate()
5 changes: 4 additions & 1 deletion docs/make.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
using Documenter
using Pkg

include("generate.jl")

makedocs(
modules = [Pkg],
sitename = "Pkg.jl",
Expand All @@ -16,12 +18,13 @@ makedocs(
"registries.md",
# "faq.md",
"glossary.md",
"repl.md",
"api.md"
],
versions = ["v#.#", "dev" => "dev"],
assets = ["assets/custom.css"],
)

deploydocs(
repo = "github.com/JuliaLang/Pkg.jl",
versions = ["v#.#", "dev" => "dev"],
)
2 changes: 1 addition & 1 deletion docs/src/creating-packages.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# **5.** Creating Packages

A package is a project with a `name`, `uuid` and `version` entry in the `Project.toml` file `src/PackageName.jl` file that defines the module `PackageName`.
A package is a project with a `name`, `uuid` and `version` entry in the `Project.toml` file, and a `src/PackageName.jl` file that defines the module `PackageName`.
This file is executed when the package is loaded.

### Generating files for a package
Expand Down
2 changes: 1 addition & 1 deletion docs/src/glossary.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# **9.** Glossary
# **8.** Glossary

**Project:** a source tree with a standard layout, including a `src` directory
for the main body of Julia code, a `test` directory for testing the project,
Expand Down
2 changes: 1 addition & 1 deletion ext/TOML/src/print.jl
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ end
printvalue(io::IO, value::AbstractDict; sorted=false) =
_print(io, value, sorted=sorted)
printvalue(io::IO, value::DateTime; sorted=false) =
Base.print(io, Dates.format(value, "YYYY-mm-ddTHH:MM:SS.sssZ"))
Base.print(io, Dates.format(value, dateformat"YYYY-mm-dd\THH:MM:SS.sss\Z"))
printvalue(io::IO, value::Bool; sorted=false) =
Base.print(io, value ? "true" : "false")
printvalue(io::IO, value; sorted=false) =
Expand Down
13 changes: 9 additions & 4 deletions src/API.jl
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,21 @@ preview_info() = printstyled("───── Preview mode ─────\n"; c

include("generate.jl")

function check_package_name(x::AbstractString)
function check_package_name(x::AbstractString, mode=nothing)
if !(occursin(Pkg.REPLMode.name_re, x))
pkgerror("$x is not a valid packagename")
message = "$x is not a valid packagename."
if mode !== nothing && any(occursin.(['\\','/'], x)) # maybe a url or a path
message *= "\nThe argument appears to be a URL or path, perhaps you meant " *
"`Pkg.$mode(PackageSpec(url=\"...\"))` or `Pkg.$mode(PackageSpec(path=\"...\"))`."
end
pkgerror(message)
end
return PackageSpec(x)
end

add_or_develop(pkg::Union{AbstractString, PackageSpec}; kwargs...) = add_or_develop([pkg]; kwargs...)
add_or_develop(pkgs::Vector{<:AbstractString}; kwargs...) =
add_or_develop([check_package_name(pkg) for pkg in pkgs]; kwargs...)
add_or_develop(pkgs::Vector{<:AbstractString}; mode::Symbol, kwargs...) =
add_or_develop([check_package_name(pkg, mode) for pkg in pkgs]; mode = mode, 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, shared::Bool=true, kwargs...)
Expand Down
13 changes: 7 additions & 6 deletions src/Operations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ function find_installed(name::String, uuid::UUID, sha1::SHA1)
end

function load_versions(path::String; include_yanked = false)
toml = parse_toml(path, "Versions.toml")
toml = parse_toml(path, "Versions.toml"; fakeit=true)
d = Dict{VersionNumber, SHA1}(
VersionNumber(ver) => SHA1(info["git-tree-sha1"]) for (ver, info) in toml
if !get(info, "yanked", false) || include_yanked)
Expand Down Expand Up @@ -380,7 +380,7 @@ function resolve_versions!(
for (uuid, ver) in vers
uuid in uuids && continue
name = registered_name(ctx.env, uuid)
push!(pkgs, PackageSpec(name, uuid, ver))
push!(pkgs, PackageSpec(;name=name, uuid=uuid, version=ver))
end
return vers
end
Expand Down Expand Up @@ -835,10 +835,10 @@ function with_dependencies_loadable_at_toplevel(f, mainctx::Context, pkg::Packag
# Only put `pkg` and its deps (recursively) in the temp project
empty!(localctx.env.project.deps)
localctx.env.project.deps[pkg.name] = pkg.uuid
seen_uuids = Set{UUID}()
# Only put `pkg` and its deps (recursively) in the temp project
collect_deps!(seen_uuids, pkg)
end
# Only put `pkg` and its deps (recursively) in the temp project
seen_uuids = Set{UUID}()
collect_deps!(seen_uuids, pkg)

pkgs = PackageSpec[]
if target !== nothing
Expand Down Expand Up @@ -1139,7 +1139,8 @@ function rm(ctx::Context, pkgs::Vector{PackageSpec})
@info "No changes"
return
end
deps_names = collect(keys(ctx.env.project.deps))
deps_names = append!(collect(keys(ctx.env.project.deps)),
collect(keys(ctx.env.project.extras)))
filter!(ctx.env.project.targets) do (target, deps)
!isempty(filter!(in(deps_names), deps))
end
Expand Down
6 changes: 3 additions & 3 deletions src/Pkg.jl
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ a package, also inside that package.
```julia
Pkg.add("Example") # Add a package from registry
Pkg.add(PackageSpec(name="Example", version="0.3")) # Specify version
Pkg.add(PackageSpec(url="https://github.com/JuliaLang/Example.jl", rev="master")) # From url
Pkg.add(PackageSpec(url="/remote/mycompany/juliapackages/OurPackage"))` # From path (has to be a gitrepo)
Pkg.add(PackageSpec(url="https://github.com/JuliaLang/Example.jl", rev="master")) # From url to remote gitrepo
Pkg.add(PackageSpec(url="/remote/mycompany/juliapackages/OurPackage"))` # From path to local gitrepo
```
See also [`PackageSpec`](@ref).
Expand Down Expand Up @@ -229,7 +229,7 @@ Pkg.develop("Example")
Pkg.develop(PackageSpec(url="https://github.com/JuliaLang/Compat.jl"))
# By path
Pkg.develop(PackageSpec(path="MyJuliaPackages/Package.jl")
Pkg.develop(PackageSpec(path="MyJuliaPackages/Package.jl"))
```
See also [`PackageSpec`](@ref)
Expand Down
54 changes: 37 additions & 17 deletions src/REPLMode.jl
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ end

is_opt(word::AbstractString) = first(word) == '-'

function core_parse(words)
function core_parse(words; only_cmd=false)
# prelude
statement = Statement()
word = nothing
Expand Down Expand Up @@ -280,6 +280,8 @@ function core_parse(words)
end
statement.spec = command

only_cmd && return statement, word # hack to hook in `help` command

next_word!() || return statement, word

while is_opt(word)
Expand Down Expand Up @@ -578,24 +580,35 @@ function CommandSpec(command_name::String)::Union{Nothing,CommandSpec}
return get(super, m.captures[2], nothing)
end

function parse_command(words::Vector{String})
statement, word = core_parse(words; only_cmd=true)
if statement.super === nothing && statement.spec === nothing
pkgerror("invalid input: `$word` is not a command")
end
return statement.spec === nothing ? statement.super : statement.spec
end

function do_help!(command::PkgCommand, repl::REPL.AbstractREPL)
disp = REPL.REPLDisplay(repl)
if isempty(command.arguments)
Base.display(disp, help)
return
end
help_md = md""
for arg in command.arguments
spec = CommandSpec(arg)
if spec === nothing
pkgerror("'$arg' does not name a command")

cmd = parse_command(command.arguments)
if cmd isa String
# gather all helps for super spec `cmd`
all_specs = sort!(unique(values(super_specs[cmd]));
by=(spec->spec.canonical_name))
for spec in all_specs
isempty(help_md.content) || push!(help_md.content, md"---")
push!(help_md.content, spec.help)
end
spec.help === nothing &&
pkgerror("Sorry, I don't have any help for the `$arg` command.")
isempty(help_md.content) ||
push!(help_md.content, md"---")
push!(help_md.content, spec.help)
elseif cmd isa CommandSpec
push!(help_md.content, cmd.help)
end
!isempty(command.arguments) && @warn "More than one command specified, only rendering help for first"
Base.display(disp, help_md)
end

Expand Down Expand Up @@ -791,6 +804,14 @@ function canonical_names()
return sort!(names)
end

function complete_help(options, partial)
names = String[]
for cmds in values(super_specs)
append!(names, [spec.canonical_name for spec in values(cmds)])
end
return sort!(unique!(append!(names, collect(keys(super_specs)))))
end

function complete_installed_packages(options, partial)
env = try EnvCache()
catch err
Expand Down Expand Up @@ -1051,19 +1072,18 @@ julia is started with `--startup-file=yes`.
:name => "help",
:short_name => "?",
:arg_count => 0 => Inf,
:completions => ((opt, partial) -> canonical_names()),
:completions => complete_help,
:description => "show this message",
:help => md"""
help
Display this message.
help cmd ...
List available commands along with short descriptions.
Display usage information for commands listed.
help cmd
Available commands: `help`, `status`, `add`, `rm`, `up`, `preview`, `gc`, `test`, `build`, `free`, `pin`, `develop`.
If `cmd` is a partial command, display help for all subcommands.
If `cmd` is a full command, display help for `cmd`.
""",
],[ :kind => CMD_INSTANTIATE,
:name => "instantiate",
Expand Down Expand Up @@ -1467,7 +1487,7 @@ Multiple commands can be given on the same line by interleaving a `;` between th

for command in canonical_names()
spec = CommandSpec(command)
push!(help.content, Markdown.parse("`$command`: $(spec.description)"))
push!(help.content, Markdown.parse("`$(replace(command, "-" => " "))`: $(spec.description)"))
end

end #module
36 changes: 15 additions & 21 deletions src/Types.jl
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ has_uuid(pkg::PackageSpec) = pkg.uuid !== nothing

function Base.show(io::IO, pkg::PackageSpec)
vstr = repr(pkg.version)
f = ["name" => pkg.name, "uuid" => has_uuid(pkg) ? pkg.uuid : "", "v" => (vstr == "VersionSpec(\"*\")" ? "" : vstr)]
f = ["name" => has_name(pkg) ? pkg.name : "", "uuid" => has_uuid(pkg) ? pkg.uuid : "", "v" => (vstr == "VersionSpec(\"*\")" ? "" : vstr)]
if pkg.repo !== nothing
if pkg.repo.url !== nothing
push!(f, "url/path" => string("\"", pkg.repo.url, "\""))
Expand Down Expand Up @@ -1384,9 +1384,9 @@ function registered_uuid(env::EnvCache, name::String)::Union{Nothing,UUID}
end

# Determine current name for a given package UUID
function registered_name(env::EnvCache, uuid::UUID)::String
function registered_name(env::EnvCache, uuid::UUID)::Union{Nothing,String}
names = registered_names(env, uuid)
length(names) == 0 && return ""
length(names) == 0 && return nothing
length(names) == 1 && return names[1]
values = registered_info(env, uuid, "name")
name = nothing
Expand Down Expand Up @@ -1450,27 +1450,21 @@ function project_key_order(key::String)
return 8
end

string(x::Vector{String}) = x

function destructure(project::Project)::Dict
raw = project.other
function entry!(key::String, src::Dict)
if isempty(src)
delete!(raw, key)
else
raw[key] = Dict(string(name) => string(uuid) for (name,uuid) in src)
end
end
entry!(key::String, src) = src === nothing ? delete!(raw, key) : (raw[key] = string(src))
raw = deepcopy(project.other)

should_delete(x::Dict) = isempty(x)
should_delete(x) = x === nothing
entry!(key::String, src) = should_delete(src) ? delete!(raw, key) : (raw[key] = src)

entry!("name", project.name)
entry!("uuid", project.uuid)
entry!("version", project.version)
entry!("name", project.name)
entry!("uuid", project.uuid)
entry!("version", project.version)
entry!("manifest", project.manifest)
entry!("deps", project.deps)
entry!("extras", project.extras)
entry!("compat", project.compat)
entry!("targets", project.targets)
entry!("deps", project.deps)
entry!("extras", project.extras)
entry!("compat", project.compat)
entry!("targets", project.targets)
return raw
end

Expand Down
Loading

0 comments on commit e0407bf

Please sign in to comment.