Skip to content

Commit

Permalink
make artifact download more similar to rest of Pkg "theme" (#1620)
Browse files Browse the repository at this point in the history
  • Loading branch information
KristofferC authored Jan 17, 2020
1 parent 359a3e5 commit f78c1e1
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 11 deletions.
30 changes: 24 additions & 6 deletions src/Artifacts.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import ..depots1, ..depots, ..set_readonly
import ..GitTools
using ..BinaryPlatforms
import ..TOML
import ..Types: parse_toml, write_env_usage
import ..Types: parse_toml, write_env_usage, printpkgstyle
import ...Pkg: pkg_server
using ..PlatformEngines
using SHA
Expand Down Expand Up @@ -728,7 +728,7 @@ function download_artifact(
tarball_url::String,
tarball_hash::Union{String, Nothing} = nothing;
verbose::Bool = false,
quiet_download::Bool = !(stderr isa Base.TTY),
quiet_download::Bool = false,
)
if artifact_exists(tree_hash)
return true
Expand Down Expand Up @@ -870,9 +870,10 @@ function ensure_artifact_installed(name::String, meta::Dict, artifacts_toml::Str
# TODO: only do this if Pkg server knows about this package
if (server = pkg_server()) !== nothing
url = "$server/artifact/$hash"
if download_artifact(hash, url; verbose=verbose, quiet_download=quiet_download)
return artifact_path(hash)
download_success = with_show_download_info(name, quiet_download) do
download_artifact(hash, url; verbose=verbose, quiet_download=quiet_download)
end
download_success && return artifact_path(hash)
end

# If this artifact does not exist on-disk already, ensure it has download
Expand All @@ -885,16 +886,33 @@ function ensure_artifact_installed(name::String, meta::Dict, artifacts_toml::Str
for entry in meta["download"]
url = entry["url"]
tarball_hash = entry["sha256"]
if download_artifact(hash, url, tarball_hash; verbose=verbose, quiet_download=quiet_download)
return artifact_path(hash)
download_success = with_show_download_info(name, quiet_download) do
download_artifact(hash, url, tarball_hash; verbose=verbose, quiet_download=quiet_download)
end
download_success && return artifact_path(hash)
end
error("Unable to automatically install '$(name)' from '$(artifacts_toml)'")
else
return artifact_path(hash)
end
end

function with_show_download_info(f, name, quiet_download)
if !quiet_download
# Should ideally pass ctx::Context as first arg here
printpkgstyle(stdout, :Downloading, "artifact: $name")
print(stdout, "\e[?25l") # disable cursor
end
try
return f()
finally
if !quiet_download
print(stdout, "\033[1A") # move cursor up one line
print(stdout, "\033[2K") # clear line
print(stdout, "\e[?25h") # put back cursor
end
end
end

"""
ensure_all_artifacts_installed(artifacts_toml::String;
Expand Down
3 changes: 1 addition & 2 deletions src/Operations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -605,9 +605,8 @@ function download_artifacts(ctx::Context, pkg_roots::Vector{String}; platform::P
end

if !isempty(artifacts_tomls)
printpkgstyle(ctx, :Downloading, "artifacts...")
for artifacts_toml in artifacts_tomls
ensure_all_artifacts_installed(artifacts_toml; platform=platform, verbose=verbose, quiet_download=false)
ensure_all_artifacts_installed(artifacts_toml; platform=platform, verbose=verbose, quiet_download=!(stderr isa Base.TTY))
write_env_usage(artifacts_toml, "artifact_usage.toml")
end
end
Expand Down
2 changes: 1 addition & 1 deletion src/PlatformEngines.jl
Original file line number Diff line number Diff line change
Expand Up @@ -835,7 +835,7 @@ function download(
end
download_cmd = gen_download_cmd(url, dest, headers...)
if verbose
@info("Downloading $(url) to $(dest)...")
# @info("Downloading $(url) to $(dest)...")
end
try
run(download_cmd, (devnull, verbose ? stdout : devnull, verbose ? stderr : devnull))
Expand Down
7 changes: 5 additions & 2 deletions src/Types.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1257,10 +1257,13 @@ function manifest_info(ctx::Context, uuid::UUID)::Union{PackageEntry,Nothing}
end

function printpkgstyle(ctx::Context, cmd::Symbol, text::String, ignore_indent::Bool=false)
printpkgstyle(ctx.io, cmd, text, ignore_indent)
end
function printpkgstyle(io::IO, cmd::Symbol, text::String, ignore_indent::Bool=false)
indent = textwidth(string(:Downloading))
ignore_indent && (indent = 0)
printstyled(ctx.io, lpad(string(cmd), indent), color=:green, bold=true)
println(ctx.io, " ", text)
printstyled(io, lpad(string(cmd), indent), color=:green, bold=true)
println(io, " ", text)
end


Expand Down

0 comments on commit f78c1e1

Please sign in to comment.