Skip to content

Commit

Permalink
Introduce stdlib_infos() instead of changing stdlibs()
Browse files Browse the repository at this point in the history
  • Loading branch information
staticfloat committed Jun 17, 2024
1 parent be5eb99 commit 62f8d8e
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
2 changes: 1 addition & 1 deletion ext/REPLExt/completions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ function complete_add_dev(options, partial, i1, i2)
end
comps = vcat(comps, sort(complete_remote_package(partial)))
if !isempty(partial)
append!(comps, filter!(startswith(partial), [info.name for info in values(Types.stdlibs())]))
append!(comps, filter!(startswith(partial), [info.name for info in values(Types.stdlib_infos())]))
end
return comps, idx, !isempty(comps)
end
Expand Down
4 changes: 2 additions & 2 deletions src/Operations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,7 @@ function resolve_versions!(env::EnvCache, registries::Vector{Registry.RegistryIn
end
end

names = Dict{UUID, String}(uuid => info.name for (uuid, info) in stdlibs())
names = Dict{UUID, String}(uuid => info.name for (uuid, info) in stdlib_infos())
# recursive search for packages which are tracking a path
developed = collect_developed(env, pkgs)
# But we only want to use information for those packages that we don't know about
Expand Down Expand Up @@ -514,7 +514,7 @@ function resolve_versions!(env::EnvCache, registries::Vector{Registry.RegistryIn
# Fixed packages are not returned by resolve (they already have their version set)
pkg.version = vers[pkg.uuid]
else
name = is_stdlib(uuid) ? stdlibs()[uuid].name : registered_name(registries, uuid)
name = is_stdlib(uuid) ? stdlib_infos()[uuid].name : registered_name(registries, uuid)
push!(pkgs, PackageSpec(;name=name, uuid=uuid, version=ver))
end
end
Expand Down
16 changes: 11 additions & 5 deletions src/Types.jl
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ using SHA
export UUID, SHA1, VersionRange, VersionSpec,
PackageSpec, PackageEntry, EnvCache, Context, GitRepo, Context!, Manifest, Project, err_rep,
PkgError, pkgerror,
has_name, has_uuid, is_stdlib, is_or_was_stdlib, stdlib_version, is_unregistered_stdlib, stdlibs, write_env, write_env_usage, parse_toml,
has_name, has_uuid, is_stdlib, is_or_was_stdlib, stdlib_version, is_unregistered_stdlib, stdlibs, stdlib_infos, write_env, write_env_usage, parse_toml,
project_resolve!, project_deps_resolve!, manifest_resolve!, registry_resolve!, stdlib_resolve!, handle_repos_develop!, handle_repos_add!, ensure_resolved,
registered_name,
manifest_info,
Expand Down Expand Up @@ -479,12 +479,18 @@ function load_stdlib()
end

function stdlibs()
# This maintains a compatible format for `stdlibs()`, but new code should always
# prefer `stdlib_infos` as it is more future-proofed, by returning a structure
# rather than a tuple of elements.
return Dict(uuid => (info.name, info.version) for (uuid, info) in stdlib_infos())
end
function stdlib_infos()
if !isassigned(STDLIB)
STDLIB[] = load_stdlib()
end
return STDLIB[]
end
is_stdlib(uuid::UUID) = uuid in keys(stdlibs())
is_stdlib(uuid::UUID) = uuid in keys(stdlib_infos())
# Includes former stdlibs
function is_or_was_stdlib(uuid::UUID, julia_version::Union{VersionNumber, Nothing})
return is_stdlib(uuid, julia_version) || uuid in FORMER_STDLIBS_UUIDS
Expand All @@ -502,7 +508,7 @@ end
# If we can't find one, defaults to `UNREGISTERED_STDLIBS`
function get_last_stdlibs(julia_version::VersionNumber; use_historical_for_current_version = false)
if !use_historical_for_current_version && julia_version == VERSION
return stdlibs()
return stdlib_infos()
end
historical_stdlibs_check()
last_stdlibs = UNREGISTERED_STDLIBS
Expand Down Expand Up @@ -1040,14 +1046,14 @@ function stdlib_resolve!(pkgs::AbstractVector{PackageSpec})
for pkg in pkgs
@assert has_name(pkg) || has_uuid(pkg)
if has_name(pkg) && !has_uuid(pkg)
for (uuid, info) in stdlibs()
for (uuid, info) in stdlib_infos()
if info.name == pkg.name
pkg.uuid = uuid
end
end
end
if !has_name(pkg) && has_uuid(pkg)
info = get(stdlibs(), pkg.uuid, nothing)
info = get(stdlib_infos(), pkg.uuid, nothing)
if info !== nothing
pkg.name = info.name
end
Expand Down

0 comments on commit 62f8d8e

Please sign in to comment.