Skip to content

Commit c78a8be

Browse files
authored
Merge pull request #2425 from IanButterworth/ib/backports_16
1.6.1 backports
2 parents 05fa7f9 + 0d33deb commit c78a8be

File tree

12 files changed

+278
-190
lines changed

12 files changed

+278
-190
lines changed

.github/workflows/test.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ jobs:
1414
fail-fast: false
1515
matrix:
1616
julia-version:
17-
# - '1.6'
18-
- 'nightly'
17+
- '1.6'
18+
# - 'nightly'
1919
julia-arch:
2020
- 'x64'
2121
- 'x86'
@@ -53,6 +53,8 @@ jobs:
5353
env:
5454
JULIA_PKG_SERVER: ${{ matrix.pkg-server }}
5555
- uses: julia-actions/julia-processcoverage@v1
56+
env:
57+
JULIA_PKG_SERVER: ${{ matrix.pkg-server }}
5658
- uses: codecov/codecov-action@v1
5759
with:
5860
file: lcov.info

src/API.jl

Lines changed: 115 additions & 87 deletions
Large diffs are not rendered by default.

src/Artifacts.jl

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ end
286286

287287
"""
288288
download_artifact(tree_hash::SHA1, tarball_url::String, tarball_hash::String;
289-
verbose::Bool = false)
289+
verbose::Bool = false, io::IO=DEFAULT_IO[])
290290
291291
Download/install an artifact into the artifact store. Returns `true` on success.
292292
@@ -299,6 +299,7 @@ function download_artifact(
299299
tarball_hash::Union{String, Nothing} = nothing;
300300
verbose::Bool = false,
301301
quiet_download::Bool = false,
302+
io::IO=DEFAULT_IO[],
302303
)
303304
if artifact_exists(tree_hash)
304305
return true
@@ -319,7 +320,7 @@ function download_artifact(
319320
# the filesystem ACLs for executable permissions, which git tree hashes care about.
320321
try
321322
download_verify_unpack(tarball_url, tarball_hash, dest_dir, ignore_existence=true,
322-
verbose=verbose, quiet_download=quiet_download)
323+
verbose=verbose, quiet_download=quiet_download, io=io)
323324
catch e
324325
# Clean that destination directory out if something went wrong
325326
rm(dest_dir; force=true, recursive=true)
@@ -339,7 +340,8 @@ function download_artifact(
339340
# `create_artifact()` wrapper does, so we use that here.
340341
calc_hash = try
341342
create_artifact() do dir
342-
download_verify_unpack(tarball_url, tarball_hash, dir, ignore_existence=true, verbose=verbose, quiet_download=quiet_download)
343+
download_verify_unpack(tarball_url, tarball_hash, dir, ignore_existence=true, verbose=verbose,
344+
quiet_download=quiet_download, io=io)
343345
end
344346
catch e
345347
if isa(e, InterruptException)
@@ -379,7 +381,10 @@ end
379381
"""
380382
ensure_artifact_installed(name::String, artifacts_toml::String;
381383
platform::AbstractPlatform = HostPlatform(),
382-
pkg_uuid::Union{Base.UUID,Nothing}=nothing)
384+
pkg_uuid::Union{Base.UUID,Nothing}=nothing,
385+
verbose::Bool = false,
386+
quiet_download::Bool = false,
387+
io::IO=DEFAULT_IO[])
383388
384389
Ensures an artifact is installed, downloading it via the download information stored in
385390
`artifacts_toml` if necessary. Throws an error if unable to install.
@@ -391,29 +396,31 @@ function ensure_artifact_installed(name::String, artifacts_toml::String;
391396
platform::AbstractPlatform = HostPlatform(),
392397
pkg_uuid::Union{Base.UUID,Nothing}=nothing,
393398
verbose::Bool = false,
394-
quiet_download::Bool = false)
399+
quiet_download::Bool = false,
400+
io::IO=DEFAULT_IO[])
395401
meta = artifact_meta(name, artifacts_toml; pkg_uuid=pkg_uuid, platform=platform)
396402
if meta === nothing
397403
error("Cannot locate artifact '$(name)' in '$(artifacts_toml)'")
398404
end
399405

400406
return ensure_artifact_installed(name, meta, artifacts_toml; platform=platform,
401-
verbose=verbose, quiet_download=quiet_download)
407+
verbose=verbose, quiet_download=quiet_download, io=io)
402408
end
403409

404410
function ensure_artifact_installed(name::String, meta::Dict, artifacts_toml::String;
405411
platform::AbstractPlatform = HostPlatform(),
406412
verbose::Bool = false,
407-
quiet_download::Bool = false)
413+
quiet_download::Bool = false,
414+
io::IO=DEFAULT_IO[])
408415
hash = SHA1(meta["git-tree-sha1"])
409416

410417
if !artifact_exists(hash)
411418
# first try downloading from Pkg server
412419
# TODO: only do this if Pkg server knows about this package
413420
if (server = pkg_server()) !== nothing
414421
url = "$server/artifact/$hash"
415-
download_success = with_show_download_info(name, quiet_download) do
416-
download_artifact(hash, url; verbose=verbose, quiet_download=quiet_download)
422+
download_success = with_show_download_info(io, name, quiet_download) do
423+
download_artifact(hash, url; verbose=verbose, quiet_download=quiet_download, io=io)
417424
end
418425
download_success && return artifact_path(hash)
419426
end
@@ -428,8 +435,8 @@ function ensure_artifact_installed(name::String, meta::Dict, artifacts_toml::Str
428435
for entry in meta["download"]
429436
url = entry["url"]
430437
tarball_hash = entry["sha256"]
431-
download_success = with_show_download_info(name, quiet_download) do
432-
download_artifact(hash, url, tarball_hash; verbose=verbose, quiet_download=quiet_download)
438+
download_success = with_show_download_info(io, name, quiet_download) do
439+
download_artifact(hash, url, tarball_hash; verbose=verbose, quiet_download=quiet_download, io=io)
433440
end
434441
download_success && return artifact_path(hash)
435442
end
@@ -439,9 +446,7 @@ function ensure_artifact_installed(name::String, meta::Dict, artifacts_toml::Str
439446
end
440447
end
441448

442-
function with_show_download_info(f, name, quiet_download)
443-
# TODO: Use DEFAULT_IO?
444-
io = stderr
449+
function with_show_download_info(f, io, name, quiet_download)
445450
fancyprint = can_fancyprint(io)
446451
if !quiet_download
447452
fancyprint && print_progress_bottom(io)
@@ -464,7 +469,8 @@ end
464469
pkg_uuid = nothing,
465470
include_lazy = false,
466471
verbose = false,
467-
quiet_download = false)
472+
quiet_download = false,
473+
io::IO=DEFAULT_IO[])
468474
469475
Installs all non-lazy artifacts from a given `(Julia)Artifacts.toml` file. `package_uuid` must
470476
be provided to properly support overrides from `Overrides.toml` entries in depots.
@@ -479,7 +485,8 @@ function ensure_all_artifacts_installed(artifacts_toml::String;
479485
pkg_uuid::Union{Nothing,Base.UUID} = nothing,
480486
include_lazy::Bool = false,
481487
verbose::Bool = false,
482-
quiet_download::Bool = false)
488+
quiet_download::Bool = false,
489+
io::IO=DEFAULT_IO[])
483490
if !isfile(artifacts_toml)
484491
return
485492
end
@@ -499,7 +506,7 @@ function ensure_all_artifacts_installed(artifacts_toml::String;
499506

500507
# Otherwise, let's try and install it!
501508
ensure_artifact_installed(name, meta, artifacts_toml; platform=platform,
502-
verbose=verbose, quiet_download=quiet_download)
509+
verbose=verbose, quiet_download=quiet_download, io=io)
503510
end
504511
end
505512

src/MiniProgressBars.jl

Lines changed: 11 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -21,25 +21,6 @@ end
2121
const NONINTERACTIVE_TIME_GRANULARITY = Ref(2.0)
2222
const PROGRESS_BAR_PERCENTAGE_GRANULARITY = Ref(0.1)
2323

24-
function pretend_cursor()
25-
io = stderr
26-
bar = MiniProgressBar(; indent=2, header = "Progress", color = Base.info_color(),
27-
percentage=false, always_reprint=true)
28-
bar.max = 40
29-
start_progress(io, bar)
30-
sleep(0.5)
31-
for i in 1:40
32-
bar.current = i
33-
print_progress_bottom(io)
34-
println("Downloading ... $i")
35-
show_progress(io, bar)
36-
x = randstring(7)
37-
sleep(0.01)
38-
end
39-
end_progress(io, bar)
40-
print("Hello!")
41-
end
42-
4324
function start_progress(io::IO, _::MiniProgressBar)
4425
ansi_disablecursor = "\e[?25l"
4526
print(io, ansi_disablecursor)
@@ -67,18 +48,22 @@ function show_progress(io::IO, p::MiniProgressBar)
6748
end
6849
p.prev = p.current
6950
p.has_shown = true
70-
n_filled = ceil(Int, p.width * perc / 100)
71-
n_left = p.width - n_filled
51+
52+
progress_text = if p.percentage
53+
@sprintf "%2.1f %%" perc
54+
else
55+
string(p.current, "/", p.max)
56+
end
57+
58+
max_progress_width = max(0, min(displaysize(io)[2] - textwidth(p.header) - textwidth(progress_text) - 10 , p.width))
59+
n_filled = ceil(Int, max_progress_width * perc / 100)
60+
n_left = max_progress_width - n_filled
7261
print(io, " "^p.indent)
7362
printstyled(io, p.header, color=p.color, bold=true)
7463
print(io, " [")
7564
print(io, "="^n_filled, ">")
7665
print(io, " "^n_left, "] ", )
77-
if p.percentage
78-
@printf io "%2.1f %%" perc
79-
else
80-
print(io, p.current, "/", p.max)
81-
end
66+
print(io, progress_text)
8267
print(io, "\r")
8368
end
8469

src/Operations.jl

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ import ..Artifacts: ensure_all_artifacts_installed, artifact_names, extract_all_
1414
using Base.BinaryPlatforms
1515
import ...Pkg
1616
import ...Pkg: pkg_server
17-
import ..Pkg: can_fancyprint
17+
import ...Pkg: can_fancyprint, DEFAULT_IO
18+
import ..Types: printpkgstyle
1819

1920
#########
2021
# Utils #
@@ -565,7 +566,8 @@ end
565566
function install_archive(
566567
urls::Vector{Pair{String,Bool}},
567568
hash::SHA1,
568-
version_path::String
569+
version_path::String;
570+
io::IO=DEFAULT_IO[]
569571
)::Bool
570572
tmp_objects = String[]
571573
url_success = false
@@ -574,7 +576,7 @@ function install_archive(
574576
push!(tmp_objects, path) # for cleanup
575577
url_success = true
576578
try
577-
PlatformEngines.download(url, path; verbose=false)
579+
PlatformEngines.download(url, path; verbose=false, io=io)
578580
catch e
579581
e isa InterruptException && rethrow()
580582
url_success = false
@@ -669,20 +671,22 @@ end
669671
function download_artifacts(ctx::Context, pkgs::Vector{PackageSpec};
670672
platform::AbstractPlatform=HostPlatform(),
671673
julia_version = VERSION,
672-
verbose::Bool=false)
674+
verbose::Bool=false,
675+
io::IO=DEFAULT_IO[])
673676
# Filter out packages that have no source_path()
674677
# pkg_roots = String[p for p in source_path.((ctx,), pkgs) if p !== nothing] # this runs up against inference limits?
675678
pkg_roots = String[]
676679
for pkg in pkgs
677680
p = source_path(ctx, pkg)
678681
p !== nothing && push!(pkg_roots, p)
679682
end
680-
return download_artifacts(ctx, pkg_roots; platform=platform, verbose=verbose)
683+
return download_artifacts(ctx, pkg_roots; platform=platform, verbose=verbose, io=io)
681684
end
682685

683686
function download_artifacts(ctx::Context, pkg_roots::Vector{String};
684687
platform::AbstractPlatform=HostPlatform(),
685-
verbose::Bool=false)
688+
verbose::Bool=false,
689+
io::IO=DEFAULT_IO[])
686690
# List of Artifacts.toml files that we're going to download from
687691
artifacts_tomls = String[]
688692

@@ -776,7 +780,7 @@ function download_source(ctx::Context, pkgs::Vector{PackageSpec},
776780
url = get_archive_url_for_version(repo_url, pkg.tree_hash)
777781
url !== nothing && push!(archive_urls, url => false)
778782
end
779-
success = install_archive(archive_urls, pkg.tree_hash, path)
783+
success = install_archive(archive_urls, pkg.tree_hash, path, io=ctx.io)
780784
if success && readonly
781785
set_readonly(path) # In add mode, files should be read-only
782786
end
@@ -1101,17 +1105,15 @@ function rm(ctx::Context, pkgs::Vector{PackageSpec})
11011105
println(ctx.io, "No changes")
11021106
return
11031107
end
1104-
# only declare `compat` for direct dependencies
1108+
# only declare `compat` for remaining direct or `extra` dependencies
11051109
# `julia` is always an implicit direct dependency
11061110
filter!(ctx.env.project.compat) do (name, _)
1107-
name == "julia" || name in keys(ctx.env.project.deps)
1111+
name == "julia" || name in keys(ctx.env.project.deps) || name in keys(ctx.env.project.extras)
11081112
end
1109-
deps_names = append!(collect(keys(ctx.env.project.deps)),
1110-
collect(keys(ctx.env.project.extras)))
1113+
deps_names = union(keys(ctx.env.project.deps), keys(ctx.env.project.extras))
11111114
filter!(ctx.env.project.targets) do (target, deps)
11121115
!isempty(filter!(in(deps_names), deps))
11131116
end
1114-
11151117
# only keep reachable manifest entires
11161118
prune_manifest(ctx)
11171119
# update project & manifest
@@ -1232,7 +1234,7 @@ function add(ctx::Context, pkgs::Vector{PackageSpec}, new_git=UUID[];
12321234

12331235
# After downloading resolutionary packages, search for (Julia)Artifacts.toml files
12341236
# and ensure they are all downloaded and unpacked as well:
1235-
download_artifacts(ctx, pkgs; platform=platform)
1237+
download_artifacts(ctx, pkgs; platform=platform, io=ctx.io)
12361238

12371239
write_env(ctx.env) # write env before building
12381240
show_update(ctx)
@@ -1251,7 +1253,7 @@ function develop(ctx::Context, pkgs::Vector{PackageSpec}, new_git::Vector{UUID};
12511253
pkgs, deps_map = _resolve(ctx, pkgs, preserve)
12521254
update_manifest!(ctx, pkgs, deps_map)
12531255
new_apply = download_source(ctx, pkgs; readonly=true)
1254-
download_artifacts(ctx, pkgs; platform=platform)
1256+
download_artifacts(ctx, pkgs; platform=platform, io=ctx.io)
12551257
write_env(ctx.env) # write env before building
12561258
show_update(ctx)
12571259
build_versions(ctx, union(UUID[pkg.uuid for pkg in new_apply], new_git))
@@ -1316,7 +1318,7 @@ function up(ctx::Context, pkgs::Vector{PackageSpec}, level::UpgradeLevel)
13161318
deps_map = resolve_versions!(ctx, pkgs)
13171319
update_manifest!(ctx, pkgs, deps_map)
13181320
new_apply = download_source(ctx, pkgs)
1319-
download_artifacts(ctx, pkgs)
1321+
download_artifacts(ctx, pkgs; io=ctx.io)
13201322
write_env(ctx.env) # write env before building
13211323
show_update(ctx)
13221324
build_versions(ctx, union(UUID[pkg.uuid for pkg in new_apply], new_git))
@@ -1359,7 +1361,7 @@ function pin(ctx::Context, pkgs::Vector{PackageSpec})
13591361
update_manifest!(ctx, pkgs, deps_map)
13601362

13611363
new = download_source(ctx, pkgs)
1362-
download_artifacts(ctx, pkgs)
1364+
download_artifacts(ctx, pkgs; io=ctx.io)
13631365
write_env(ctx.env) # write env before building
13641366
show_update(ctx)
13651367
build_versions(ctx, UUID[pkg.uuid for pkg in new])
@@ -1396,7 +1398,7 @@ function free(ctx::Context, pkgs::Vector{PackageSpec})
13961398
pkgs, deps_map = _resolve(ctx, pkgs, PRESERVE_TIERED)
13971399
update_manifest!(ctx, pkgs, deps_map)
13981400
new = download_source(ctx, pkgs)
1399-
download_artifacts(ctx, new)
1401+
download_artifacts(ctx, new; io=ctx.io)
14001402
write_env(ctx.env) # write env before building
14011403
show_update(ctx)
14021404
build_versions(ctx, UUID[pkg.uuid for pkg in new])
@@ -1742,12 +1744,14 @@ print_single(ctx::Context, pkg::PackageSpec) = printstyled(ctx.io, stat_rep(pkg)
17421744

17431745
is_instantiated(::Nothing) = false
17441746
is_instantiated(x::PackageSpec) = x.version != VersionSpec() || is_stdlib(x.uuid)
1747+
# Compare an old and new node of the dependency graph and print a single line to summarize the change
17451748
function print_diff(ctx::Context, old::Union{Nothing,PackageSpec}, new::Union{Nothing,PackageSpec})
17461749
if !is_instantiated(old) && is_instantiated(new)
17471750
printstyled(ctx.io, "+ $(stat_rep(new))"; color=:light_green)
17481751
elseif !is_instantiated(new)
17491752
printstyled(ctx.io, "- $(stat_rep(old))"; color=:light_red)
1750-
elseif is_tracking_registry(old) && is_tracking_registry(new) && new.version isa VersionNumber && old.version isa VersionNumber
1753+
elseif is_tracking_registry(old) && is_tracking_registry(new) &&
1754+
new.version isa VersionNumber && old.version isa VersionNumber && new.version != old.version
17511755
if new.version > old.version
17521756
printstyled(ctx.io, "$(stat_rep(old))$(stat_rep(new; name=false))"; color=:light_yellow)
17531757
else

0 commit comments

Comments
 (0)