Refine pkg setup, make work with 1.10 and 1.11
This commit is contained in:
parent
6a72ab6d45
commit
08f4b58c1a
|
@ -23,10 +23,12 @@ KittyTerminalImages = "b7fa5abe-5c7d-46c6-a1ae-1026d0d509b9"
|
||||||
Netpbm = "f09324ee-3d7c-5217-9330-fc30815ba969"
|
Netpbm = "f09324ee-3d7c-5217-9330-fc30815ba969"
|
||||||
OhMyREPL = "5fb14364-9ced-5910-84b2-373655c76a03"
|
OhMyREPL = "5fb14364-9ced-5910-84b2-373655c76a03"
|
||||||
PNGFiles = "f57f5aa1-a3ce-4bc8-8ab9-96f992907883"
|
PNGFiles = "f57f5aa1-a3ce-4bc8-8ab9-96f992907883"
|
||||||
|
Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"
|
||||||
QOI = "4b34888f-f399-49d4-9bb3-47ed5cae4e65"
|
QOI = "4b34888f-f399-49d4-9bb3-47ed5cae4e65"
|
||||||
TiffImages = "731e570b-9d59-4bfa-96dc-6df516fadf69"
|
TiffImages = "731e570b-9d59-4bfa-96dc-6df516fadf69"
|
||||||
|
|
||||||
[extensions]
|
[extensions]
|
||||||
|
PkgExt = "Pkg"
|
||||||
cairomakie = "CairoMakie"
|
cairomakie = "CairoMakie"
|
||||||
gadfly = "Gadfly"
|
gadfly = "Gadfly"
|
||||||
hdf5 = "HDF5"
|
hdf5 = "HDF5"
|
||||||
|
|
|
@ -1,8 +1,10 @@
|
||||||
module PkgStack
|
module PkgExt
|
||||||
|
|
||||||
import Pkg
|
import Setup: lazypkg
|
||||||
import Markdown: @md_str
|
import Markdown: @md_str
|
||||||
|
|
||||||
|
const Pkg = lazypkg()
|
||||||
|
|
||||||
function stack(envs)
|
function stack(envs)
|
||||||
if isempty(envs)
|
if isempty(envs)
|
||||||
printstyled(" The current stack:\n", bold=true)
|
printstyled(" The current stack:\n", bold=true)
|
41
src/Setup.jl
41
src/Setup.jl
|
@ -1,7 +1,6 @@
|
||||||
module Setup
|
module Setup
|
||||||
|
|
||||||
import REPL
|
import REPL
|
||||||
import Pkg
|
|
||||||
|
|
||||||
export about, @about
|
export about, @about
|
||||||
|
|
||||||
|
@ -18,7 +17,6 @@ include("install.jl")
|
||||||
include("cmdpuns.jl")
|
include("cmdpuns.jl")
|
||||||
include("termsetup.jl")
|
include("termsetup.jl")
|
||||||
include("about.jl")
|
include("about.jl")
|
||||||
include("pkgstack.jl")
|
|
||||||
|
|
||||||
include("autoloads.jl")
|
include("autoloads.jl")
|
||||||
using .Autoloads
|
using .Autoloads
|
||||||
|
@ -27,12 +25,35 @@ include("autoload_data.jl")
|
||||||
include("sessions.jl")
|
include("sessions.jl")
|
||||||
using .Sessions
|
using .Sessions
|
||||||
|
|
||||||
using .PkgStack
|
@static if VERSION <= v"1.10"
|
||||||
|
const Pkg = let pkg_id = Base.PkgId(Base.UUID("44cfe95a-1eb2-52ea-b672-e2afdf69b78f"), "Pkg")
|
||||||
|
@something(get(Base.loaded_modules, pkg_id, nothing),
|
||||||
|
Base.require(pkg_id))
|
||||||
|
end
|
||||||
|
lazypkg() = Pkg
|
||||||
|
|
||||||
function ensurepkg(pkg::String)
|
include("../ext/PkgExt.jl")
|
||||||
|
using .PkgExt
|
||||||
|
else
|
||||||
|
function lazypkg()
|
||||||
|
pkg_id = Base.PkgId(Base.UUID("44cfe95a-1eb2-52ea-b672-e2afdf69b78f"), "Pkg")
|
||||||
|
@something(get(Base.loaded_modules, pkg_id, nothing),
|
||||||
|
Base.require(pkg_id))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function ensureglobalpkg(pkg::String)
|
||||||
if isnothing(Base.find_package(pkg))
|
if isnothing(Base.find_package(pkg))
|
||||||
|
Pkg = lazypkg()
|
||||||
|
oldproj = Base.current_project()
|
||||||
|
Pkg.activate()
|
||||||
@info "Installing $pkg"
|
@info "Installing $pkg"
|
||||||
Pkg.add(pkg)
|
lazypkg().add(pkg)
|
||||||
|
if isnothing(oldproj)
|
||||||
|
Pkg.activate()
|
||||||
|
else
|
||||||
|
Pkg.activate(oldproj)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -44,16 +65,6 @@ function __init__()
|
||||||
TERM[] = termcode()
|
TERM[] = termcode()
|
||||||
|
|
||||||
Main.Threads.@spawn if TERM[] == "xterm-kitty"
|
Main.Threads.@spawn if TERM[] == "xterm-kitty"
|
||||||
if isnothing(Base.find_package("KittyTerminalImages"))
|
|
||||||
@info "Installing KittyTerminalImages"
|
|
||||||
currentproj = Pkg.project().path
|
|
||||||
try
|
|
||||||
Pkg.activate()
|
|
||||||
# Pkg.add("KittyTerminalImages")
|
|
||||||
finally
|
|
||||||
Pkg.activate(currentproj)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
termtitle(pwd())
|
termtitle(pwd())
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -6,17 +6,22 @@ const STARTUP_MANAGED_MESSAGE =
|
||||||
const STARTUP_CONTENT = """
|
const STARTUP_CONTENT = """
|
||||||
$STARTUP_MANAGED_MESSAGE
|
$STARTUP_MANAGED_MESSAGE
|
||||||
if VERSION < v"1.7"
|
if VERSION < v"1.7"
|
||||||
@warn "Setup disabled as Julia \$VERSION < 1.7 is unsupported"
|
@warn "Setup disabled as Julia $VERSION < 1.7 is unsupported"
|
||||||
else
|
else
|
||||||
let pkg_id = Base.PkgId(Base.UUID("44cfe95a-1eb2-52ea-b672-e2afdf69b78f"), "Pkg")
|
try
|
||||||
Pkg = Base.loaded_modules[pkg_id]
|
using Setup
|
||||||
isnothing(Base.find_package("Setup")) &&
|
catch e
|
||||||
Pkg.develop(path=joinpath(@__DIR__, "Setup"))
|
if e isa ArgumentError && isnothing(Base.find_package("Setup")) # Package not found in current path
|
||||||
|
let pkg_id = Base.PkgId(Base.UUID("44cfe95a-1eb2-52ea-b672-e2afdf69b78f"), "Pkg")
|
||||||
|
Base.require(pkg_id).develop(path=joinpath(@__DIR__, "Setup"))
|
||||||
|
end
|
||||||
|
using Setup
|
||||||
|
else
|
||||||
|
rethrow()
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
using Setup
|
Setup.ensureglobalpkg("Revise")
|
||||||
|
|
||||||
Setup.ensurepkg("Revise")
|
|
||||||
@async @eval using Revise
|
@async @eval using Revise
|
||||||
end
|
end
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -137,7 +137,7 @@ end
|
||||||
|
|
||||||
const ATTEMPTED_TERMIMAGE_LOAD = Ref(false)
|
const ATTEMPTED_TERMIMAGE_LOAD = Ref(false)
|
||||||
|
|
||||||
function load_termimage_pkg()
|
function load_termimage_pkg(autoinstall::Bool=true)
|
||||||
ATTEMPTED_TERMIMAGE_LOAD[] && return
|
ATTEMPTED_TERMIMAGE_LOAD[] && return
|
||||||
pkg, pkgsetup = get(TERM_IMAGE_PACKAGES, Setup.TERM[], (nothing, nothing))
|
pkg, pkgsetup = get(TERM_IMAGE_PACKAGES, Setup.TERM[], (nothing, nothing))
|
||||||
if !isnothing(pkg) && !haskey(Base.loaded_modules, pkg)
|
if !isnothing(pkg) && !haskey(Base.loaded_modules, pkg)
|
||||||
|
@ -146,6 +146,16 @@ function load_termimage_pkg()
|
||||||
# Don't to this async because it may affect a `display` call
|
# Don't to this async because it may affect a `display` call
|
||||||
# that's just about to occur.
|
# that's just about to occur.
|
||||||
Core.eval(Main, :(import $(Symbol(pkg.name)); $pkgsetup))
|
Core.eval(Main, :(import $(Symbol(pkg.name)); $pkgsetup))
|
||||||
|
elseif autoinstall
|
||||||
|
Pkg = lazypkg()
|
||||||
|
currentproj = Pkg.project().path
|
||||||
|
try
|
||||||
|
Pkg.activate()
|
||||||
|
Pkg.add(pkg.name)
|
||||||
|
load_termimage_pkg(false)
|
||||||
|
finally
|
||||||
|
Pkg.activate(currentproj)
|
||||||
|
end
|
||||||
else
|
else
|
||||||
@info "Consider installing $(pkg.name) for better in-terminal image previews"
|
@info "Consider installing $(pkg.name) for better in-terminal image previews"
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue