Skip to content

Commit

Permalink
lazily load Pkg (#4955)
Browse files Browse the repository at this point in the history
* lazily load Pkg

* compat fixes

* use 'pre' in CI

* please formatter

---------

Co-authored-by: Simon Christ <[email protected]>
  • Loading branch information
KristofferC and BeastyBlacksmith authored Jul 5, 2024
1 parent a03e19f commit c364ec8
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 22 deletions.
6 changes: 1 addition & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,7 @@ jobs:
- os: ubuntu-latest
experimental: true
prefix: xvfb-run
version: '~1.11.0-0' # upcoming julia version, next `rc`
- os: ubuntu-latest
experimental: true
prefix: xvfb-run
version: 'nightly'
version: 'pre' # upcoming julia version, next `rc`

steps:
- uses: actions/checkout@v4
Expand Down
1 change: 1 addition & 0 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ Showoff = "992d4aef-0814-514b-bc4d-f2e9a6c4116f"
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
StatsBase = "2913bbd2-ae8a-5f71-8c99-4fb6c76f3a91"
TOML = "fa267f1f-6049-4f14-aa54-33bafae1ed76"
UUIDs = "cf7118a7-6976-5b1a-9a39-7adc72f591a4"
UnicodeFun = "1cfade01-22cf-5700-b092-accc4b62d6e1"
UnitfulLatexify = "45397f5d-5981-4c77-b2b3-fc36d6e9b728"
Expand Down
2 changes: 1 addition & 1 deletion src/Plots.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ if isdefined(Base, :Experimental) && isdefined(Base.Experimental, Symbol("@max_m
@eval Base.Experimental.@max_methods 1
end

using Pkg, Dates, Printf, Statistics, Base64, LinearAlgebra, SparseArrays, Random
using Dates, Printf, Statistics, Base64, LinearAlgebra, SparseArrays, Random, TOML
using PrecompileTools, Reexport, RelocatableFolders
using Base.Meta
@reexport using RecipesBase
Expand Down
35 changes: 19 additions & 16 deletions src/backends.jl
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
struct NoBackend <: AbstractBackend end

const _plots_project = Pkg.Types.read_package(normpath(@__DIR__, "..", "Project.toml"))
const _current_plots_version = _plots_project.version
const _plots_compats = _plots_project.compat
lazyloadPkg() = Base.require(@__MODULE__, :Pkg)

const _current_plots_version = VersionNumber(TOML.parsefile(normpath(@__DIR__, "..", "Project.toml"))["version"])
const _plots_compats = TOML.parsefile(normpath(@__DIR__, "..", "Project.toml"))["compat"]

const _backendSymbol = Dict{DataType,Symbol}(NoBackend => :none)
const _backendType = Dict{Symbol,DataType}(:none => NoBackend)
const _backend_packages = Dict{Symbol,Symbol}()
const _initialized_backends = Set{Symbol}()
const _backends = Symbol[]

const _plots_deps = let toml = Pkg.TOML.parsefile(normpath(@__DIR__, "..", "Project.toml"))
const _plots_deps = let toml = TOML.parsefile(normpath(@__DIR__, "..", "Project.toml"))
merge(toml["deps"], toml["extras"])
end

Expand Down Expand Up @@ -38,22 +39,20 @@ function _check_installed(backend::Union{Module,AbstractString,Symbol}; warn = t
version = if pkg_id === nothing
nothing
else
get(Pkg.dependencies(), pkg_id.uuid, (; version = nothing)).version
pkg = lazyloadPkg()
get(Base.invokelatest(pkg.dependencies), pkg_id.uuid, (; version = nothing)).version
end
version === nothing && @warn "backend `$str` is not installed."
version
end

function _check_compat(m::Module; warn = true)
(be_v = _check_installed(m; warn)) === nothing && return
if (be_c = _plots_compats[string(m)]) isa String # julia 1.6
if be_v Pkg.Types.semver_spec(be_c)
@warn "`$m` $be_v is not compatible with this version of `Plots`. The declared compatibility is $(be_c)."
end
else
if intersect(be_v, be_c.val) |> isempty
@warn "`$m` $be_v is not compatible with this version of `Plots`. The declared compatibility is $(be_c.str)."
end
be_c = _plots_compats[string(m)]
pkg = lazyloadPkg()
semver = Base.invokelatest(pkg.Types.semver_spec, be_c)
if Base.invokelatest(, be_v, semver)
@warn "`$m` $be_v is not compatible with this version of `Plots`. The declared compatibility is $(be_c)."
end
nothing
end
Expand Down Expand Up @@ -214,9 +213,11 @@ function diagnostics(io::IO = stdout)
else
be_name = string(backend_package_name(be))
@info "selected `Plots` backend: $be_name, from $origin"
Pkg.status(
pkg = lazyloadPkg()
Base.invokelatest(
pkg.status,
["Plots", "RecipesBase", "RecipesPipeline", be_name];
mode = Pkg.PKGMODE_MANIFEST,
mode = pkg.PKGMODE_MANIFEST,
io,
)
end
Expand Down Expand Up @@ -379,7 +380,9 @@ function _initialize_backend(pkg::AbstractBackend)
@eval name === :GR ? Plots : Main begin
import $name
export $name
$(_check_compat)($name)
if $(QuoteNode(name)) !== :GR
$(_check_compat)($name)
end
end
_post_imports(pkg)
_runtime_init(pkg)
Expand Down

2 comments on commit c364ec8

@BeastyBlacksmith
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/110501

Tip: Release Notes

Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.

@JuliaRegistrator register

Release notes:

## Breaking changes

- blah

To add them here just re-invoke and the PR will be updated.

Tagging

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v1.40.5 -m "<description of version>" c364ec8183569b4ce366d9143fbb3f9175c58225
git push origin v1.40.5

Please sign in to comment.