diff --git a/CHANGELOG.md b/CHANGELOG.md index 6e0a7efe3..74a094eb0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), * All the public API names are now correctly marked `public` in Julia 1.11 and above. ([#83]) +### Changed + +* The string `repr` of `DatasetVersion` (e.g. `dataset.versions`) is now valid Julia code. ([#84]) + ### Fixed * The `JuliaHub.update_dataset` function now correctly accepts the `license=(:fulltext, ...)` argument. ([#74]) @@ -146,3 +150,4 @@ Initial package release. [#58]: https://github.com/JuliaComputing/JuliaHub.jl/issues/58 [#74]: https://github.com/JuliaComputing/JuliaHub.jl/issues/74 [#83]: https://github.com/JuliaComputing/JuliaHub.jl/issues/83 +[#84]: https://github.com/JuliaComputing/JuliaHub.jl/issues/84 \ No newline at end of file diff --git a/Makefile b/Makefile index 95c287b54..2454001da 100644 --- a/Makefile +++ b/Makefile @@ -17,6 +17,9 @@ docs-manifest: docs: docs/Manifest.toml ${JULIA} --project=docs/ docs/make.jl +fix-doctests: docs/Manifest.toml + ${JULIA} --project=docs/ docs/make.jl --fix-doctests + changelog: ${JULIA} --project=docs/ docs/changelog.jl diff --git a/docs/src/guides/datasets.md b/docs/src/guides/datasets.md index aa04ce409..a4ba7c073 100644 --- a/docs/src/guides/datasets.md +++ b/docs/src/guides/datasets.md @@ -87,8 +87,8 @@ When downloading, you can also specify the version you wish to download (with th ```jldoctest example-dataset; filter = r"\"/.+/mydata\"" julia> ds.versions 2-element Vector{JuliaHub.DatasetVersion}: - JuliaHub.DatasetVersion(dataset = ("username", "example-dataset"), version = 1) - JuliaHub.DatasetVersion(dataset = ("username", "example-dataset"), version = 2) + JuliaHub.dataset(("username", "example-dataset")).versions[1] + JuliaHub.dataset(("username", "example-dataset")).versions[2] julia> ds.versions[1] DatasetVersion: example-dataset @ v1 diff --git a/src/datasets.jl b/src/datasets.jl index f4c7441fe..4d81eada5 100644 --- a/src/datasets.jl +++ b/src/datasets.jl @@ -25,8 +25,25 @@ Objects have the following properties: - `.size :: Int`: size of the dataset version in bytes - `.timestamp :: ZonedDateTime`: dataset version timestamp -``` -julia> JuliaHub.datasets() +```jldoctest +julia> dataset = JuliaHub.dataset("example-dataset") +Dataset: example-dataset (Blob) + owner: username + description: An example dataset + versions: 2 + size: 388 bytes + tags: tag1, tag2 + +julia> dataset.versions +2-element Vector{JuliaHub.DatasetVersion}: + JuliaHub.dataset(("username", "example-dataset")).versions[1] + JuliaHub.dataset(("username", "example-dataset")).versions[2] + +julia> dataset.versions[end] +DatasetVersion: example-dataset @ v2 + owner: username + timestamp: 2022-10-14T01:39:43.237-04:00 + size: 331 bytes ``` See also: [`Dataset`](@ref), [`datasets`](@ref), [`dataset`](@ref). @@ -46,21 +63,17 @@ struct DatasetVersion size = _get_json(json, "size", Int; msg) timestamp = _parse_tz(_get_json(json, "date", String; msg); msg) blobstore_path = _get_json(json, "blobstore_path", String; msg) - new((owner, name), version, size, timestamp, blobstore_path) + return new((owner, name), version, size, timestamp, blobstore_path) end end function Base.show(io::IO, dsv::DatasetVersion) owner, name = dsv._dsref - print( - io, - "JuliaHub.DatasetVersion(dataset = (\"", - owner, - "\", \"", - name, - "\"), version = $(dsv.id))", - ) + dsref = string("(\"", owner, "\", \"", name, "\")") + print(io, "JuliaHub.dataset($dsref).versions[$(dsv.id)]") + return nothing end + function Base.show(io::IO, ::MIME"text/plain", dsv::DatasetVersion) owner, name = dsv._dsref printstyled(io, "DatasetVersion:"; bold=true) @@ -68,6 +81,7 @@ function Base.show(io::IO, ::MIME"text/plain", dsv::DatasetVersion) print(io, "\n owner: ", owner) print(io, "\n timestamp: ", dsv.timestamp) print(io, "\n size: ", dsv.size, " bytes") + return nothing end """ diff --git a/test/datasets.jl b/test/datasets.jl index 2506f2242..0ea3ecf75 100644 --- a/test/datasets.jl +++ b/test/datasets.jl @@ -56,6 +56,20 @@ end @test ds.versions[2].id == 2 @test ds.versions[2].size == 331 + # Test that .versions repr()-s to a valid array + # and DatasetVersion reprs to a valid JuliaHub.dataset().versions[...] + # call. + let versions = eval(Meta.parse(string(ds.versions))) + @test versions isa Vector{JuliaHub.DatasetVersion} + @test length(versions) == 2 + @test versions == ds.versions + end + let expr = Meta.parse(string(ds.versions[1])) + @test expr == :((JuliaHub.dataset(("username", "example-dataset"))).versions[1]) + version = eval(expr) + @test version == ds.versions[1] + end + ds_updated = JuliaHub.dataset("example-dataset") @test ds_updated isa JuliaHub.Dataset @test ds_updated.name == ds.name