From 60d69b293659c6bc380dde55c4808384e4977191 Mon Sep 17 00:00:00 2001 From: Daniel Loos Date: Wed, 11 Sep 2024 14:43:13 +0200 Subject: [PATCH 1/4] Fix optional and required args --- src/Processes.jl | 39 +++++++++++++++++++++++---------------- 1 file changed, 23 insertions(+), 16 deletions(-) diff --git a/src/Processes.jl b/src/Processes.jl index 84e0c4a..18d5bba 100644 --- a/src/Processes.jl +++ b/src/Processes.jl @@ -27,21 +27,25 @@ struct Process experimental::Union{Nothing,Bool} end StructTypes.StructType(::Type{Process}) = StructTypes.Struct() -function (process::Process)(args...) - params = get_parameters(process.parameters) - length(args) == length(params) || throw(ArgumentError("Number of arguments does not match for process $(process.id)")) - argument_dict = Dict{Symbol,Any}() - for i in 1:length(args) - argname, argtype = params[i] - args[i] isa argtype || throw(ArgumentError("Type of argument number $i does not match, expected $argtype but got $(typeof(args[i]))")) - argument_dict[argname] = args[i] + +function (process::Process)(args...; kwargs...) + required_args = get_parameters(process.parameters, :required) + + length(required_args) == length(args) || error("Must provide $(length(required_args)) positional arguments") + + args_d = Dict{Symbol,Any}(zip(map(x -> x.first, required_args), args)) + merge!(args_d, Dict(kwargs)) + + if isnothing(args_d) + args_d = Dict{Symbol,Any}() end - ProcessCall("$(process.id)", argument_dict) + ProcessCall("$(process.id)", args_d) end + function Docs.getdoc(process::Process) - arguments = get_parameters(process.parameters) - args_str = join(["$(k)::$(v)" for (k, v) in arguments], ", ") - docs = """ $(process.id)($(args_str)) + args_str = join(["$(k)::$(v)" for (k, v) in get_parameters(process.parameters, :required)], ", ") + kwargs_str = join(["$(k)::$(v)" for (k, v) in get_parameters(process.parameters, :optional)], ", ") + docs = """ $(process.id)($(args_str); $(kwargs_str)) $(process.description) """ Markdown.parse(docs) @@ -49,7 +53,9 @@ end Base.Docs.doc(p::Process, ::Type=Union{}) = Base.Docs.getdoc(p) function Base.show(io::IO, ::MIME"text/plain", p::Process) - print(io, "$(p.id)($(join([x.name for x in p.parameters], ", "))): $(p.summary)") + args_str = join(["$(k)::$(v)" for (k, v) in get_parameters(p.parameters, :required)], ", ") + kwargs_str = join(["$(k)::$(v)" for (k, v) in get_parameters(p.parameters, :optional)], ", ") + print(io, "$(p.id)($(args_str); $(kwargs_str)): $(p.summary)") end # root e.g. https://earthengine.openeo.org/v1.0/processes @@ -76,7 +82,6 @@ mutable struct ProcessCall <: AbstractProcessCall const arguments::Dict{Symbol,Any} result::Bool end -ProcessCall(id, process_id, arguments) = ProcessCall(id, process_id, arguments, false) StructTypes.StructType(::Type{ProcessCall}) = StructTypes.Mutable() StructTypes.excludes(::Type{ProcessCall}) = (:id,) @@ -112,7 +117,7 @@ function Base.show(io::IO, ::MIME"text/plain", p::ProcessCall) pretty_print(io, Dict(:result => p.result)) end -function get_parameters(parameters) +function get_parameters(parameters, keep=:all) # openEO type string to Julia type julia_types_map = Dict( "string" => String, @@ -145,7 +150,9 @@ function get_parameters(parameters) julia_types = [get(julia_types_map, t, String) for t in types] julia_type = Union{julia_types...} - push!(res, name => julia_type) + if keep == :all || (keep == :optional && p.optional == true) || (keep == :required && isnothing(p.optional)) + push!(res, name => julia_type) + end end return res end From 19a6b030672fb5340bda34c80da6a872b00eb9ea Mon Sep 17 00:00:00 2001 From: Daniel Loos Date: Wed, 11 Sep 2024 14:53:59 +0200 Subject: [PATCH 2/4] Adapt tests --- test/runtests.jl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/runtests.jl b/test/runtests.jl index 6373f8f..294046e 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -22,15 +22,15 @@ password = ENV["OPENEO_PASSWORD"] # test sequential workflow step1 = c2.load_collection( "COPERNICUS/S2", BoundingBox(west=16.06, south=48.06, east=16.65, north=48.35), - ["2020-01-20", "2020-01-30"], ["B10"] + ["2020-01-20", "2020-01-30"]; bands=["B10"] ) @test step1.id == "load_collection_tQ79zrFEGi8=" @test step1.process_id == "load_collection" @test Set(keys(step1.arguments)) == Set([:bands, :id, :spatial_extent, :temporal_extent]) @test step1.arguments[:bands] == ["B10"] - step2 = c2.reduce_dimension(step1, ProcessGraph("median"), "t", nothing) - step3 = c2.save_result(step2, "JPEG", Dict()) + step2 = c2.reduce_dimension(step1, ProcessGraph("median"), "t") + step3 = c2.save_result(step2, "JPEG") result = c2.compute_result(step3) @test result == "out.jpeg" From 9a590a0bff60b9e96af8a003633aaf1c7c382103 Mon Sep 17 00:00:00 2001 From: Daniel Loos Date: Wed, 11 Sep 2024 15:02:39 +0200 Subject: [PATCH 3/4] Fix docs function call load_collection --- docs/src/index.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/src/index.md b/docs/src/index.md index ad4195a..4eee4f7 100644 --- a/docs/src/index.md +++ b/docs/src/index.md @@ -23,10 +23,10 @@ password = ENV["OPENEO_PASSWORD"] c = connect("earthengine.openeo.org", "v1.0", username, password) step1 = c.load_collection( "COPERNICUS/S2", BoundingBox(west=16.06, south=48.06, east=16.65, north=48.35), - ["2020-01-01", "2020-01-31"], ["B10"] + ["2020-01-01", "2020-01-31"]; bands = ["B10"] ) -step2 = c.reduce_dimension(step1, ProcessGraph("median"), "t", nothing) -step3 = c.save_result(step2, "GTIFF-ZIP", Dict()) +step2 = c.reduce_dimension(step1, ProcessGraph("median"), "t") +step3 = c.save_result(step2, "GTIFF") path = c.compute_result(step3) ``` From a2a0f7e23b2708e67b26805665bcd25b4a25f52f Mon Sep 17 00:00:00 2001 From: Daniel Loos Date: Wed, 11 Sep 2024 15:07:46 +0200 Subject: [PATCH 4/4] Remove nightly julia from CI --- .github/workflows/CI.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index ecf4727..8fcf53d 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -31,7 +31,7 @@ jobs: matrix: version: - "1.9" - - "nightly" + - "1.10" os: - ubuntu-latest arch: