-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Banner hiding in Oscar.jl, Polymake.jl, etc (#1643)
* Universal parts of banner hiding * utils: Do not export should_show_banner * Bump version to 0.40.8 * Locally test a chain of modules with banners * More debug output * Fix debug output * banner tests: add Pkg to test env, cleanup temp project generation * bannertest: adjust broken for ModA, usw raw string for windows * run banner tests at the beginning for now * bannertest: force precompile to fix tests on 1.9
- Loading branch information
Showing
12 changed files
with
159 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
function should_show_banner() | ||
# Check if were loaded from another package | ||
# if VERSION < 1.7.*, only the "other" package will have the | ||
# _tryrequire_from_serialized in the backtrace. | ||
# if VERSION >= 1.8, also doing 'using Package' will have | ||
# _tryrequire_from_serialized the backtrace. | ||
# | ||
# To still distinguish both scenarios, notice that | ||
# 'using OtherPackage' will either have _tryrequire_from_serialized at least twice, | ||
# or one with four arguments (hence five as the function name is the first argument) | ||
# 'using Package' serialized will have a version with less arguments | ||
bt = Base.process_backtrace(Base.backtrace()) | ||
Base.filter!(sf -> sf[1].func === :_tryrequire_from_serialized, bt) | ||
isinteractive_manual = | ||
length(bt) == 0 || (length(bt) == 1 && length(only(bt)[1].linfo.specTypes.parameters) < 4) | ||
|
||
# Respect the -q flag | ||
isquiet = Bool(Base.JLOptions().quiet) | ||
show_banner = !isquiet && isinteractive_manual && isinteractive() && | ||
Base.JLOptions().banner != 0 | ||
return show_banner | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,11 @@ | ||
[deps] | ||
Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595" | ||
Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f" | ||
REPL = "3fa0cd96-eef1-5676-8a61-b3b8758bbffb" | ||
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" | ||
|
||
[compat] | ||
Aqua = "0.8.2" | ||
Pkg = "1.6" | ||
REPL = "1.6" | ||
Test = "1.6" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
name = "ModA" | ||
uuid = "a32e2e01-01a9-418d-9b94-b3b59314d0cc" | ||
version = "0.1.0" | ||
|
||
[deps] | ||
AbstractAlgebra = "c3fe647b-3220-5bb0-a1ea-a7954cac585d" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
module ModA | ||
|
||
import AbstractAlgebra: should_show_banner | ||
|
||
function __init__() | ||
if should_show_banner() | ||
println("Banner of ModA") | ||
end | ||
end | ||
|
||
end # module ModA |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
name = "ModB" | ||
uuid = "1f443fa9-d801-49d7-85a0-b381b1f56192" | ||
version = "0.1.0" | ||
|
||
[deps] | ||
AbstractAlgebra = "c3fe647b-3220-5bb0-a1ea-a7954cac585d" | ||
ModA = "a32e2e01-01a9-418d-9b94-b3b59314d0cc" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
module ModB | ||
|
||
import AbstractAlgebra: should_show_banner | ||
|
||
using ModA | ||
|
||
function __init__() | ||
if should_show_banner() | ||
println("Banner of ModB") | ||
end | ||
end | ||
|
||
end # module ModB |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
name = "ModC" | ||
uuid = "df9190fa-7efd-4656-b7a4-f08ddd3526a5" | ||
version = "0.1.0" | ||
|
||
[deps] | ||
ModB = "1f443fa9-d801-49d7-85a0-b381b1f56192" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
module ModC | ||
|
||
using ModB | ||
|
||
end # module ModC |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
using Pkg | ||
|
||
if VERSION>=v"1.9" | ||
@testset "Banners" begin | ||
|
||
function run_repl_code(code::String, proj::String) | ||
bin = Base.julia_cmd() | ||
opts = ["--project=$proj", "-i", "-e", "$code; exit();"] | ||
cmd = Cmd(`$bin $opts`, ignorestatus=true) | ||
outs = IOBuffer() | ||
errs = IOBuffer() | ||
proc = run(pipeline(`$cmd`, stderr=errs, stdout=outs)) | ||
result = String(take!(outs)) | ||
err = String(take!(errs)) | ||
return result, err, proc.exitcode | ||
end | ||
|
||
# Set up a separate temporary project for some modules that depend on each | ||
# other with some of them showing banners. Chain is | ||
# AA -> ModA -> ModB -> ModC | ||
path = dirname(@__FILE__) | ||
aadir = dirname(dirname(pathof(AbstractAlgebra))) | ||
modadir = joinpath(path, "ModA") | ||
modbdir = joinpath(path, "ModB") | ||
modcdir = joinpath(path, "ModC") | ||
|
||
# generate temp project | ||
td = mktempdir() | ||
code = """ | ||
using Pkg; | ||
Pkg.develop(path=raw"$aadir"); | ||
Pkg.develop(path=raw"$modadir"); | ||
Pkg.develop(path=raw"$modbdir"); | ||
Pkg.develop(path=raw"$modcdir"); | ||
Pkg.precompile(); | ||
""" | ||
out,err,exitcode = run_repl_code(code, td) | ||
res = @test exitcode == 0 | ||
if res isa Test.Fail | ||
println("out\n$out") | ||
println("err\n$err") | ||
end | ||
|
||
# Banner of ModA shows | ||
out, err = run_repl_code("using ModA;", td) | ||
res = @test strip(out) == "Banner of ModA" | ||
if res isa Test.Fail | ||
println("out\n$out") | ||
println("err\n$err") | ||
end | ||
|
||
# Banner of ModB shows, but ModA is supressed | ||
out, err = run_repl_code("using ModB;", td) | ||
res = @test strip(out) == "Banner of ModB" broken=VERSION>=v"1.11.0-DEV" | ||
if res isa Test.Fail | ||
println("out\n$out") | ||
println("err\n$err") | ||
end | ||
|
||
# Banner of ModB shows, but ModA is supressed, even if ModA is specifically | ||
# used after ModB | ||
out, err = run_repl_code("using ModB; using ModA;", td) | ||
res = @test strip(out) == "Banner of ModB" broken=VERSION>=v"1.11.0-DEV" | ||
if res isa Test.Fail | ||
println("out\n$out") | ||
println("err\n$err") | ||
end | ||
|
||
# Banner does not show when our module is a dependency | ||
out, err = run_repl_code("using ModC;", td) | ||
res = @test strip(out) == "" broken=VERSION>=v"1.11.0-DEV" | ||
if res isa Test.Fail | ||
println("out\n$out") | ||
println("err\n$err") | ||
end | ||
end | ||
end |
1d9eef1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@JuliaRegistrator register
1d9eef1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Registration pull request created: JuliaRegistries/General/104692
Tip: Release Notes
Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.
To add them here just re-invoke and the PR will be updated.
Tagging
After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.
This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via: