Skip to content

Commit

Permalink
Use public API for Pkg stdlibs (#3098)
Browse files Browse the repository at this point in the history
* Use public API for Pkg stdlibs

* add a bunch of stdlib tests

* whatevs
  • Loading branch information
fonsp authored Feb 14, 2025
1 parent 3e8a4a0 commit 511320a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 16 deletions.
19 changes: 3 additions & 16 deletions src/packages/PkgCompat.jl
Original file line number Diff line number Diff line change
Expand Up @@ -260,22 +260,9 @@ end
# Standard Libraries
###

# (⚠️ Internal API with fallback)
_stdlibs() = try
stdlibs = values(Pkg.Types.stdlibs())
T = eltype(stdlibs)
if T == String
stdlibs
elseif T <: Tuple{String,Any}
first.(stdlibs)
else
error()
end
catch e
@warn "Pkg compat: failed to load standard libraries." exception=(e,catch_backtrace())

String["ArgTools", "Artifacts", "Base64", "CRC32c", "CompilerSupportLibraries_jll", "Dates", "DelimitedFiles", "Distributed", "Downloads", "FileWatching", "Future", "GMP_jll", "InteractiveUtils", "LLD_jll", "LLVMLibUnwind_jll", "LazyArtifacts", "LibCURL", "LibCURL_jll", "LibGit2", "LibGit2_jll", "LibOSXUnwind_jll", "LibSSH2_jll", "LibUV_jll", "LibUnwind_jll", "Libdl", "LinearAlgebra", "Logging", "MPFR_jll", "Markdown", "MbedTLS_jll", "Mmap", "MozillaCACerts_jll", "NetworkOptions", "OpenBLAS_jll", "OpenLibm_jll", "PCRE2_jll", "Pkg", "Printf", "Profile", "REPL", "Random", "SHA", "Serialization", "SharedArrays", "Sockets", "SparseArrays", "Statistics", "SuiteSparse", "SuiteSparse_jll", "TOML", "Tar", "Test", "UUIDs", "Unicode", "Zlib_jll", "dSFMT_jll", "libLLVM_jll", "libblastrampoline_jll", "nghttp2_jll", "p7zip_jll"]
end
# (✅ Public API)
_stdlibs_found = sort(readdir(Sys.STDLIB))
_stdlibs() = _stdlibs_found

# ⚠️ Internal API with fallback
is_stdlib(package_name::AbstractString) = package_name _stdlibs()
Expand Down
12 changes: 12 additions & 0 deletions test/packages/PkgCompat.jl
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,18 @@ import Pkg
@test PkgCompat.package_exists("Dates")

@test PkgCompat.is_stdlib("Dates")
@test PkgCompat.is_stdlib("Markdown")
@test PkgCompat.is_stdlib("Sockets")
@test PkgCompat.is_stdlib("MbedTLS_jll")
@test PkgCompat.is_stdlib("Test")
@test PkgCompat.is_stdlib("Pkg")
@test PkgCompat.is_stdlib("Random")
@test PkgCompat.is_stdlib("FileWatching")
@test PkgCompat.is_stdlib("Distributed")
# upgradable stdlibs:
@test PkgCompat.is_stdlib("Statistics")
@test PkgCompat.is_stdlib("DelimitedFiles")

@test !PkgCompat.is_stdlib("PlutoUI")


Expand Down

0 comments on commit 511320a

Please sign in to comment.