Skip to content

Rename context API methods as internal functions #4161

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
57 changes: 31 additions & 26 deletions src/API.jl
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ end

# Provide some convenience calls
for f in (:develop, :add, :rm, :up, :pin, :free, :test, :build, :status, :why, :precompile)
f_under = Symbol("_", f)
@eval begin
$f(pkg::Union{AbstractString, PackageSpec}; kwargs...) = $f([pkg]; kwargs...)
$f(pkgs::Vector{<:AbstractString}; kwargs...) = $f([PackageSpec(pkg) for pkg in pkgs]; kwargs...)
Expand All @@ -161,12 +162,12 @@ for f in (:develop, :add, :rm, :up, :pin, :free, :test, :build, :status, :why, :
kwargs = merge((;kwargs...), (:io => io,))
pkgs = deepcopy(pkgs) # don't mutate input
foreach(handle_package_input!, pkgs)
ret = $f(ctx, pkgs; kwargs...)
ret = $f_under(ctx, pkgs; kwargs...) # note the underscore for private entrypoint
$(f in (:up, :pin, :free, :build)) && Pkg._auto_precompile(ctx)
$(f in (:up, :pin, :free, :rm)) && Pkg._auto_gc(ctx)
return ret
end
$f(ctx::Context; kwargs...) = $f(ctx, PackageSpec[]; kwargs...)
$f_under(ctx::Context; kwargs...) = $f_under(ctx, PackageSpec[]; kwargs...)
function $f(; name::Union{Nothing,AbstractString}=nothing, uuid::Union{Nothing,String,UUID}=nothing,
version::Union{VersionNumber, String, VersionSpec, Nothing}=nothing,
url=nothing, rev=nothing, path=nothing, mode=PKGMODE_PROJECT, subdir=nothing, kwargs...)
Expand Down Expand Up @@ -218,7 +219,7 @@ function update_source_if_set(project, pkg)
end
end

function develop(ctx::Context, pkgs::Vector{PackageSpec}; shared::Bool=true,
function _develop(ctx::Context, pkgs::Vector{PackageSpec}; shared::Bool=true,
preserve::PreserveLevel=Operations.default_preserve(), platform::AbstractPlatform=HostPlatform(), kwargs...)
require_not_empty(pkgs, :develop)
Context!(ctx; kwargs...)
Expand Down Expand Up @@ -264,7 +265,7 @@ function develop(ctx::Context, pkgs::Vector{PackageSpec}; shared::Bool=true,
return
end

function add(ctx::Context, pkgs::Vector{PackageSpec}; preserve::PreserveLevel=Operations.default_preserve(),
function _add(ctx::Context, pkgs::Vector{PackageSpec}; preserve::PreserveLevel=Operations.default_preserve(),
platform::AbstractPlatform=HostPlatform(), target::Symbol=:deps, allow_autoprecomp::Bool=true, kwargs...)
require_not_empty(pkgs, :add)
Context!(ctx; kwargs...)
Expand Down Expand Up @@ -318,7 +319,7 @@ function add(ctx::Context, pkgs::Vector{PackageSpec}; preserve::PreserveLevel=Op
return
end

function rm(ctx::Context, pkgs::Vector{PackageSpec}; mode=PKGMODE_PROJECT, all_pkgs::Bool=false, kwargs...)
function _rm(ctx::Context, pkgs::Vector{PackageSpec}; mode=PKGMODE_PROJECT, all_pkgs::Bool=false, kwargs...)
Context!(ctx; kwargs...)
if all_pkgs
!isempty(pkgs) && pkgerror("cannot specify packages when operating on all packages")
Expand Down Expand Up @@ -364,7 +365,7 @@ function append_all_pkgs!(pkgs, ctx, mode)
return
end

function up(ctx::Context, pkgs::Vector{PackageSpec};
function _up(ctx::Context, pkgs::Vector{PackageSpec};
level::UpgradeLevel=UPLEVEL_MAJOR, mode::PackageMode=PKGMODE_PROJECT,
preserve::Union{Nothing,PreserveLevel}= isempty(pkgs) ? nothing : PRESERVE_ALL,
update_registry::Bool=true,
Expand Down Expand Up @@ -394,13 +395,13 @@ function up(ctx::Context, pkgs::Vector{PackageSpec};
return
end

resolve(; io::IO=stderr_f(), kwargs...) = resolve(Context(;io); kwargs...)
function resolve(ctx::Context; skip_writing_project::Bool=false, kwargs...)
up(ctx; level=UPLEVEL_FIXED, mode=PKGMODE_MANIFEST, update_registry=false, skip_writing_project, kwargs...)
resolve(; io::IO=stderr_f(), kwargs...) = _resolve(Context(;io); kwargs...)
function _resolve(ctx::Context; skip_writing_project::Bool=false, kwargs...)
_up(ctx; level=UPLEVEL_FIXED, mode=PKGMODE_MANIFEST, update_registry=false, skip_writing_project, kwargs...)
return nothing
end

function pin(ctx::Context, pkgs::Vector{PackageSpec}; all_pkgs::Bool=false, kwargs...)
function _pin(ctx::Context, pkgs::Vector{PackageSpec}; all_pkgs::Bool=false, kwargs...)
Context!(ctx; kwargs...)
if all_pkgs
!isempty(pkgs) && pkgerror("cannot specify packages when operating on all packages")
Expand Down Expand Up @@ -435,7 +436,7 @@ function pin(ctx::Context, pkgs::Vector{PackageSpec}; all_pkgs::Bool=false, kwar
return
end

function free(ctx::Context, pkgs::Vector{PackageSpec}; all_pkgs::Bool=false, kwargs...)
function _free(ctx::Context, pkgs::Vector{PackageSpec}; all_pkgs::Bool=false, kwargs...)
Context!(ctx; kwargs...)
if all_pkgs
!isempty(pkgs) && pkgerror("cannot specify packages when operating on all packages")
Expand All @@ -462,7 +463,7 @@ function free(ctx::Context, pkgs::Vector{PackageSpec}; all_pkgs::Bool=false, kwa
return
end

function test(ctx::Context, pkgs::Vector{PackageSpec};
function _test(ctx::Context, pkgs::Vector{PackageSpec};
coverage=false, test_fn=nothing,
julia_args::Union{Cmd, AbstractVector{<:AbstractString}}=``,
test_args::Union{Cmd, AbstractVector{<:AbstractString}}=``,
Expand Down Expand Up @@ -526,7 +527,11 @@ admin privileges depending on the setup).

Use verbose mode (`verbose=true`) for detailed output.
"""
function gc(ctx::Context=Context(); collect_delay::Period=Day(7), verbose=false, force=false, kwargs...)
function gc(; collect_delay::Period=Day(7), verbose=false, force=false, kwargs...)
ctx = Context()
return _gc(ctx; collect_delay, verbose, force, kwargs...)
end
function _gc(ctx::Context; collect_delay::Period=Day(7), verbose::Bool=false, force::Bool=false, kwargs...)
Context!(ctx; kwargs...)
env = ctx.env

Expand Down Expand Up @@ -1097,7 +1102,7 @@ function gc(ctx::Context=Context(); collect_delay::Period=Day(7), verbose=false,
return
end

function build(ctx::Context, pkgs::Vector{PackageSpec}; verbose=false, kwargs...)
function _build(ctx::Context, pkgs::Vector{PackageSpec}; verbose=false, kwargs...)
Context!(ctx; kwargs...)

if isempty(pkgs)
Expand Down Expand Up @@ -1134,13 +1139,13 @@ function get_or_make_pkgspec(pkgspecs::Vector{PackageSpec}, ctx::Context, uuid)
end
end

function precompile(ctx::Context, pkgs::Vector{PackageSpec}; internal_call::Bool=false,
function _precompile(ctx::Context, pkgs::Vector{PackageSpec}; internal_call::Bool=false,
strict::Bool=false, warn_loaded = true, already_instantiated = false, timing::Bool = false,
_from_loading::Bool=false, configs::Union{Base.Precompilation.Config,Vector{Base.Precompilation.Config}}=(``=>Base.CacheFlags()),
workspace::Bool=false, kwargs...)
Context!(ctx; kwargs...)
if !already_instantiated
instantiate(ctx; allow_autoprecomp=false, kwargs...)
_instantiate(ctx; allow_autoprecomp=false, kwargs...)
@debug "precompile: instantiated"
end

Expand Down Expand Up @@ -1173,8 +1178,8 @@ function tree_hash(repo::LibGit2.GitRepo, tree_hash::String)
return nothing
end

instantiate(; kwargs...) = instantiate(Context(); kwargs...)
function instantiate(ctx::Context; manifest::Union{Bool, Nothing}=nothing,
instantiate(; kwargs...) = _instantiate(Context(); kwargs...)
function _instantiate(ctx::Context; manifest::Union{Bool, Nothing}=nothing,
update_registry::Bool=true, verbose::Bool=false,
platform::AbstractPlatform=HostPlatform(), allow_build::Bool=true, allow_autoprecomp::Bool=true,
workspace::Bool=false, julia_version_strict::Bool=false, kwargs...)
Expand All @@ -1194,12 +1199,12 @@ function instantiate(ctx::Context; manifest::Union{Bool, Nothing}=nothing,
deps[pkg.name] = string(uuid)
end
Types.write_project(Dict("deps" => deps), ctx.env.project_file)
return instantiate(Context(); manifest=manifest, update_registry=update_registry, allow_autoprecomp=allow_autoprecomp, verbose=verbose, platform=platform, kwargs...)
return _instantiate(Context(); manifest=manifest, update_registry=update_registry, allow_autoprecomp=allow_autoprecomp, verbose=verbose, platform=platform, kwargs...)
end
if (!isfile(ctx.env.manifest_file) && manifest === nothing) || manifest == false
# given no manifest exists, only allow invoking a registry update if there are project deps
allow_registry_update = isfile(ctx.env.project_file) && !isempty(ctx.env.project.deps)
up(ctx; update_registry = update_registry && allow_registry_update)
_up(ctx; update_registry = update_registry && allow_registry_update)
allow_autoprecomp && Pkg._auto_precompile(ctx, already_instantiated = true)
return
end
Expand Down Expand Up @@ -1289,7 +1294,7 @@ end

@deprecate status(mode::PackageMode) status(mode=mode)

function status(ctx::Context, pkgs::Vector{PackageSpec}; diff::Bool=false, mode=PKGMODE_PROJECT, workspace::Bool=false, outdated::Bool=false, compat::Bool=false, extensions::Bool=false, io::IO=stdout_f())
function _status(ctx::Context, pkgs::Vector{PackageSpec}; diff::Bool=false, mode=PKGMODE_PROJECT, workspace::Bool=false, outdated::Bool=false, compat::Bool=false, extensions::Bool=false, io::IO=stdout_f())
if compat
diff && pkgerror("Compat status has no `diff` mode")
outdated && pkgerror("Compat status has no `outdated` mode")
Expand Down Expand Up @@ -1392,7 +1397,7 @@ function activate(f::Function, new_project::AbstractString)
end
end

function compat(ctx::Context, pkg::String, compat_str::Union{Nothing,String}; io = nothing, kwargs...)
function _compat(ctx::Context, pkg::String, compat_str::Union{Nothing,String}; io = nothing, kwargs...)
io = something(io, ctx.io)
pkg = pkg == "Julia" ? "julia" : pkg
isnothing(compat_str) || (compat_str = string(strip(compat_str, '"')))
Expand All @@ -1407,7 +1412,7 @@ function compat(ctx::Context, pkg::String, compat_str::Union{Nothing,String}; io
end
printpkgstyle(io, :Resolve, "checking for compliance with the new compat rules...")
try
resolve(ctx)
_resolve(ctx)
catch e
if e isa ResolverError || e isa ResolverTimeoutError
printpkgstyle(io, :Error, string(e.msg), color = Base.warn_color())
Expand All @@ -1422,14 +1427,14 @@ function compat(ctx::Context, pkg::String, compat_str::Union{Nothing,String}; io
end
end
compat(pkg::String; kwargs...) = compat(pkg, nothing; kwargs...)
compat(pkg::String, compat_str::Union{Nothing,String}; kwargs...) = compat(Context(), pkg, compat_str; kwargs...)
compat(;kwargs...) = compat(Context(); kwargs...)
compat(pkg::String, compat_str::Union{Nothing,String}; kwargs...) = _compat(Context(), pkg, compat_str; kwargs...)
compat(;kwargs...) = _compat(Context(); kwargs...)

#######
# why #
#######

function why(ctx::Context, pkgs::Vector{PackageSpec}; io::IO, workspace::Bool=false, kwargs...)
function _why(ctx::Context, pkgs::Vector{PackageSpec}; io::IO, workspace::Bool=false, kwargs...)
require_not_empty(pkgs, :why)

manifest_resolve!(ctx.env.manifest, pkgs)
Expand Down
4 changes: 2 additions & 2 deletions src/Apps/Apps.jl
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,9 @@ function _resolve(manifest::Manifest, pkgname=nothing)
end
if isempty(ctx.env.manifest)
ctx.env.manifest.deps[uuid] = pkg
Pkg.resolve(ctx)
Pkg.API._resolve(ctx)
else
Pkg.instantiate(ctx)
Pkg.API._instantiate(ctx)
end
end

Expand Down
10 changes: 5 additions & 5 deletions src/Operations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1262,7 +1262,7 @@ end

function build(ctx::Context, uuids::Set{UUID}, verbose::Bool)
if any_package_not_installed(ctx.env.manifest) || !isfile(ctx.env.manifest_file)
Pkg.instantiate(ctx, allow_build = false, allow_autoprecomp = false)
Pkg.API._instantiate(ctx, allow_build = false, allow_autoprecomp = false)
end
all_uuids = get_deps(ctx.env, uuids)
build_versions(ctx, all_uuids; verbose)
Expand Down Expand Up @@ -2145,14 +2145,14 @@ function sandbox(fn::Function, ctx::Context, target::PackageSpec,
end

try
Pkg.resolve(temp_ctx; io=devnull, skip_writing_project=true)
Pkg.API._resolve(temp_ctx; io=devnull, skip_writing_project=true)
@debug "Using _parent_ dep graph"
catch err# TODO
err isa Resolve.ResolverError || rethrow()
allow_reresolve || rethrow()
@debug err
printpkgstyle(ctx.io, :Test, "Could not use exact versions of packages in manifest. Re-resolving dependencies", color=Base.warn_color())
Pkg.update(temp_ctx; skip_writing_project=true, update_registry=false, io=ctx.io)
Pkg.API._up(temp_ctx; skip_writing_project=true, update_registry=false, io=ctx.io)
printpkgstyle(ctx.io, :Test, "Successfully re-resolved")
@debug "Using _clean_ dep graph"
end
Expand Down Expand Up @@ -2244,7 +2244,7 @@ function test(ctx::Context, pkgs::Vector{PackageSpec};
force_latest_compatible_version::Bool=false,
allow_earlier_backwards_compatible_versions::Bool=true,
allow_reresolve::Bool=true)
Pkg.instantiate(ctx; allow_autoprecomp = false) # do precomp later within sandbox
Pkg.API._instantiate(ctx; allow_autoprecomp = false) # do precomp later within sandbox

# load manifest data
for pkg in pkgs
Expand Down Expand Up @@ -2285,7 +2285,7 @@ function test(ctx::Context, pkgs::Vector{PackageSpec};
proj = Base.locate_project_file(abspath(testdir(source_path)))
env = EnvCache(proj)
# Instantiate test env
Pkg.instantiate(Context(env=env); allow_autoprecomp = false)
Pkg.API._instantiate(Context(env=env); allow_autoprecomp = false)
status(env, ctx.registries; mode=PKGMODE_COMBINED, io=ctx.io, ignore_indent = false, show_usagetips = false)
flags = gen_subprocess_flags(source_path; coverage, julia_args)

Expand Down
4 changes: 2 additions & 2 deletions src/Pkg.jl
Original file line number Diff line number Diff line change
Expand Up @@ -844,7 +844,7 @@ function _auto_gc(ctx::Types.Context; collect_delay::Period = Day(7))
if curr_time - DEPOT_ORPHANAGE_TIMESTAMPS[depots1()] > delay_secs
printpkgstyle(ctx.io, :Info, "We haven't cleaned this depot up for a bit, running Pkg.gc()...", color = Base.info_color())
try
Pkg.gc(ctx; collect_delay)
Pkg.API._gc(ctx; collect_delay)
DEPOT_ORPHANAGE_TIMESTAMPS[depots1()] = curr_time
catch ex
@error("GC failed", exception=ex)
Expand All @@ -859,7 +859,7 @@ end

function _auto_precompile(ctx::Types.Context, pkgs::Vector{PackageSpec}=PackageSpec[]; warn_loaded = true, already_instantiated = false)
if should_autoprecompile()
Pkg.precompile(ctx, pkgs; internal_call=true, warn_loaded = warn_loaded, already_instantiated = already_instantiated)
Pkg.API._precompile(ctx, pkgs; internal_call=true, warn_loaded = warn_loaded, already_instantiated = already_instantiated)
end
end

Expand Down
4 changes: 2 additions & 2 deletions test/historical_stdlib_version.jl
Original file line number Diff line number Diff line change
Expand Up @@ -320,12 +320,12 @@ isolate(loaded_depot=true) do
# specific version vs. compat spec
@testset for version in (v"3.24.3+0", "3.24.3")
dependencies = [PackageSpec(; name="CMake_jll", version = version)]
@testset "with context (using private Pkg.add method)" begin
@testset "with context (using private Pkg._add function)" begin
Pkg.activate(temp=true)
ctx = Pkg.Types.Context(; julia_version=nothing)
mydeps = deepcopy(dependencies)
foreach(Pkg.API.handle_package_input!, mydeps)
Pkg.add(ctx, mydeps; platform)
Pkg.API._add(ctx, mydeps; platform)
end
@testset "with julia_version" begin
Pkg.activate(temp=true)
Expand Down