Skip to content

Commit 2bac6f5

Browse files
authored
Don't use the Module(...) constructor to create a module (#2683)
1 parent 5655b59 commit 2bac6f5

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2020

2121
### Fixed
2222

23+
* Modules for `@example` environments are now generated by `eval`'ing an expression, rather than invoking the `Module` constructor, which is not recommended. (#2683)
2324
* Changed the header crossref step to eagerly fail when encountering a non-unique header slug. ([#2668], [#2787])
2425

2526
This is **potentially breaking** and may cause some documentation builds to fail.
@@ -2153,6 +2154,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
21532154
[#2662]: https://github.com/JuliaDocs/Documenter.jl/issues/2662
21542155
[#2668]: https://github.com/JuliaDocs/Documenter.jl/issues/2668
21552156
[#2674]: https://github.com/JuliaDocs/Documenter.jl/issues/2674
2157+
[#2683]: https://github.com/JuliaDocs/Documenter.jl/issues/2683
21562158
[#2675]: https://github.com/JuliaDocs/Documenter.jl/issues/2675
21572159
[#2676]: https://github.com/JuliaDocs/Documenter.jl/issues/2676
21582160
[#2682]: https://github.com/JuliaDocs/Documenter.jl/issues/2682

src/utilities/utilities.jl

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -628,12 +628,19 @@ function get_sandbox_module!(meta, prefix, name = nothing; share_default_module
628628
# Either fetch and return an existing sandbox from the meta dictionary (based on the generated name),
629629
# or initialize a new clean one, which gets stored in meta for future re-use.
630630
return get!(meta, sym) do
631-
# If the module does not exists already, we need to construct a new one.
632-
m = Module(sym)
633-
# eval(expr) is available in the REPL (i.e. Main) so we emulate that for the sandbox
634-
Core.eval(m, :(eval(x) = Core.eval($m, x)))
635-
# modules created with Module() does not have include defined
636-
Core.eval(m, :(include(x) = Base.include($m, abspath(x))))
631+
# If the module does not exist already, we need to construct a new one.
632+
# We create a baremodule so that we can insert a custom `include` method
633+
# that is closer to the one in Main, in that it works relative to the
634+
# current working directory, not relative to the module.
635+
m = Core.eval(
636+
Main, :(
637+
baremodule $sym
638+
using Base
639+
eval(x) = Core.eval($sym, x)
640+
include(x) = Base.include($sym, abspath(x))
641+
end
642+
)
643+
)
637644
return m
638645
end
639646
end

0 commit comments

Comments
 (0)