Skip to content

Commit

Permalink
Remove Pkg as a dependency
Browse files Browse the repository at this point in the history
In recent Julia versions Pkg is not in the sysimage and therefore it can
not be loaded "for free". Pkg was only used to conditionally activate
the documentation environment in `LiveServer.servedocs` so the loss of
functionality is basically non-existent -- it is easy enough to
configure the package environment before calling `LiveServer.servedocs`.

Timings for loading LiveServer on Julia 1.12:
```
julia> @time using LiveServer # this PR
  0.448249 seconds

julia> @time using LiveServer # master
  0.743163 seconds
```
  • Loading branch information
fredrikekre committed Sep 4, 2024
1 parent eec3d5b commit d5d1779
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 7 deletions.
1 change: 0 additions & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ version = "1.3.1"
HTTP = "cd3eb016-35fb-5094-929b-558a96fad6f3"
LoggingExtras = "e6f89c97-d47a-5376-807f-9c37f3926c36"
MIMEs = "6c6e2e6c-3030-632d-7369-2d6c69616d65"
Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"
Sockets = "6462fe0b-24de-5631-8697-dd941f90decc"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

Expand Down
2 changes: 1 addition & 1 deletion src/LiveServer.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module LiveServer

import Sockets, Pkg, MIMEs
import Sockets, MIMEs
using Base.Filesystem
using Base.Threads: @spawn

Expand Down
19 changes: 15 additions & 4 deletions src/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,6 @@ subfolder `docs`.
* `verbose=false`: boolean switch to make the server print information about
file changes and connections.
* `doc_env=false`: a boolean switch to make the server start by activating the
doc environment or not (i.e. the `Project.toml` in `docs/`).
* `literate=nothing`: see `literate_dir`.
* `literate_dir=nothing`: Path to a directory containing Literate scripts if
these are not simply under `docs/src`.
Expand Down Expand Up @@ -271,7 +269,12 @@ function servedocs(;
)

# activate the doc environment if required
doc_env && Pkg.activate(joinpath(foldername, "Project.toml"))
if doc_env
msg = "The `doc_env` keyword argument is deprecated. Configure the environment " *
"before calling LiveServer.servedocs instead."
Base.depwarn(msg, :servedocs)
prev = deprecated_activate(joinpath(foldername, "Project.toml"))
end

# trigger a first pass of Documenter (& possibly Literate)
Main.include(abspath(path2makejl))
Expand All @@ -291,10 +294,18 @@ function servedocs(;
)

# when the serve loop is interrupted, de-activate the environment
doc_env && Pkg.activate()
if doc_env
deprecated_activate(prev)
end
return
end

function deprecated_activate(path)
prev = Base.ACTIVE_PROJECT[]
Base.ACTIVE_PROJECT[] = path
return prev
end


#
# Miscellaneous utils
Expand Down
1 change: 0 additions & 1 deletion test/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
Crayons = "a8cc5b0e-0ffa-5ad4-8c14-923d3ee1735f"
HTTP = "cd3eb016-35fb-5094-929b-558a96fad6f3"
MIMEs = "6c6e2e6c-3030-632d-7369-2d6c69616d65"
Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"
Sockets = "6462fe0b-24de-5631-8697-dd941f90decc"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

Expand Down

0 comments on commit d5d1779

Please sign in to comment.