repl.jl
1 using Pkg: Pkg as Pkg 2 3 macro in_repl() 4 quote 5 @eval begin 6 Misc.clearpypath!() 7 sst = StrategyStats 8 using Plotting: plotone, @plotone 9 using Misc: config, @margin!, @margin!! 10 end 11 exc = setexchange!(:kucoin) 12 end 13 end 14 15 function analyze!() 16 @eval using StrategyStats, Plotting 17 end 18 19 function user!() 20 @eval include(joinpath(@__DIR__, "user.jl")) 21 @eval using Misc: config 22 @eval export results, exc, config 23 @eval sst = StrategyStats 24 nothing 25 end 26 27 @doc """ Binds a module to a symbol in the Main namespace. 28 29 $(TYPEDSIGNATURES) 30 31 This function attempts to bind a module to a symbol in the Main namespace. 32 If the module is not already defined, it tries to activate the module's project and import it. 33 """ 34 function module!(sym, bind) 35 if !isdefined(Main, bind) 36 projpath = dirname(dirname(pathof(Planar))) 37 modpath = joinpath(projpath, string(sym, ".jl")) 38 try 39 @eval Main using $sym: $sym as $bind 40 catch e 41 Base.showerror(stdout, e) 42 prev = Pkg.project().path 43 Pkg.activate(modpath) 44 try 45 @eval Main using $sym: $sym as $bind 46 finally 47 Pkg.activate(prev) 48 end 49 end 50 end 51 @info "`$sym` module bound to `$bind`" 52 end 53 54 # NOTE: required to register extensions hooks 55 @doc """ Activates and imports a given module. 56 57 $(TYPEDSIGNATURES) 58 59 This function activates the project of a given module and imports it. 60 It binds the module to a symbol in the Main namespace. 61 If the module is not already defined, it tries to activate the module's project and import it. 62 """ 63 function _activate_and_import(name, bind) 64 proj_name = string(name) 65 @assert isfile(joinpath(proj_name, "Project.toml")) 66 prev = Base.active_project() 67 Pkg.activate(proj_name, io=devnull) 68 try 69 module!(Symbol(name), Symbol(bind)) 70 finally 71 Pkg.activate(prev, io=devnull) 72 end 73 end 74 75 @doc """ Activates and imports the `Plotting` module. """ 76 plots!() = _activate_and_import(:Plotting, :plo) 77 @doc """ Imports the `Metrics` module. """ 78 metrics!() = module!(:Metrics, :ss) 79 @doc """ Imports the `Engine` module. """ 80 engine!() = module!(:Engine, :egn) 81 @doc """ Imports the `StrategyStats` module. """ 82 analysis!() = module!(:StrategyStats, :sst) 83 @doc """ Imports the `Stubs` module. """ 84 stubs!() = module!(:Stubs, :stubs) 85 @doc """ Activates and Imports the `Opt` module. """ 86 optim!() = _activate_and_import(:Opt, :opt) 87 @doc """ Activates and Imports the `PlanarInteractive` module. """ 88 interactive!() = _activate_and_import(:PlanarInteractive, :plni) 89 @doc """ Activates and Imports the `Scrapers` module. """ 90 scrape!() = _activate_and_import(:Scrapers, :scr) 91 feats!() = _activate_and_import(:FeatureSelection, :feats) 92 93 export plots!, optim!, metrics!, engine!, analysis!, interactive!, scrape!, feats!