Skip to content

Commit 69d8d3e

Browse files
committed
add "verbosity" preference and default_verbosity()
oops
1 parent 5e31043 commit 69d8d3e

File tree

6 files changed

+62
-2
lines changed

6 files changed

+62
-2
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ sandbox/
88
/docs/site/
99
/docs/Manifest.toml
1010
.vscode
11+
LocalPreferences.toml

Project.toml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
1+
authors = ["Anthony D. Blaom <anthony.blaom@gmail.com>"]
12
name = "LearnAPI"
23
uuid = "92ad9a40-7767-427a-9ee6-6e577f1266cb"
3-
authors = ["Anthony D. Blaom <anthony.blaom@gmail.com>"]
44
version = "2.0.0"
55

66
[compat]
7+
Preferences = "1.5.0"
78
julia = "1.10"
89

10+
[deps]
11+
Preferences = "21216c6a-2e73-6563-6e65-726566657250"
12+
913
[extras]
1014
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
1115

1216
[targets]
13-
test = ["Test",]
17+
test = ["Test"]

src/LearnAPI.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
module LearnAPI
22

3+
using Preferences
4+
5+
include("preferences.jl")
36
include("types.jl")
47
include("tools.jl")
58
include("predict_transform.jl")

src/preferences.jl

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
const VERBOSITY = @load_preference "verbosity" 1
2+
3+
INFO_VERBOSITY_IS(verbosity) =
4+
"Currently the baseline verbosity is $verbosity. "
5+
INFO_VERBOSITY_WILL_BE(verbosity) =
6+
"After restarting Julia, this will be changed to $verbosity. "
7+
8+
"""
9+
LearnAPI.default_verbosity()
10+
11+
Return the default verbosity for training LearnAPI learners.
12+
13+
The value is determined at compile time by a Preferences.jl-style preference, with key
14+
"verbosity".
15+
16+
"""
17+
default_verbosity() = VERBOSITY
18+
19+
"""
20+
LearnAPI.default_verbosity(level)
21+
22+
Set the default verbosity for training LearnAPI learners to `level`. Changes do not take
23+
effect until the next Julia session.
24+
25+
"""
26+
function default_verbosity(level)
27+
@info INFO_VERBOSITY_IS(VERBOSITY)
28+
@set_preferences! "verbosity" => level
29+
@info INFO_VERBOSITY_WILL_BE(level)
30+
end

test/preferences.jl

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
using LearnAPI
2+
using Preferences
3+
4+
@testset "default_verbosity" begin
5+
@test LearnAPI.default_verbosity() == LearnAPI.VERBOSITY
6+
@test_logs(
7+
(:info, LearnAPI.INFO_VERBOSITY_IS(LearnAPI.default_verbosity())),
8+
(:info, LearnAPI.INFO_VERBOSITY_WILL_BE(3)),
9+
LearnAPI.default_verbosity(3),
10+
)
11+
@test load_preference(LearnAPI, "verbosity") == 3
12+
13+
# restore active preference:
14+
@test_logs(
15+
(:info, LearnAPI.INFO_VERBOSITY_IS(LearnAPI.default_verbosity())),
16+
(:info, LearnAPI.INFO_VERBOSITY_WILL_BE(LearnAPI.VERBOSITY)),
17+
LearnAPI.default_verbosity(LearnAPI.VERBOSITY),
18+
)
19+
end
20+
21+
true

test/runtests.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using Test
22

33
test_files = [
4+
"preferences.jl",
45
"tools.jl",
56
"traits.jl",
67
"clone.jl",

0 commit comments

Comments
 (0)