Compare commits

...

4 Commits

Author SHA1 Message Date
TEC 1e39ac037b
Precompile __init__ too 2024-01-27 03:00:52 +08:00
TEC da8ff454b8
Fix some about fn bugs 2024-01-27 03:00:49 +08:00
TEC ceed7facc1
Refine pkg setup, make work with 1.10 and 1.11 2024-01-27 03:00:49 +08:00
TEC 6a72ab6d45
Adapt to updated makie version 2024-01-27 02:58:40 +08:00
6 changed files with 58 additions and 29 deletions

View File

@ -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"

View File

@ -2,7 +2,6 @@ module cairomakie
using Setup
using CairoMakie
import Pkg
import Setup.theme_term
@ -50,7 +49,7 @@ function theme_term()
palette = merge(Attributes(
color = onecolors(1.0),
patchcolor = onecolors(0.8)
), CairoMakie.Makie.default_palettes),
), CairoMakie.Makie.DEFAULT_PALETTES),
Axis = (
backgroundcolor = :transparent,
bottomspinecolor = fg,

View File

@ -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

View File

@ -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

View File

@ -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
"""

View File

@ -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