Skip to content

Commit

Permalink
Merge pull request #152 from JuliaAI/dev
Browse files Browse the repository at this point in the history
For a 1.4.4 release
  • Loading branch information
ablaom authored Jul 6, 2022
2 parents fe70185 + f18bd47 commit f6432bc
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 9 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "MLJModelInterface"
uuid = "e80e1ace-859a-464e-9ed9-23947d8ae3ea"
authors = ["Thibaut Lienart and Anthony Blaom"]
version = "1.4.3"
version = "1.4.4"

[deps]
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
Expand Down
24 changes: 16 additions & 8 deletions src/metadata_utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,12 @@ function metadata_pkg(
package_license=license,
)
ex = quote
MLJModelInterface.package_name(::Type{<:$T}) = $package_name
MLJModelInterface.package_uuid(::Type{<:$T}) = $package_uuid
MLJModelInterface.package_url(::Type{<:$T}) = $package_url
MLJModelInterface.is_pure_julia(::Type{<:$T}) = $is_pure_julia
MLJModelInterface.package_license(::Type{<:$T}) = $package_license
MLJModelInterface.is_wrapper(::Type{<:$T}) = $is_wrapper
$MLJModelInterface.package_name(::Type{<:$T}) = $package_name
$MLJModelInterface.package_uuid(::Type{<:$T}) = $package_uuid
$MLJModelInterface.package_url(::Type{<:$T}) = $package_url
$MLJModelInterface.is_pure_julia(::Type{<:$T}) = $is_pure_julia
$MLJModelInterface.package_license(::Type{<:$T}) = $package_license
$MLJModelInterface.is_wrapper(::Type{<:$T}) = $is_wrapper
end
parentmodule(T).eval(ex)
end
Expand All @@ -59,14 +59,20 @@ end
function _extend!(program::Expr, trait::Symbol, value, T)
if value !== nothing
push!(program.args, quote
MLJModelInterface.$trait(::Type{<:$T}) = $value
$MLJModelInterface.$trait(::Type{<:$T}) = $value
end)
return nothing
end
end

const DEPWARN_DOCSTRING =
"`metadata_model` should not be called with the keyword argument "*
"`descr` or `docstring`. Implementers of the MLJ model interface "*
"should instead create an MLJ-compliant docstring in the usual way. "*
"See https://alan-turing-institute.github.io/MLJ.jl/dev/adding_models_for_general_use/#Document-strings for details. "

"""
metadata_model(`T`; args...)
metadata_model(T; args...)
Helper function to write the metadata for a model `T`.
Expand All @@ -78,6 +84,7 @@ Helper function to write the metadata for a model `T`.
* `supports_weights=false`: whether the model supports sample weights
* `supports_class_weights=false`: whether the model supports class weights
* `load_path="unknown"`: where the model is (usually `PackageName.ModelName`)
* `human_name=nothing`: human name of the model
## Example
Expand Down Expand Up @@ -110,6 +117,7 @@ function metadata_model(
load_path::Union{Nothing,String}=path,
human_name::Union{Nothing,String}=nothing
)
docstring === nothing || Base.depwarn(DEPWARN_DOCSTRING, :metadata_model)

program = quote end

Expand Down
11 changes: 11 additions & 0 deletions test/data_utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -318,3 +318,14 @@ end
@test_throws M.InterfaceError UnivariateFinite(Dict(2=>3, 3=>4))
@test_throws M.InterfaceError UnivariateFinite(randn(2), randn(2))
end

@testset "not assuming MLJModelInterface symbol at user-side" begin
eval(:(module UserSide
import MLJModelInterface: metadata_model, metadata_pkg
struct A end
descr = "something"
# Smoke tests.
metadata_model(A; descr=descr)
metadata_pkg(A)
end))
end

0 comments on commit f6432bc

Please sign in to comment.