Skip to content

Commit

Permalink
Banner hiding in Oscar.jl, Polymake.jl, etc (#1643)
Browse files Browse the repository at this point in the history
* 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
lkastner authored Apr 11, 2024
1 parent a49b43f commit 1d9eef1
Show file tree
Hide file tree
Showing 12 changed files with 159 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "AbstractAlgebra"
uuid = "c3fe647b-3220-5bb0-a1ea-a7954cac585d"
version = "0.40.7"
version = "0.40.8"

[deps]
InteractiveUtils = "b77e0a4c-d291-57a0-90e8-8db25a27a240"
Expand Down
7 changes: 7 additions & 0 deletions src/AbstractAlgebra.jl
Original file line number Diff line number Diff line change
Expand Up @@ -443,4 +443,11 @@ function test_module(x, y)
run(`$julia_exe -e $cmd`)
end

###############################################################################
#
# Utils
#
###############################################################################
include("utils.jl")

end # module
22 changes: 22 additions & 0 deletions src/utils.jl
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
2 changes: 2 additions & 0 deletions test/Project.toml
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"
2 changes: 2 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ if false VERSION >= v"1.8.0"
=#
end

include("utils/Banners/banners.jl")

include("Aqua.jl")
include("rand.jl")
include("AbstractAlgebra-test.jl")
6 changes: 6 additions & 0 deletions test/utils/Banners/ModA/Project.toml
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"
11 changes: 11 additions & 0 deletions test/utils/Banners/ModA/src/ModA.jl
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
7 changes: 7 additions & 0 deletions test/utils/Banners/ModB/Project.toml
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"
13 changes: 13 additions & 0 deletions test/utils/Banners/ModB/src/ModB.jl
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
6 changes: 6 additions & 0 deletions test/utils/Banners/ModC/Project.toml
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"
5 changes: 5 additions & 0 deletions test/utils/Banners/ModC/src/ModC.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module ModC

using ModB

end # module ModC
77 changes: 77 additions & 0 deletions test/utils/Banners/banners.jl
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

2 comments on commit 1d9eef1

@lgoettgens
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

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.

@JuliaRegistrator register

Release notes:

## Breaking changes

- blah

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:

git tag -a v0.40.8 -m "<description of version>" 1d9eef196a3473e439c9c255b1a8c7328daaff73
git push origin v0.40.8

Please sign in to comment.