Skip to content

Commit 7140b26

Browse files
fredrikekreKristofferC
authored andcommitted
Use the current std(out|err) for printing, fixes #2542. (#2543)
(cherry picked from commit ad3d639)
1 parent d876a0a commit 7140b26

File tree

6 files changed

+40
-36
lines changed

6 files changed

+40
-36
lines changed

src/API.jl

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import ..can_fancyprint, ..DEFAULT_IO
1616
using ..Types, ..TOML
1717
using ..Types: VersionTypes
1818
using Base.BinaryPlatforms
19+
import ..stderr_f, ..stdout_f
1920
using ..Artifacts: artifact_paths
2021
using ..MiniProgressBars
2122

@@ -73,7 +74,7 @@ for f in (:develop, :add, :rm, :up, :pin, :free, :test, :build, :status)
7374
@eval begin
7475
$f(pkg::Union{AbstractString, PackageSpec}; kwargs...) = $f([pkg]; kwargs...)
7576
$f(pkgs::Vector{<:AbstractString}; kwargs...) = $f([PackageSpec(pkg) for pkg in pkgs]; kwargs...)
76-
function $f(pkgs::Vector{PackageSpec}; io::IO=DEFAULT_IO[], kwargs...)
77+
function $f(pkgs::Vector{PackageSpec}; io::IO=$(f === :status ? :stdout_f : :stderr_f)(), kwargs...)
7778
ctx = Context()
7879
kwargs = merge((;kwargs...), (:io => io,))
7980
ret = $f(ctx, pkgs; kwargs...)
@@ -261,7 +262,7 @@ function up(ctx::Context, pkgs::Vector{PackageSpec};
261262
return
262263
end
263264

264-
resolve(; io::IO=DEFAULT_IO[], kwargs...) = resolve(Context(;io); kwargs...)
265+
resolve(; io::IO=stderr_f(), kwargs...) = resolve(Context(;io); kwargs...)
265266
function resolve(ctx::Context; kwargs...)
266267
up(ctx; level=UPLEVEL_FIXED, mode=PKGMODE_MANIFEST, update_registry=false, kwargs...)
267268
return nothing
@@ -1422,7 +1423,7 @@ function status(ctx::Context, pkgs::Vector{PackageSpec}; diff::Bool=false, mode=
14221423
end
14231424

14241425

1425-
function activate(;temp=false, shared=false, io::IO=DEFAULT_IO[])
1426+
function activate(;temp=false, shared=false, io::IO=stderr_f())
14261427
shared && pkgerror("Must give a name for a shared environment")
14271428
temp && return activate(mktempdir())
14281429
Base.ACTIVE_PROJECT[] = nothing
@@ -1448,7 +1449,7 @@ function _activate_dep(dep_name::AbstractString)
14481449
end
14491450
end
14501451
end
1451-
function activate(path::AbstractString; shared::Bool=false, temp::Bool=false, io::IO=DEFAULT_IO[])
1452+
function activate(path::AbstractString; shared::Bool=false, temp::Bool=false, io::IO=stderr_f())
14521453
temp && pkgerror("Can not give `path` argument when creating a temporary environment")
14531454
if !shared
14541455
# `pkg> activate path`/`Pkg.activate(path)` does the following

src/Artifacts.jl

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import ..GitTools
1111
import ..TOML
1212
import ..Types: parse_toml, write_env_usage, printpkgstyle
1313
import ..Pkg
14-
import ..Pkg: pkg_server, can_fancyprint, DEFAULT_IO
14+
import ..Pkg: pkg_server, can_fancyprint, stderr_f
1515
using ..Pkg.MiniProgressBars
1616
using ..PlatformEngines
1717
using SHA
@@ -286,7 +286,7 @@ end
286286

287287
"""
288288
download_artifact(tree_hash::SHA1, tarball_url::String, tarball_hash::String;
289-
verbose::Bool = false, io::IO=DEFAULT_IO[])
289+
verbose::Bool = false, io::IO=stderr)
290290
291291
Download/install an artifact into the artifact store. Returns `true` on success.
292292
@@ -299,7 +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[],
302+
io::IO=stderr_f(),
303303
)
304304
if artifact_exists(tree_hash)
305305
return true
@@ -386,7 +386,7 @@ end
386386
pkg_uuid::Union{Base.UUID,Nothing}=nothing,
387387
verbose::Bool = false,
388388
quiet_download::Bool = false,
389-
io::IO=DEFAULT_IO[])
389+
io::IO=stderr)
390390
391391
Ensures an artifact is installed, downloading it via the download information stored in
392392
`artifacts_toml` if necessary. Throws an error if unable to install.
@@ -399,7 +399,7 @@ function ensure_artifact_installed(name::String, artifacts_toml::String;
399399
pkg_uuid::Union{Base.UUID,Nothing}=nothing,
400400
verbose::Bool = false,
401401
quiet_download::Bool = false,
402-
io::IO=DEFAULT_IO[])
402+
io::IO=stderr_f())
403403
meta = artifact_meta(name, artifacts_toml; pkg_uuid=pkg_uuid, platform=platform)
404404
if meta === nothing
405405
error("Cannot locate artifact '$(name)' in '$(artifacts_toml)'")
@@ -413,7 +413,7 @@ function ensure_artifact_installed(name::String, meta::Dict, artifacts_toml::Str
413413
platform::AbstractPlatform = HostPlatform(),
414414
verbose::Bool = false,
415415
quiet_download::Bool = false,
416-
io::IO=DEFAULT_IO[])
416+
io::IO=stderr_f())
417417
hash = SHA1(meta["git-tree-sha1"])
418418

419419
if !artifact_exists(hash)
@@ -472,7 +472,7 @@ end
472472
include_lazy = false,
473473
verbose = false,
474474
quiet_download = false,
475-
io::IO=DEFAULT_IO[])
475+
io::IO=stderr)
476476
477477
Installs all non-lazy artifacts from a given `(Julia)Artifacts.toml` file. `package_uuid` must
478478
be provided to properly support overrides from `Overrides.toml` entries in depots.
@@ -488,7 +488,7 @@ function ensure_all_artifacts_installed(artifacts_toml::String;
488488
include_lazy::Bool = false,
489489
verbose::Bool = false,
490490
quiet_download::Bool = false,
491-
io::IO=DEFAULT_IO[])
491+
io::IO=stderr_f())
492492
if !isfile(artifacts_toml)
493493
return
494494
end

src/Operations.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ 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, DEFAULT_IO
17+
import ...Pkg: can_fancyprint, stderr_f
1818
import ..Types: printpkgstyle
1919

2020
#########
@@ -567,7 +567,7 @@ function install_archive(
567567
urls::Vector{Pair{String,Bool}},
568568
hash::SHA1,
569569
version_path::String;
570-
io::IO=DEFAULT_IO[]
570+
io::IO=stderr_f()
571571
)::Bool
572572
tmp_objects = String[]
573573
url_success = false
@@ -686,7 +686,7 @@ end
686686
function download_artifacts(ctx::Context, pkg_roots::Vector{String};
687687
platform::AbstractPlatform=HostPlatform(),
688688
verbose::Bool=false,
689-
io::IO=DEFAULT_IO[])
689+
io::IO=stderr_f())
690690
# List of Artifacts.toml files that we're going to download from
691691
artifacts_tomls = String[]
692692

src/Pkg.jl

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,10 @@ devdir(depot = depots1()) = get(ENV, "JULIA_PKG_DEVDIR", joinpath(depots1(), "de
3232
envdir(depot = depots1()) = joinpath(depot, "environments")
3333
const UPDATED_REGISTRY_THIS_SESSION = Ref(false)
3434
const OFFLINE_MODE = Ref(false)
35-
const DEFAULT_IO = Ref{IO}()
35+
# For globally overriding in e.g. tests
36+
const DEFAULT_IO = Ref{Union{IO,Nothing}}(nothing)
37+
stderr_f() = something(DEFAULT_IO[], stderr)
38+
stdout_f() = something(DEFAULT_IO[], stdout)
3639

3740
can_fancyprint(io::IO) = (io isa Base.TTY) && (get(ENV, "CI", nothing) != "true")
3841

@@ -216,7 +219,7 @@ by starting julia with `--inline=no`.
216219
const test = API.test
217220

218221
"""
219-
Pkg.gc(; io::IO=DEFAULT_IO[])
222+
Pkg.gc(; io::IO=stderr)
220223
221224
Garbage collect packages that are no longer reachable from any project.
222225
Only packages that are tracked by version are deleted, so no packages
@@ -226,9 +229,9 @@ const gc = API.gc
226229

227230

228231
"""
229-
Pkg.build(; verbose = false, io::IO=DEFAULT_IO[])
230-
Pkg.build(pkg::Union{String, Vector{String}}; verbose = false, io::IO=DEFAULT_IO[])
231-
Pkg.build(pkgs::Union{PackageSpec, Vector{PackageSpec}}; verbose = false, io::IO=DEFAULT_IO[])
232+
Pkg.build(; verbose = false, io::IO=stderr)
233+
Pkg.build(pkg::Union{String, Vector{String}}; verbose = false, io::IO=stderr)
234+
Pkg.build(pkgs::Union{PackageSpec, Vector{PackageSpec}}; verbose = false, io::IO=stderr)
232235
233236
Run the build script in `deps/build.jl` for `pkg` and all of its dependencies in
234237
depth-first recursive order.
@@ -242,8 +245,8 @@ redirecting to the `build.log` file.
242245
const build = API.build
243246

244247
"""
245-
Pkg.pin(pkg::Union{String, Vector{String}}; io::IO=DEFAULT_IO[])
246-
Pkg.pin(pkgs::Union{PackageSpec, Vector{PackageSpec}}; io::IO=DEFAULT_IO[])
248+
Pkg.pin(pkg::Union{String, Vector{String}}; io::IO=stderr)
249+
Pkg.pin(pkgs::Union{PackageSpec, Vector{PackageSpec}}; io::IO=stderr)
247250
248251
Pin a package to the current version (or the one given in the `PackageSpec`) or to a certain
249252
git revision. A pinned package is never updated.
@@ -257,8 +260,8 @@ Pkg.pin(name="Example", version="0.3.1")
257260
const pin = API.pin
258261

259262
"""
260-
Pkg.free(pkg::Union{String, Vector{String}}; io::IO=DEFAULT_IO[])
261-
Pkg.free(pkgs::Union{PackageSpec, Vector{PackageSpec}}; io::IO=DEFAULT_IO[])
263+
Pkg.free(pkg::Union{String, Vector{String}}; io::IO=stderr)
264+
Pkg.free(pkgs::Union{PackageSpec, Vector{PackageSpec}}; io::IO=stderr)
262265
263266
If `pkg` is pinned, remove the pin.
264267
If `pkg` is tracking a path,
@@ -273,8 +276,8 @@ const free = API.free
273276

274277

275278
"""
276-
Pkg.develop(pkg::Union{String, Vector{String}}; io::IO=DEFAULT_IO[])
277-
Pkg.develop(pkgs::Union{Packagespec, Vector{Packagespec}}; io::IO=DEFAULT_IO[])
279+
Pkg.develop(pkg::Union{String, Vector{String}}; io::IO=stderr)
280+
Pkg.develop(pkgs::Union{Packagespec, Vector{Packagespec}}; io::IO=stderr)
278281
279282
Make a package available for development by tracking it by path.
280283
If `pkg` is given with only a name or by a URL, the package will be downloaded
@@ -347,7 +350,7 @@ Request a `ProjectInfo` struct which contains information about the active proje
347350
const project = API.project
348351

349352
"""
350-
Pkg.instantiate(; verbose = false, io::IO=DEFAULT_IO[])
353+
Pkg.instantiate(; verbose = false, io::IO=stderr)
351354
352355
If a `Manifest.toml` file exists in the active project, download all
353356
the packages declared in that manifest.
@@ -361,7 +364,7 @@ dependencies in the manifest and instantiate the resulting project.
361364
const instantiate = API.instantiate
362365

363366
"""
364-
Pkg.resolve(; io::IO=DEFAULT_IO[])
367+
Pkg.resolve(; io::IO=stderr)
365368
366369
Update the current manifest with potential changes to the dependency graph
367370
from packages that are tracking a path.
@@ -390,7 +393,8 @@ const status = API.status
390393

391394

392395
"""
393-
Pkg.activate([s::String]; shared::Bool=false, io::IO=DEFAULT_IO[])
396+
Pkg.activate([s::String]; shared::Bool=false, io::IO=stderr)
397+
Pkg.activate(; temp::Bool=false, shared::Bool=false, io::IO=stderr)
394398
395399
Activate the environment at `s`. The active environment is the environment
396400
that is modified by executing package commands.
@@ -544,7 +548,6 @@ const RegistrySpec = Types.RegistrySpec
544548

545549

546550
function __init__()
547-
DEFAULT_IO[] = stderr
548551
if isdefined(Base, :active_repl)
549552
REPLMode.repl_init(Base.active_repl)
550553
else

src/PlatformEngines.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
module PlatformEngines
66

77
using SHA, Downloads, Tar
8-
import ...Pkg: Pkg, TOML, pkg_server, depots1, can_fancyprint, DEFAULT_IO
8+
import ...Pkg: Pkg, TOML, pkg_server, depots1, can_fancyprint, stderr_f
99
using ..MiniProgressBars
1010
using Base.BinaryPlatforms, p7zip_jll
1111

@@ -242,7 +242,7 @@ function download(
242242
verbose::Bool = false,
243243
headers::Vector{Pair{String,String}} = Pair{String,String}[],
244244
auth_header::Union{Pair{String,String}, Nothing} = nothing,
245-
io::IO=DEFAULT_IO[]
245+
io::IO=stderr_f()
246246
)
247247
if auth_header === nothing
248248
auth_header = get_auth_header(url, verbose=verbose)
@@ -405,7 +405,7 @@ end
405405
force::Bool = false,
406406
verbose::Bool = false,
407407
quiet_download::Bool = false,
408-
io::IO=DEFAULT_IO[],
408+
io::IO=stderr,
409409
)
410410
411411
Helper method to download tarball located at `url`, verify it matches the
@@ -440,7 +440,7 @@ function download_verify_unpack(
440440
force::Bool = false,
441441
verbose::Bool = false,
442442
quiet_download::Bool = false,
443-
io::IO=DEFAULT_IO[],
443+
io::IO=stderr_f(),
444444
)
445445
# First, determine whether we should keep this tarball around
446446
remove_tarball = false

src/Types.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import Base.string
1111
using REPL.TerminalMenus
1212

1313
using TOML
14-
import ...Pkg, ..UPDATED_REGISTRY_THIS_SESSION, ..DEFAULT_IO
14+
import ...Pkg, ..UPDATED_REGISTRY_THIS_SESSION, ..stderr_f
1515
import ...Pkg: GitTools, depots, depots1, logdir, set_readonly, safe_realpath, pkg_server
1616
import Base.BinaryPlatforms: Platform
1717
import ..PlatformEngines: probe_platform_engines!, download, download_verify_unpack
@@ -313,7 +313,7 @@ include("manifest.jl")
313313
# ENV variables to set some of these defaults?
314314
Base.@kwdef mutable struct Context
315315
env::EnvCache = EnvCache()
316-
io::IO = something(DEFAULT_IO[], stderr)
316+
io::IO = stderr_f()
317317
use_libgit2_for_all_downloads::Bool = false
318318
use_only_tarballs_for_downloads::Bool = false
319319
num_concurrent_downloads::Int = 8

0 commit comments

Comments
 (0)