Compare commits
3 Commits
1e39ac037b
...
0244858177
Author | SHA1 | Date |
---|---|---|
TEC | 0244858177 | |
TEC | 5492e6954a | |
TEC | 08f4b58c1a |
|
@ -23,10 +23,12 @@ KittyTerminalImages = "b7fa5abe-5c7d-46c6-a1ae-1026d0d509b9"
|
|||
Netpbm = "f09324ee-3d7c-5217-9330-fc30815ba969"
|
||||
OhMyREPL = "5fb14364-9ced-5910-84b2-373655c76a03"
|
||||
PNGFiles = "f57f5aa1-a3ce-4bc8-8ab9-96f992907883"
|
||||
Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"
|
||||
QOI = "4b34888f-f399-49d4-9bb3-47ed5cae4e65"
|
||||
TiffImages = "731e570b-9d59-4bfa-96dc-6df516fadf69"
|
||||
|
||||
[extensions]
|
||||
PkgExt = "Pkg"
|
||||
cairomakie = "CairoMakie"
|
||||
gadfly = "Gadfly"
|
||||
hdf5 = "HDF5"
|
||||
|
|
|
@ -1,8 +1,10 @@
|
|||
module PkgStack
|
||||
module PkgExt
|
||||
|
||||
import Pkg
|
||||
import Setup: lazypkg
|
||||
import Markdown: @md_str
|
||||
|
||||
const Pkg = lazypkg()
|
||||
|
||||
function stack(envs)
|
||||
if isempty(envs)
|
||||
printstyled(" The current stack:\n", bold=true)
|
43
src/Setup.jl
43
src/Setup.jl
|
@ -1,7 +1,6 @@
|
|||
module Setup
|
||||
|
||||
import REPL
|
||||
import Pkg
|
||||
|
||||
export about, @about
|
||||
|
||||
|
@ -18,7 +17,6 @@ include("install.jl")
|
|||
include("cmdpuns.jl")
|
||||
include("termsetup.jl")
|
||||
include("about.jl")
|
||||
include("pkgstack.jl")
|
||||
|
||||
include("autoloads.jl")
|
||||
using .Autoloads
|
||||
|
@ -27,12 +25,35 @@ include("autoload_data.jl")
|
|||
include("sessions.jl")
|
||||
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))
|
||||
Pkg = lazypkg()
|
||||
oldproj = Base.current_project()
|
||||
Pkg.activate()
|
||||
@info "Installing $pkg"
|
||||
Pkg.add(pkg)
|
||||
lazypkg().add(pkg)
|
||||
if isnothing(oldproj)
|
||||
Pkg.activate()
|
||||
else
|
||||
Pkg.activate(oldproj)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -44,16 +65,6 @@ function __init__()
|
|||
TERM[] = termcode()
|
||||
|
||||
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())
|
||||
end
|
||||
|
||||
|
@ -68,6 +79,7 @@ precompile(replsetup, ())
|
|||
precompile(_termcolors, ())
|
||||
precompile(termcolors, ())
|
||||
precompile(termtheme, ())
|
||||
precompile(__init__, ())
|
||||
|
||||
precompile(Autoloads.autoload_loadpkg, (Symbol,))
|
||||
precompile(Autoloads.autoload_scan!, (Expr,))
|
||||
|
@ -76,5 +88,6 @@ precompile(Autoloads.autoload_scan!, (Any,))
|
|||
precompile(Autoloads.read_named_envs!, ())
|
||||
precompile(Autoloads.repl_scan_autoloads!, (Expr,))
|
||||
precompile(Autoloads.repl_scan_autoloads!, (Nothing,))
|
||||
precompile(Autoloads.__init__, ())
|
||||
|
||||
end
|
||||
|
|
|
@ -162,7 +162,7 @@ function memorylayout(val::T) where {T}
|
|||
end
|
||||
|
||||
function about(fn::Function)
|
||||
source = Main.InteractiveUtils.which(Main, Symbol(fn))
|
||||
source = Main.InteractiveUtils.which(parentmodule(fn), Symbol(fn))
|
||||
methodmodules = getproperty.(methods(fn).ms, :module)
|
||||
others = setdiff(methodmodules, [source])
|
||||
print(Base.summary(fn))
|
||||
|
@ -238,7 +238,7 @@ macro about(obj::Symbol, types::Union{Symbol, Expr}...)
|
|||
types[1] == :(())
|
||||
:(about($obj, Tuple{}))
|
||||
elseif Core.eval(Main, obj) isa Function && length(types) > 0
|
||||
:(about($obj, $(Tuple{Core.eval.(Main, types)...})))
|
||||
:(about($obj, $(Tuple{Core.eval.(Ref(Main), types)...})))
|
||||
else
|
||||
:(about($obj))
|
||||
end |> esc
|
||||
|
@ -249,7 +249,7 @@ macro about(qobj::Union{QuoteNode, Expr}, types::Union{Symbol, Expr}...)
|
|||
types[1] == :(())
|
||||
:(about($(Core.eval(Main, qobj)), Tuple{}))
|
||||
elseif length(types) > 0
|
||||
:(about($(Core.eval(Main, qobj)), $(Tuple{Core.eval.(Main, types)...})))
|
||||
:(about($(Core.eval(Main, qobj)), $(Tuple{Core.eval.(Ref(Main), types)...})))
|
||||
else
|
||||
:(about($(Core.eval(Main, qobj))))
|
||||
end |> esc
|
||||
|
|
|
@ -6,17 +6,22 @@ const STARTUP_MANAGED_MESSAGE =
|
|||
const STARTUP_CONTENT = """
|
||||
$STARTUP_MANAGED_MESSAGE
|
||||
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
|
||||
let pkg_id = Base.PkgId(Base.UUID("44cfe95a-1eb2-52ea-b672-e2afdf69b78f"), "Pkg")
|
||||
Pkg = Base.loaded_modules[pkg_id]
|
||||
isnothing(Base.find_package("Setup")) &&
|
||||
Pkg.develop(path=joinpath(@__DIR__, "Setup"))
|
||||
try
|
||||
using Setup
|
||||
catch e
|
||||
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
|
||||
|
||||
using Setup
|
||||
|
||||
Setup.ensurepkg("Revise")
|
||||
Setup.ensureglobalpkg("Revise")
|
||||
@async @eval using Revise
|
||||
end
|
||||
"""
|
||||
|
|
|
@ -137,7 +137,7 @@ end
|
|||
|
||||
const ATTEMPTED_TERMIMAGE_LOAD = Ref(false)
|
||||
|
||||
function load_termimage_pkg()
|
||||
function load_termimage_pkg(autoinstall::Bool=true)
|
||||
ATTEMPTED_TERMIMAGE_LOAD[] && return
|
||||
pkg, pkgsetup = get(TERM_IMAGE_PACKAGES, Setup.TERM[], (nothing, nothing))
|
||||
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
|
||||
# that's just about to occur.
|
||||
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
|
||||
@info "Consider installing $(pkg.name) for better in-terminal image previews"
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue