Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove includet #717

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/Configuration.jl
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@ Base.@kwdef mutable struct Settings
path_db::String = "db"
path_bin::String = "bin"
path_src::String = "src"
path_elements_html::String = "elements" # the folder where the HTML elements are stored

webchannels_default_route::String = "____"
webchannels_js_file::String = "channels.js"
Expand Down Expand Up @@ -280,7 +281,7 @@ Base.@kwdef mutable struct Settings
format_julia_builds::Bool = false
format_html_output::Bool = true
format_html_indentation_string::String = " "

autoload::Vector{Symbol} = Symbol[:initializers, :helpers, :libs, :resources, :plugins, :routes, :app]
autoload_file::String = ".autoload"
autoload_ignore_file::String = ".autoload_ignore"
Expand Down
4 changes: 3 additions & 1 deletion src/Genie.jl
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,9 @@ function loadapp( path::String = ".";
path = normpath(path) |> abspath

if isfile(joinpath(path, Genie.BOOTSTRAP_FILE_NAME))
Revise.includet(context, joinpath(path, Genie.BOOTSTRAP_FILE_NAME))
# Revise.includet(context, joinpath(path, Genie.BOOTSTRAP_FILE_NAME))
Base.include(context, joinpath(path, Genie.BOOTSTRAP_FILE_NAME))
Genie.Configuration.isdev() && Revise.track(context, joinpath(path, Genie.BOOTSTRAP_FILE_NAME))
Genie.config.watch && @async Genie.Watch.watch(path)
autostart && (Core.eval(context, :(up())))
elseif isfile(joinpath(path, Genie.ROUTES_FILE_NAME)) || isfile(joinpath(path, Genie.APP_FILE_NAME))
Expand Down
65 changes: 51 additions & 14 deletions src/Loader.jl
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,14 @@ function bootstrap(context::Union{Module,Nothing} = default_context(context); sh
ENV["GENIE_ENV"] = Genie.config.app_env = "dev"
end

isfile(joinpath(Genie.config.path_env, GLOBAL_ENV_FILE_NAME)) && Base.include(context, joinpath(Genie.config.path_env, GLOBAL_ENV_FILE_NAME))
isfile(joinpath(Genie.config.path_env, ENV["GENIE_ENV"] * ".jl")) && Base.include(context, joinpath(Genie.config.path_env, ENV["GENIE_ENV"] * ".jl"))
isfile(abspath(Genie.config.path_env, GLOBAL_ENV_FILE_NAME)) && begin
Base.include(context, abspath(Genie.config.path_env, GLOBAL_ENV_FILE_NAME))
Genie.Configuration.isdev() && Revise.track(context, abspath(Genie.config.path_env, GLOBAL_ENV_FILE_NAME))
end
isfile(abspath(Genie.config.path_env, ENV["GENIE_ENV"] * ".jl")) && begin
Base.include(context, abspath(Genie.config.path_env, ENV["GENIE_ENV"] * ".jl"))
Genie.Configuration.isdev() && Revise.track(context, abspath(Genie.config.path_env, ENV["GENIE_ENV"] * ".jl"))
end
Genie.config.app_env = ENV["GENIE_ENV"] # ENV might have changed
importenv()

Expand Down Expand Up @@ -192,7 +198,9 @@ end
Loads the routes file.
"""
function load_routes(routes_file::String = Genie.ROUTES_FILE_NAME; context::Union{Module,Nothing} = nothing) :: Nothing
isfile(routes_file) && Revise.includet(default_context(context), routes_file)
# isfile(routes_file) && Revise.includet(default_context(context), routes_file)
println("routes_file: ", routes_file)
isfile(routes_file) && autoload(routes_file; context)

nothing
end
Expand All @@ -204,7 +212,8 @@ end
Loads the app file (`app.jl` can be used for single file apps, instead of `routes.jl`).
"""
function load_app(app_file::String = Genie.APP_FILE_NAME; context::Union{Module,Nothing} = nothing) :: Nothing
isfile(app_file) && Revise.includet(default_context(context), abspath(app_file))
# isfile(app_file) && Revise.includet(default_context(context), abspath(app_file))
isfile(app_file) && autoload(abspath(app_file); context)

nothing
end
Expand All @@ -215,6 +224,18 @@ end

Automatically and recursively includes files from the indicated `root_dir` into the indicated `context` module,
skipping directories from `dir`.
```julia
example
Genie.Loader.autoload(abspath("models"))
```

Or includes explicitly a file into the indicated `context` module.
```julia
example
Genie.Loader.autoload(abspath("models", "example.jl"))
```


The files are set up with `Revise` to be automatically reloaded when changed (in dev environment).
"""
function autoload(root_dir::String = Genie.config.path_lib;
Expand All @@ -224,23 +245,37 @@ function autoload(root_dir::String = Genie.config.path_lib;
skipmatch::Union{Regex,Nothing} = nothing,
autoload_ignore_file::String = Genie.config.autoload_ignore_file,
autoload_file::String = Genie.config.autoload_file) :: Nothing
isdir(root_dir) || return nothing

validinclude(fi)::Bool = endswith(fi, ".jl") && match(namematch, fi) !== nothing &&
((skipmatch !== nothing && match(skipmatch, fi) === nothing) || skipmatch === nothing)

for i in sort_load_order(root_dir, readdir(root_dir))
(isfile(joinpath(root_dir, autoload_ignore_file)) || i == autoload_file ) && continue
# check if root_dir is a .jl file and includet it
if isfile(abspath(root_dir))
validinclude(abspath(root_dir)) || return nothing
@debug "Auto loading file: $abspath(root_dir)"
# Revise.includet(default_context(context), root_dir)
Base.include(default_context(context), abspath(root_dir))
Genie.Configuration.isdev() && Revise.track(default_context(context), abspath(root_dir))
println("loaded: ", abspath(root_dir), " in ", default_context(context))
return nothing
end

isdir(abspath(root_dir)) || return nothing

for i in sort_load_order(abspath(root_dir), readdir(root_dir))
(isfile(joinpath(abspath(root_dir), autoload_ignore_file)) || i == autoload_file ) && continue

fi = joinpath(root_dir, i)
fi = joinpath(abspath(root_dir), i)
@debug "Checking $fi"
if validinclude(fi)
if validinclude(abspath(fi))
@debug "Auto loading file: $fi"
Revise.includet(default_context(context), fi)
# Revise.includet(default_context(context), fi)
Base.include(default_context(context), abspath(fi))
Genie.Configuration.isdev() && Revise.track(default_context(context), abspath(fi))
end
end

for (root, dirs, files) in walkdir(root_dir)
for (root, dirs, files) in walkdir(abspath(root_dir))
for dir in dirs
in(dir, skipdirs) && continue

Expand All @@ -250,9 +285,11 @@ function autoload(root_dir::String = Genie.config.path_lib;

fi = joinpath(p, i)
@debug "Checking $fi"
if validinclude(fi)
if validinclude(abspath(fi))
@debug "Auto loading file: $fi"
Revise.includet(default_context(context), fi)
# Revise.includet(default_context(context), fi)
Base.include(default_context(context), abspath(fi))
Genie.Configuration.isdev() && Revise.track(default_context(context), abspath(fi))
end
end
end
Expand Down Expand Up @@ -306,7 +343,7 @@ Main entry point to loading a Genie app.
function load(; context::Union{Module,Nothing} = nothing) :: Nothing
context = default_context(context)

Genie.Configuration.isdev() && Core.eval(context, :(__revise_mode__ = :eval))
# Genie.Configuration.isdev() && Core.eval(context, :(__revise_mode__ = :eval))

t = Terminals.TTYTerminal("", stdin, stdout, stderr)

Expand Down
7 changes: 6 additions & 1 deletion src/Renderer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -159,9 +159,13 @@ function WebRenderable(wr::WebRenderable, content_type::Symbol, status::Int, hea
end


"""
Converts a function into a `WebRenderable` object by invoking it and joining the result.
"""
function WebRenderable(f::Function, args...)
# that convert all back to string mybe not needed same with stipple
fr::String = Base.invokelatest(f) |> join

println("WebRenderable 1")
WebRenderable(fr, args...)
end

Expand Down Expand Up @@ -232,6 +236,7 @@ end


function respond(body::String, params::Dict{Symbol,T})::HTTP.Response where {T}
prinln("respond 4")
r = params[:RESPONSE]
r.data = body

Expand Down
10 changes: 7 additions & 3 deletions src/Secrets.jl
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@ Here, a temporary one is generated for the current session if no other token is
"""
function secret_token(generate_if_missing::Bool = true; context::Union{Module,Nothing} = nothing)
if isempty(SECRET_TOKEN[])
isfile(joinpath(Genie.config.path_config, SECRETS_FILE_NAME)) &&
Revise.includet(Genie.Loader.default_context(context), joinpath(Genie.config.path_config, SECRETS_FILE_NAME))
isfile(abspath(Genie.config.path_config, SECRETS_FILE_NAME)) && begin
Base.include(Genie.Loader.default_context(context), abspath(Genie.config.path_config, SECRETS_FILE_NAME))
# Revise.track(context, abspath(Genie.config.path_config, SECRETS_FILE_NAME))
end

if isempty(SECRET_TOKEN[]) && generate_if_missing && Genie.Configuration.isprod()
@warn "
Expand Down Expand Up @@ -63,7 +65,9 @@ The files are set up with `Revise` to be automatically reloaded.
"""
function load(root_dir::String = Genie.config.path_config; context::Union{Module,Nothing} = nothing) :: Nothing
secrets_path = secret_file_path(root_dir)
isfile(secrets_path) && Revise.includet(Genie.Loader.default_context(context), secrets_path)
# isfile(secrets_path) && Revise.includet(Genie.Loader.default_context(context), abspath(secrets_path))
isfile(secrets_path) && Base.include(Genie.Loader.default_context(context), abspath(secrets_path))
Genie.Configuration.isdev() && Revise.track(context, abspath(secrets_path))

# check that the secrets_path has called Genie.secret_token!
if isempty(secret_token(false)) # do not generate a temporary token in this check
Expand Down
4 changes: 3 additions & 1 deletion src/Toolbox.jl
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ function loadtasks(context::Module = Genie.Loader.default_context(); filter_type
for i in f
if ( endswith(i, "Task.jl") )
module_name = Genie.Util.file_name_without_extension(i) |> Symbol
Revise.includet(context, joinpath(Genie.config.path_tasks, i))
# Revise.includet(context, joinpath(Genie.config.path_tasks, i))
Base.include(context, joinpath(Genie.config.path_tasks, i))
Revise.track(context, joinpath(Genie.config.path_tasks, i))

ti = TaskInfo(i, module_name, taskdocs(module_name, context = context))

Expand Down
Loading