Skip to content

Commit c364ec8

Browse files
lazily load Pkg (#4955)
* lazily load Pkg * compat fixes * use 'pre' in CI * please formatter --------- Co-authored-by: Simon Christ <SimonChrist@gmx.de>
1 parent a03e19f commit c364ec8

File tree

4 files changed

+22
-22
lines changed

4 files changed

+22
-22
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,7 @@ jobs:
5353
- os: ubuntu-latest
5454
experimental: true
5555
prefix: xvfb-run
56-
version: '~1.11.0-0' # upcoming julia version, next `rc`
57-
- os: ubuntu-latest
58-
experimental: true
59-
prefix: xvfb-run
60-
version: 'nightly'
56+
version: 'pre' # upcoming julia version, next `rc`
6157

6258
steps:
6359
- uses: actions/checkout@v4

Project.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ Showoff = "992d4aef-0814-514b-bc4d-f2e9a6c4116f"
3535
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
3636
Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
3737
StatsBase = "2913bbd2-ae8a-5f71-8c99-4fb6c76f3a91"
38+
TOML = "fa267f1f-6049-4f14-aa54-33bafae1ed76"
3839
UUIDs = "cf7118a7-6976-5b1a-9a39-7adc72f591a4"
3940
UnicodeFun = "1cfade01-22cf-5700-b092-accc4b62d6e1"
4041
UnitfulLatexify = "45397f5d-5981-4c77-b2b3-fc36d6e9b728"

src/Plots.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ if isdefined(Base, :Experimental) && isdefined(Base.Experimental, Symbol("@max_m
77
@eval Base.Experimental.@max_methods 1
88
end
99

10-
using Pkg, Dates, Printf, Statistics, Base64, LinearAlgebra, SparseArrays, Random
10+
using Dates, Printf, Statistics, Base64, LinearAlgebra, SparseArrays, Random, TOML
1111
using PrecompileTools, Reexport, RelocatableFolders
1212
using Base.Meta
1313
@reexport using RecipesBase

src/backends.jl

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
struct NoBackend <: AbstractBackend end
22

3-
const _plots_project = Pkg.Types.read_package(normpath(@__DIR__, "..", "Project.toml"))
4-
const _current_plots_version = _plots_project.version
5-
const _plots_compats = _plots_project.compat
3+
lazyloadPkg() = Base.require(@__MODULE__, :Pkg)
4+
5+
const _current_plots_version = VersionNumber(TOML.parsefile(normpath(@__DIR__, "..", "Project.toml"))["version"])
6+
const _plots_compats = TOML.parsefile(normpath(@__DIR__, "..", "Project.toml"))["compat"]
67

78
const _backendSymbol = Dict{DataType,Symbol}(NoBackend => :none)
89
const _backendType = Dict{Symbol,DataType}(:none => NoBackend)
910
const _backend_packages = Dict{Symbol,Symbol}()
1011
const _initialized_backends = Set{Symbol}()
1112
const _backends = Symbol[]
1213

13-
const _plots_deps = let toml = Pkg.TOML.parsefile(normpath(@__DIR__, "..", "Project.toml"))
14+
const _plots_deps = let toml = TOML.parsefile(normpath(@__DIR__, "..", "Project.toml"))
1415
merge(toml["deps"], toml["extras"])
1516
end
1617

@@ -38,22 +39,20 @@ function _check_installed(backend::Union{Module,AbstractString,Symbol}; warn = t
3839
version = if pkg_id === nothing
3940
nothing
4041
else
41-
get(Pkg.dependencies(), pkg_id.uuid, (; version = nothing)).version
42+
pkg = lazyloadPkg()
43+
get(Base.invokelatest(pkg.dependencies), pkg_id.uuid, (; version = nothing)).version
4244
end
4345
version === nothing && @warn "backend `$str` is not installed."
4446
version
4547
end
4648

4749
function _check_compat(m::Module; warn = true)
4850
(be_v = _check_installed(m; warn)) === nothing && return
49-
if (be_c = _plots_compats[string(m)]) isa String # julia 1.6
50-
if be_v Pkg.Types.semver_spec(be_c)
51-
@warn "`$m` $be_v is not compatible with this version of `Plots`. The declared compatibility is $(be_c)."
52-
end
53-
else
54-
if intersect(be_v, be_c.val) |> isempty
55-
@warn "`$m` $be_v is not compatible with this version of `Plots`. The declared compatibility is $(be_c.str)."
56-
end
51+
be_c = _plots_compats[string(m)]
52+
pkg = lazyloadPkg()
53+
semver = Base.invokelatest(pkg.Types.semver_spec, be_c)
54+
if Base.invokelatest(, be_v, semver)
55+
@warn "`$m` $be_v is not compatible with this version of `Plots`. The declared compatibility is $(be_c)."
5756
end
5857
nothing
5958
end
@@ -214,9 +213,11 @@ function diagnostics(io::IO = stdout)
214213
else
215214
be_name = string(backend_package_name(be))
216215
@info "selected `Plots` backend: $be_name, from $origin"
217-
Pkg.status(
216+
pkg = lazyloadPkg()
217+
Base.invokelatest(
218+
pkg.status,
218219
["Plots", "RecipesBase", "RecipesPipeline", be_name];
219-
mode = Pkg.PKGMODE_MANIFEST,
220+
mode = pkg.PKGMODE_MANIFEST,
220221
io,
221222
)
222223
end
@@ -379,7 +380,9 @@ function _initialize_backend(pkg::AbstractBackend)
379380
@eval name === :GR ? Plots : Main begin
380381
import $name
381382
export $name
382-
$(_check_compat)($name)
383+
if $(QuoteNode(name)) !== :GR
384+
$(_check_compat)($name)
385+
end
383386
end
384387
_post_imports(pkg)
385388
_runtime_init(pkg)

0 commit comments

Comments
 (0)