Skip to content

Commit af8d395

Browse files
committed
refactor: mark public names as public
1 parent 1040337 commit af8d395

File tree

2 files changed

+37
-13
lines changed

2 files changed

+37
-13
lines changed

src/JuliaHub.jl

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,28 @@ function __init__()
3838
_LOCAL_TZ[] = _localtz()
3939
end
4040

41+
# JuliaHub.jl follows the convention that all private names are
42+
# prefixed with an underscore.
43+
function _find_public_names()
44+
return filter(names(@__MODULE__; all=true)) do s
45+
# Internal functions and types, prefixed by _
46+
startswith(string(s), "_") && return false
47+
# Internal macros, prefixed by _
48+
startswith(string(s), "@_") && return false
49+
# Strange generated functions
50+
startswith(string(s), "#") && return false
51+
# Some core functions that are not relevant for the package
52+
s in [:eval, :include] && return false
53+
return true
54+
end
55+
end
56+
macro _mark_names_public()
57+
if !Base.isdefined(Base, :ispublic)
58+
return nothing
59+
end
60+
public_names = _find_public_names()
61+
return esc(Expr(:public, public_names...))
62+
end
63+
@_mark_names_public
64+
4165
end

test/runtests.jl

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -173,19 +173,7 @@ end
173173
# This set tests that we haven't accidentally added or removed any public-looking
174174
# functions (i.e. ones that are not prefixed by _ basically).
175175
@testset "Public API" begin
176-
public_symbols = Set(
177-
filter(names(JuliaHub; all=true)) do s
178-
# Internal functions and types, prefixed by _
179-
startswith(string(s), "_") && return false
180-
# Internal macros, prefixed by _
181-
startswith(string(s), "@_") && return false
182-
# Strange generated functions
183-
startswith(string(s), "#") && return false
184-
# Some core functions that are not relevant for the package
185-
s in [:eval, :include] && return false
186-
return true
187-
end,
188-
)
176+
public_symbols = Set(JuliaHub._find_public_names())
189177
expected_public_symbols = Set([
190178
Symbol("@script_str"),
191179
:AbstractJobConfig, :AbstractJuliaHubApp,
@@ -223,6 +211,18 @@ end
223211
extra_expected_symbols = $(sprint(show, MIME"text/plain"(), extra_expected_symbols))
224212
"""
225213
@test isempty(extra_expected_symbols)
214+
# Make sure that on Julia versions that support the `public` keyword,
215+
# we are also marking the right symbols as public.
216+
if Base.isdefined(Base, :ispublic)
217+
@testset "ispublic" begin
218+
for name in public_symbols
219+
@test Base.ispublic(JuliaHub, name)
220+
end
221+
for name in setdiff(names(JuliaHub; all=true), public_symbols)
222+
@test !Base.ispublic(JuliaHub, name)
223+
end
224+
end
225+
end
226226
end
227227

228228
@testset "Utilities" begin

0 commit comments

Comments
 (0)