Skip to content

Commit

Permalink
Merge pull request #712 from hhaensel/hh-compat2
Browse files Browse the repository at this point in the history
bump compat of LoweredCodeUtils and DotEnv and move package_version from Assets to Util
  • Loading branch information
hhaensel authored Apr 23, 2024
2 parents 144e3a8 + a8c64f7 commit 5cadc69
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 25 deletions.
4 changes: 2 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ ArgParse = "1"
Base64 = "1.6"
Dates = "1.6"
Distributed = "1.6"
DotEnv = "0.3"
DotEnv = "0.3, 1"
EzXML = "1"
FilePathsBase = "0.9"
HTTP = "1"
Expand All @@ -52,7 +52,7 @@ JSON3 = "1"
JuliaFormatter = "1"
Logging = "1.6"
LoggingExtras = "1"
LoweredCodeUtils = "=2.3.2"
LoweredCodeUtils = "2.4.5"
MIMEs = "0.1"
Markdown = "1.6"
Millboard = "0.2"
Expand Down
20 changes: 1 addition & 19 deletions src/Assets.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module Assets

import Genie, Genie.Configuration, Genie.Router, Genie.WebChannels, Genie.WebThreads
import Genie.Renderer.Json
import Pkg
import Genie.Util.package_version

export include_asset, css_asset, js_asset, js_settings, css, js
export embedded, channels_script, channels_support, webthreads_script, webthreads_support
Expand All @@ -14,24 +14,6 @@ export favicon_support

### PUBLIC ###

"""
package_version(package::Union{Module,String}) :: String
Returns the version of a package, or "master" if the package is not installed.
### Example
```julia
julia> package_version("Genie.jl")
"v0.23.0"
"""
function package_version(package::Union{Module,String}) :: String
isa(package, Module) && (package = String(nameof(package)))
endswith(package, ".jl") && (package = String(package[1:end-3]))
pkg_dict = filter(x -> x.second.name == package, Pkg.dependencies())
isempty(pkg_dict) ? "master" : ("v" * string(first(pkg_dict)[2].version))
end

"""
mutable struct AssetsConfig
Expand Down
2 changes: 1 addition & 1 deletion src/Genie.jl
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ import Logging
using Reexport
using Revise

include("Util.jl")
include("HTTPUtils.jl")
include("Exceptions.jl")
include("Repl.jl")
include("Watch.jl")
include("Loader.jl")
include("Secrets.jl")
include("Util.jl")
include("FileTemplates.jl")
include("Toolbox.jl")
include("Generator.jl")
Expand Down
7 changes: 5 additions & 2 deletions src/Loader.jl
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,11 @@ Loads .env file if present
"""
function load_dotenv()
if isfile(Genie.config.env_file)
# DotEnv.load!(Genie.config.env_file; override = true) #TODO: enable this when DotEnv.jl is updated
DotEnv.config(; path = Genie.config.env_file, override = true)
@static if VersionNumber(Genie.Util.package_version(DotEnv)) >= v"1.0"
DotEnv.load!(Genie.config.env_file; override = true)
else
DotEnv.config(; path = Genie.config.env_file, override = true)
end
end

nothing
Expand Down
20 changes: 20 additions & 0 deletions src/Util.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
module Util

using Pkg
import Genie


Expand Down Expand Up @@ -76,4 +77,23 @@ isprecompiling() = ccall(:jl_generating_output, Cint, ()) == 1

const fws = filterwhitespace

"""
package_version(package::Union{Module,String}) :: String
Returns the version of a package, or "master" if the package is not installed.
### Example
```julia
julia> package_version("Genie.jl")
"v0.23.0"
"""
function package_version(package::Union{Module,String}) :: String
isa(package, Module) && (package = String(nameof(package)))
endswith(package, ".jl") && (package = String(package[1:end-3]))
pkg_dict = filter(x -> x.second.name == package, Pkg.dependencies())
isempty(pkg_dict) ? "master" : ("v" * string(first(pkg_dict)[2].version))
end

end
2 changes: 1 addition & 1 deletion test/tests_1_config.jl
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@

Genie.config.server_port = 8000
Genie.config.server_host = "127.0.0.1"
Genie.config.websockets_port = 8000
Genie.config.websockets_port = nothing
Genie.config.run_as_server = false

down()
Expand Down
1 change: 1 addition & 0 deletions test/tests_loader.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@
@test get(ENV, "FOO", "") == ""
Genie.Loader.load_dotenv()
@test get(ENV, "FOO", "") == "bar"
delete!(ENV, "FOO")
end

0 comments on commit 5cadc69

Please sign in to comment.