Skip to content

Commit a4274a7

Browse files
mortenpipfitzseb
andauthored
feat: add functions for project-dataset operations (#82)
* feat(experiment): add JuliaHub._project_datasets * upload WIP * end-to-end wip * wip docs & cleanup * cleanup * get rid of separate type * add basic Dataset constructor tests * make sure Dataset only throws JuliaHubError * in mocking, .tags is sometimes Any[] * only silently capture JuliaHubErrors in datasets() * add a return * don't rely on string rep of a parametric type * bad merge * fix * fix current tests * fixes & tests for auth * add unit tests for listing APIs * basic upload_project_dataset unit tests * add live tests for projects * add option to run tests * format * docs: use [sources] * docstrings * auth docs * changelog * make JET happy? * 🤦 * fix project_dataset print * Update src/authentication.jl * don't allow missing in authenticate() * fix doctests --------- Co-authored-by: Sebastian Pfitzner <[email protected]>
1 parent 17315b9 commit a4274a7

20 files changed

+1252
-93
lines changed

CHANGELOG.md

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

77
### Added
88

9+
* With JuliaHub instances v6.9 and above, JuliaHub.jl now supports project-dataset operations. ([#15], [#82])
10+
11+
This includes the following new features:
12+
13+
- Authentication objects can now be associated with projects.
14+
If the `JULIAHUB_PROJECT_UUID` environment variable is set, JuliaHub.jl will pick it up automatically..
15+
- The `project_dataset` and `project_datasets` functions allow for listing datasets attached to a project.
16+
- `upload_project_dataset` can be used to upload a new version of a dataset.
17+
918
* All the public API names are now correctly marked `public` in Julia 1.11 and above. ([#83])
1019

1120
### Changed
@@ -134,6 +143,7 @@ Initial package release.
134143
[#12]: https://github.com/JuliaComputing/JuliaHub.jl/issues/12
135144
[#13]: https://github.com/JuliaComputing/JuliaHub.jl/issues/13
136145
[#14]: https://github.com/JuliaComputing/JuliaHub.jl/issues/14
146+
[#15]: https://github.com/JuliaComputing/JuliaHub.jl/issues/15
137147
[#18]: https://github.com/JuliaComputing/JuliaHub.jl/issues/18
138148
[#28]: https://github.com/JuliaComputing/JuliaHub.jl/issues/28
139149
[#31]: https://github.com/JuliaComputing/JuliaHub.jl/issues/31
@@ -150,6 +160,7 @@ Initial package release.
150160
[#53]: https://github.com/JuliaComputing/JuliaHub.jl/issues/53
151161
[#58]: https://github.com/JuliaComputing/JuliaHub.jl/issues/58
152162
[#74]: https://github.com/JuliaComputing/JuliaHub.jl/issues/74
163+
[#82]: https://github.com/JuliaComputing/JuliaHub.jl/issues/82
153164
[#83]: https://github.com/JuliaComputing/JuliaHub.jl/issues/83
154165
[#84]: https://github.com/JuliaComputing/JuliaHub.jl/issues/84
155166
[#86]: https://github.com/JuliaComputing/JuliaHub.jl/issues/86

docs/Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ URIs = "5c2747f8-b7ea-4ff2-ba2e-563bfd36b1d4"
1010

1111
[compat]
1212
Changelog = "1"
13-
Documenter = "1"
13+
Documenter = "1.9"
1414
DocumenterMermaid = "0.1"
1515

1616
[sources]

docs/make.jl

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ import TimeZones
99
ENV["TZ"] = "America/New_York"
1010
JuliaHub._LOCAL_TZ[] = TimeZones.localzone()
1111

12+
# Patching of the API responses. Also sets JuliaHub.__AUTH__.
13+
include("../test/mocking.jl")
14+
15+
# We don't want doctests to interfere with each other
1216
DocMeta.setdocmeta!(
1317
JuliaHub, :DocTestSetup,
1418
quote
@@ -18,8 +22,29 @@ DocMeta.setdocmeta!(
1822
recursive=true,
1923
)
2024

21-
# Patching of the API responses. Also sets JuliaHub.__AUTH__.
22-
include("../test/mocking.jl")
25+
# For project-related APIs, we need a different authentication object.
26+
# So we set up small setup and teardown functions here too.
27+
const DEFAULT_PROJECT_AUTH = mockauth(
28+
URIs.URI("https://juliahub.com");
29+
api_version=v"0.2.0",
30+
project_id=UUIDs.UUID("cd6c9ee3-d15f-414f-a762-7e1d3faed835"),
31+
)
32+
projectauth_setup!() = JuliaHub.__AUTH__[] = DEFAULT_PROJECT_AUTH
33+
projectauth_teardown!() = JuliaHub.__AUTH__[] = DEFAULT_GLOBAL_MOCK_AUTH
34+
35+
function env_setup!(; project=false)
36+
ENV["JULIA_PKG_SERVER"] = "juliahub.com"
37+
if project
38+
ENV["JULIAHUB_PROJECT_UUID"] = "b1a95ba8-43e6-4eb6-b280-3c5cbe0fa0b9"
39+
end
40+
return nothing
41+
end
42+
function env_teardown!()
43+
delete!(ENV, "JULIA_PKG_SERVER")
44+
delete!(ENV, "JULIAHUB_PROJECT_UUID")
45+
return nothing
46+
end
47+
2348
# The following setup function is reused in both at-setup blocks, but also in
2449
# doctestsetup.
2550
function setup_job_results_file!()
@@ -65,6 +90,7 @@ const PAGES_REFERENCE = [
6590
"reference/job-submission.md",
6691
"reference/jobs.md",
6792
"reference/datasets.md",
93+
"reference/projects.md",
6894
"reference/exceptions.md",
6995
]
7096
Mocking.apply(mocking_patch) do

docs/src/guides/authentication.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ When working with JuliaHub.jl in JuliaHub cloud environment, such as in JuliaHub
4343
The `JULIA_PKG_SERVER` should always be correctly set up, and the `auth.toml` file will also be present and up-to-date.
4444
This means that [`authenticate`](@ref) should automatically be able to authenticate your session, and you should never be prompted for interactive authentication.
4545

46+
This also extends to JuliaHub Projects support --- if an IDE has been launched withing the context of a project, the environment will have the `JULIAHUB_PROJECT_UUID` environment set, and the authentication object will be automatically linked to the correct project.
47+
4648
!!! tip "No need to authenticate()"
4749

4850
As in a JuliaHub environment everything is already set up and pointing to the correct server, you do not need to call [`authenticate`](@ref) yourself, nor set up `JULIA_PKG_SERVER`.

docs/src/reference/datasets.md

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,16 @@ The versions are indexed with a linear list of integers starting from `1`.
4141
## Reference
4242

4343
```@docs
44-
JuliaHub.Dataset
45-
JuliaHub.DatasetVersion
46-
JuliaHub.datasets
47-
JuliaHub.DatasetReference
48-
JuliaHub.dataset
49-
JuliaHub.download_dataset
50-
JuliaHub.upload_dataset
51-
JuliaHub.update_dataset
52-
JuliaHub.delete_dataset
44+
Dataset
45+
DatasetVersion
46+
datasets
47+
DatasetReference
48+
dataset
49+
download_dataset
50+
upload_dataset
51+
update_dataset
52+
delete_dataset
53+
DatasetProjectLink
5354
```
5455

5556
## Index

docs/src/reference/exceptions.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ InvalidRequestError
2424
JuliaHubConnectionError
2525
JuliaHubError
2626
PermissionError
27+
ProjectNotSetError
28+
InvalidJuliaHubVersion
2729
```
2830

2931
## Index

docs/src/reference/projects.md

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
```@meta
2+
CurrentModule=JuliaHub
3+
```
4+
5+
# Projects
6+
7+
These APIs allow you to interact with datasets that have been attached to projects.
8+
9+
* [`project_datasets`](@ref) and [`project_dataset`](@ref) let you list and access datasets linked to a project
10+
* [`upload_project_dataset`](@ref) allows uploading new versions of project-linked datasets
11+
12+
## Automatic project authentication
13+
14+
The [`Authentication`](@ref) object can be associated with a default project UUID, which will
15+
then be used to for all _project_ operations, unless an explicit `project` gets passed to
16+
override the default.
17+
18+
Importantly, [`JuliaHub.authenticate`](@ref) will automatically pick up the the JuliaHub
19+
project UUID from the `JULIAHUB_PROJECT_UUID` environment variable. This means in JuliaHub
20+
cloud jobs and IDEs, it is not necessary to manually set the project, and JuliaHub.jl
21+
will automatically.
22+
However, you can opt-out of this behavior by explicitly passing a `project=nothing` to
23+
[`JuliaHub.authenticate`](@ref).
24+
25+
You can always verify that your operations are running in the context of the correct project
26+
by checking the [`Authentication`](@ref) object, e.g. via [`current_authentication`](@ref):
27+
28+
```jldoctest; setup = :(using JuliaHub; Main.projectauth_setup!()), teardown = :(Main.projectauth_teardown!())
29+
julia> JuliaHub.current_authentication()
30+
JuliaHub.Authentication("https://juliahub.com", "username", *****; project_id = "cd6c9ee3-d15f-414f-a762-7e1d3faed835")
31+
```
32+
33+
## Reference
34+
35+
```@docs
36+
project_datasets
37+
project_dataset
38+
upload_project_dataset
39+
ProjectReference
40+
```
41+
42+
## Index
43+
44+
```@index
45+
Pages = ["project_datasets.md"]
46+
```

src/JuliaHub.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import SHA
1111
import TimeZones
1212
import TOML
1313
import URIs
14-
import UUIDs
14+
using UUIDs: UUIDs, UUID
1515

1616
# We cache the local timezone in a global, so that we don't have to call
1717
# TimeZones.localzone() every time we do a TZ operation. However, we only
@@ -34,6 +34,7 @@ include("jobs/request.jl")
3434
include("jobs/logging.jl")
3535
include("jobs/logging-kafka.jl")
3636
include("jobs/logging-legacy.jl")
37+
include("projects.jl")
3738

3839
# JuliaHub.jl follows the convention that all private names are
3940
# prefixed with an underscore.

0 commit comments

Comments
 (0)