1+ """
2+ struct ProjectNotSetError <: JuliaHubException
3+
4+ Exception thrown when the authentication object is not set to a project, nor was
5+ an explicit project UUID provided, but the operation requires a project to be
6+ specified.
7+ """
8+ struct ProjectNotSetError <: JuliaHubException end
9+
10+ function Base. showerror (io:: IO , e:: ProjectNotSetError )
11+ print (io, " ProjectNotSetError: authentication object not associated with a project" )
12+ end
13+
14+ function _assert_projects_enabled (auth:: Authentication )
15+ # The different project APIs are only present in JuliaHub 6.9 and later.
16+ if auth. _api_version < v " 0.2.0"
17+ msg = " Project APIs got added in JuliaHub 6.9 (expected API version >= 0.2.0, got $(auth. _api_version) , for $(auth. server) )"
18+ throw (InvalidJuliaHubVersion (msg))
19+ end
20+ end
21+
122"""
223 struct ProjectDataset
324
425A dataset object returned by the functions that return project dataset links.
526
6- Has the same fields as [`Dataset`](@ref) plus the following fields
7- that are specific to the project-dataset link :
27+ Has the same fields as [`Dataset`](@ref) plus the following fields that are specific
28+ to project-dataset links :
829
930- `project_uuid::UUID`: identifies the project in the context of which the dataset was listed
1031- `is_writable :: Bool`: whether this dataset has been marked writable by the dataset owner
@@ -53,20 +74,20 @@ function Base.show(io::IO, ::MIME"text/plain", pd::ProjectDataset)
5374end
5475
5576"""
56- struct ProjectNotSetError <: JuliaHubException
77+ const ProjectReference :: Type
5778
58- Exception thrown when the authentication object is not set to a project, but the
59- operation is meant to take place in the context of a project.
60- """
61- struct ProjectNotSetError <: JuliaHubException end
62- function Base. showerror (io:: IO , e:: ProjectNotSetError )
63- print (io, " ProjectNotSetError: authentication object not associated with a project" )
64- end
79+ Type constraint on the argument that specifies the project in projects-related
80+ APIs that (e.g. [`project_datasets`](@ref)).
6581
82+ Presently, you can specify the project by directly passing the project UUID.
83+ The UUID should be either a string (`<: AbstractString`) or an `UUIDs.UUID` object.
84+ """
6685const ProjectReference = Union{AbstractString, UUIDs. UUID}
6786
6887# Parses the standard project::Union{ProjectReference, Nothing} we pass to
6988# project_* function into a project UUID object (or throws the appropriate error).
89+ # If project is nothing, we fall back to the project_id of the authentication object,
90+ # if present.
7091function _project_uuid (auth:: Authentication , project:: Union{ProjectReference, Nothing} ):: UUIDs.UUID
7192 if isnothing (project)
7293 if isnothing (auth. project_id)
@@ -88,17 +109,22 @@ function _project_uuid(auth::Authentication, project::Union{ProjectReference, No
88109end
89110
90111"""
91- JuliaHub.project_dataset(dataset::DatasetReference; [project::ProjectReference], [auth]) -> Dataset
112+ JuliaHub.project_dataset(dataset::DatasetReference; [project::ProjectReference], [auth]) -> ProjectDataset
113+
114+ Looks up the specified dataset among the datasets attached to the project, returning a
115+ [`ProjectDataset`](@ref) object, or throwing an [`InvalidRequestError`](@ref) if the project
116+ does not have the dataset attached.
92117
93- Looks up a dataset in the context of a project.
118+ $(_DOCS_nondynamic_datasets_object_warning)
94119"""
95120function project_dataset end
96121
97122function project_dataset (
98- dataset:: Dataset ;
123+ dataset:: Union{ Dataset, ProjectDataset} ;
99124 project:: Union{ProjectReference, Nothing} = nothing ,
100125 auth:: Authentication = __auth__ (),
101126)
127+ _assert_projects_enabled (auth)
102128 project_uuid = _project_uuid (auth, project)
103129 datasets = _project_datasets (auth, project_uuid)
104130 for project_dataset in datasets
@@ -142,9 +168,10 @@ function project_dataset(
142168end
143169
144170"""
145- JuliaHub.project_datasets([project::Union{AbstractString, UUID} ]; [auth::Authentication]) -> Vector{Dataset}
171+ JuliaHub.project_datasets([project::ProjectReference ]; [auth::Authentication]) -> Vector{Dataset}
146172
147- Returns the list of datasets linked to the given project.
173+ Returns the list of datasets attached to the project, as a list of [`ProjectDataset`](@ref) objects.
174+ If the project is not explicitly specified, it uses the project of the authentication object.
148175"""
149176function project_datasets end
150177
@@ -239,7 +266,7 @@ Uploads a new version of a project-linked dataset.
239266function upload_project_dataset end
240267
241268function upload_project_dataset (
242- ds:: Dataset ,
269+ ds:: Union{ Dataset, ProjectDataset} ,
243270 local_path:: AbstractString ;
244271 progress:: Bool = true ,
245272 project:: Union{ProjectReference, Nothing} = nothing ,
@@ -281,8 +308,16 @@ function upload_project_dataset(
281308end
282309
283310function upload_project_dataset (
284- :: Union{_DatasetRefTuple, AbstractString}
311+ dataset:: Union{_DatasetRefTuple, AbstractString} ,
312+ local_path:: AbstractString ;
313+ progress:: Bool = true ,
314+ project:: Union{ProjectReference, Nothing} = nothing ,
315+ # Authentication
316+ auth:: Authentication = __auth__ (),
285317)
318+ project_uuid = _project_uuid (auth, project)
319+ dataset = project_dataset (dataset; project= project_uuid, auth)
320+ return upload_project_dataset (dataset, local_path; progress, project= project_uuid, auth)
286321end
287322
288323# This calls the /datasets/{uuid}/versions?project={uuid} endpoint,
0 commit comments