Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),

## Unreleased

### 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])
Expand Down Expand Up @@ -141,3 +145,4 @@ Initial package release.
[#53]: https://github.com/JuliaComputing/JuliaHub.jl/issues/53
[#58]: https://github.com/JuliaComputing/JuliaHub.jl/issues/58
[#74]: https://github.com/JuliaComputing/JuliaHub.jl/issues/74
[#84]: https://github.com/JuliaComputing/JuliaHub.jl/issues/84
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions docs/src/guides/datasets.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
36 changes: 25 additions & 11 deletions src/datasets.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand All @@ -46,28 +63,25 @@ 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)
print(io, " ", name, " @ v", dsv.id)
print(io, "\n owner: ", owner)
print(io, "\n timestamp: ", dsv.timestamp)
print(io, "\n size: ", dsv.size, " bytes")
return nothing
end

"""
Expand Down
14 changes: 14 additions & 0 deletions test/datasets.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading