Skip to content

Commit c9a711d

Browse files
authored
refactor: mark public names as public (#83)
1 parent 1040337 commit c9a711d

File tree

3 files changed

+49
-14
lines changed

3 files changed

+49
-14
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
44

55
## Unreleased
66

7+
### Added
8+
9+
* All the public API names are now correctly marked `public` in Julia 1.11 and above. ([#83])
10+
711
### Fixed
812

913
* The `JuliaHub.update_dataset` function now correctly accepts the `license=(:fulltext, ...)` argument. ([#74])
@@ -141,3 +145,4 @@ Initial package release.
141145
[#53]: https://github.com/JuliaComputing/JuliaHub.jl/issues/53
142146
[#58]: https://github.com/JuliaComputing/JuliaHub.jl/issues/58
143147
[#74]: https://github.com/JuliaComputing/JuliaHub.jl/issues/74
148+
[#83]: https://github.com/JuliaComputing/JuliaHub.jl/issues/83

src/JuliaHub.jl

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,31 @@ 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+
# We don't need to check or mark public the main module itself
46+
(s == :JuliaHub) && return false
47+
startswith(string(s), "_") && return false
48+
# Internal functions and types, prefixed by _
49+
startswith(string(s), "_") && return false
50+
# Internal macros, prefixed by _
51+
startswith(string(s), "@_") && return false
52+
# Strange generated functions
53+
startswith(string(s), "#") && return false
54+
# Some core functions that are not relevant for the package
55+
s in [:eval, :include] && return false
56+
return true
57+
end
58+
end
59+
macro _mark_names_public()
60+
if !Base.isdefined(Base, :ispublic)
61+
return nothing
62+
end
63+
public_names = _find_public_names()
64+
return esc(Expr(:public, public_names...))
65+
end
66+
@_mark_names_public
67+
4168
end

test/runtests.jl

Lines changed: 17 additions & 14 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,
@@ -194,7 +182,7 @@ end
194182
:Dataset, :DatasetReference, :DatasetVersion,
195183
:DefaultApp, :FileHash, :InvalidAuthentication, :InvalidRequestError, :Job,
196184
:WorkloadConfig, :JobFile, :JobLogMessage, :JobReference, :JobStatus,
197-
:JuliaHub, :JuliaHubConnectionError, :JuliaHubError,
185+
:JuliaHubConnectionError, :JuliaHubError,
198186
:JuliaHubException,
199187
:Limit, :NodeSpec, :PackageApp, :PackageJob, :Unlimited,
200188
:PermissionError, :script, :Secret, :UserApp,
@@ -223,6 +211,21 @@ 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: $(name)" for name in public_symbols
218+
@test Base.ispublic(JuliaHub, name)
219+
end
220+
private_names = setdiff(
221+
names(JuliaHub; all=true),
222+
public_symbols,
223+
[:JuliaHub],
224+
)
225+
@testset "!ispublic: $(name)" for name in private_names
226+
@test !Base.ispublic(JuliaHub, name)
227+
end
228+
end
226229
end
227230

228231
@testset "Utilities" begin

0 commit comments

Comments
 (0)