Skip to content

Commit 8f40681

Browse files
committed
Merge remote-tracking branch 'origin/main' into mp/project-datasets
2 parents 1f3c1aa + b2558f8 commit 8f40681

File tree

7 files changed

+98
-27
lines changed

7 files changed

+98
-27
lines changed

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,14 @@ 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+
11+
### Changed
12+
13+
* The string `repr` of `DatasetVersion` (e.g. `dataset.versions`) is now valid Julia code. ([#84])
14+
715
### Fixed
816

917
* The `JuliaHub.update_dataset` function now correctly accepts the `license=(:fulltext, ...)` argument. ([#74])
@@ -141,3 +149,5 @@ Initial package release.
141149
[#53]: https://github.com/JuliaComputing/JuliaHub.jl/issues/53
142150
[#58]: https://github.com/JuliaComputing/JuliaHub.jl/issues/58
143151
[#74]: https://github.com/JuliaComputing/JuliaHub.jl/issues/74
152+
[#83]: https://github.com/JuliaComputing/JuliaHub.jl/issues/83
153+
[#84]: https://github.com/JuliaComputing/JuliaHub.jl/issues/84

Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ docs-manifest:
1717
docs: docs/Manifest.toml
1818
${JULIA} --project=docs/ docs/make.jl
1919

20+
fix-doctests: docs/Manifest.toml
21+
${JULIA} --project=docs/ docs/make.jl --fix-doctests
22+
2023
changelog:
2124
${JULIA} --project=docs/ docs/changelog.jl
2225

docs/src/guides/datasets.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,8 @@ When downloading, you can also specify the version you wish to download (with th
8787
```jldoctest example-dataset; filter = r"\"/.+/mydata\""
8888
julia> ds.versions
8989
2-element Vector{JuliaHub.DatasetVersion}:
90-
JuliaHub.DatasetVersion(dataset = ("username", "example-dataset"), version = 1)
91-
JuliaHub.DatasetVersion(dataset = ("username", "example-dataset"), version = 2)
90+
JuliaHub.dataset(("username", "example-dataset")).versions[1]
91+
JuliaHub.dataset(("username", "example-dataset")).versions[2]
9292
9393
julia> ds.versions[1]
9494
DatasetVersion: example-dataset @ v1

src/JuliaHub.jl

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,31 @@ function __init__()
3939
_LOCAL_TZ[] = _localtz()
4040
end
4141

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

src/datasets.jl

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,25 @@ Objects have the following properties:
2626
- `.size :: Int`: size of the dataset version in bytes
2727
- `.timestamp :: ZonedDateTime`: dataset version timestamp
2828
29-
```
30-
julia> JuliaHub.datasets()
29+
```jldoctest
30+
julia> dataset = JuliaHub.dataset("example-dataset")
31+
Dataset: example-dataset (Blob)
32+
owner: username
33+
description: An example dataset
34+
versions: 2
35+
size: 388 bytes
36+
tags: tag1, tag2
37+
38+
julia> dataset.versions
39+
2-element Vector{JuliaHub.DatasetVersion}:
40+
JuliaHub.dataset(("username", "example-dataset")).versions[1]
41+
JuliaHub.dataset(("username", "example-dataset")).versions[2]
42+
43+
julia> dataset.versions[end]
44+
DatasetVersion: example-dataset @ v2
45+
owner: username
46+
timestamp: 2022-10-14T01:39:43.237-04:00
47+
size: 331 bytes
3148
```
3249
3350
See also: [`Dataset`](@ref), [`datasets`](@ref), [`dataset`](@ref).
@@ -47,28 +64,25 @@ struct DatasetVersion
4764
size = _get_json(json, "size", Int; msg)
4865
timestamp = _parse_tz(_get_json(json, "date", String; msg); msg)
4966
blobstore_path = _get_json(json, "blobstore_path", String; msg)
50-
new((owner, name), version, size, timestamp, blobstore_path)
67+
return new((owner, name), version, size, timestamp, blobstore_path)
5168
end
5269
end
5370

5471
function Base.show(io::IO, dsv::DatasetVersion)
5572
owner, name = dsv._dsref
56-
print(
57-
io,
58-
"JuliaHub.DatasetVersion(dataset = (\"",
59-
owner,
60-
"\", \"",
61-
name,
62-
"\"), version = $(dsv.id))",
63-
)
73+
dsref = string("(\"", owner, "\", \"", name, "\")")
74+
print(io, "JuliaHub.dataset($dsref).versions[$(dsv.id)]")
75+
return nothing
6476
end
77+
6578
function Base.show(io::IO, ::MIME"text/plain", dsv::DatasetVersion)
6679
owner, name = dsv._dsref
6780
printstyled(io, "DatasetVersion:"; bold=true)
6881
print(io, " ", name, " @ v", dsv.id)
6982
print(io, "\n owner: ", owner)
7083
print(io, "\n timestamp: ", dsv.timestamp)
7184
print(io, "\n size: ", dsv.size, " bytes")
85+
return nothing
7286
end
7387

7488
"""

test/datasets.jl

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,20 @@ end
5656
@test ds.versions[2].id == 2
5757
@test ds.versions[2].size == 331
5858

59+
# Test that .versions repr()-s to a valid array
60+
# and DatasetVersion reprs to a valid JuliaHub.dataset().versions[...]
61+
# call.
62+
let versions = eval(Meta.parse(string(ds.versions)))
63+
@test versions isa Vector{JuliaHub.DatasetVersion}
64+
@test length(versions) == 2
65+
@test versions == ds.versions
66+
end
67+
let expr = Meta.parse(string(ds.versions[1]))
68+
@test expr == :((JuliaHub.dataset(("username", "example-dataset"))).versions[1])
69+
version = eval(expr)
70+
@test version == ds.versions[1]
71+
end
72+
5973
ds_updated = JuliaHub.dataset("example-dataset")
6074
@test ds_updated isa JuliaHub.Dataset
6175
@test ds_updated.name == ds.name

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)