Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add InterfacesCore subpackage #39

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all 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
9 changes: 9 additions & 0 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,15 @@ jobs:
arch: ${{ matrix.arch }}
- uses: julia-actions/cache@v1
- uses: julia-actions/julia-buildpkg@v1
- name: Install Julia dependencies
shell: julia --project=./ {0}
run: |
using Pkg;
# dev sub packages
pkg"dev . ./BaseInterfaces ./InterfacesCore"
- name: Run InterfacesCore tests
run: julia --project=InterfacesCore -e 'using Pkg; pkg"dev ."; pkg"update"; pkg"test"'
shell: bash
- uses: julia-actions/julia-runtest@v1
- name: Run BaseInterfaces tests
run: julia --project=BaseInterfaces -e 'using Pkg; pkg"dev ."; pkg"update"; pkg"test"'
Expand Down
8 changes: 6 additions & 2 deletions .github/workflows/Documentation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,12 @@ jobs:
- uses: julia-actions/setup-julia@v1
with:
version: '1'
- name: Install dependencies
run: julia --project=docs/ -e 'using Pkg; pkg"dev ."; pkg"dev ./BaseInterfaces"; Pkg.instantiate()'
- name: Install Julia dependencies
shell: julia --project=docs/
run: |
using Pkg;
# dev sub packages
pkg"dev . ./BaseInterfaces ./InterfacesCore"
- name: Build and deploy
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # If authenticating with GitHub Actions token
Expand Down
21 changes: 21 additions & 0 deletions InterfacesCore/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2024 Rafael Schouten <rafaelschouten@gmail.com>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
14 changes: 14 additions & 0 deletions InterfacesCore/Project.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name = "InterfacesCore"
uuid = "a94bad63-e719-4205-a4a7-d6d26991555a"
authors = ["Rafael Schouten <rafaelschouten@gmail.com>"]
version = "0.1"

[compat]
Test = "1"
julia = "1.6"

[extras]
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[targets]
test = ["Test"]
36 changes: 36 additions & 0 deletions InterfacesCore/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# BaseInterfaces

[![Stable](https://img.shields.io/badge/docs-stable-blue.svg)](https://rafaqz.github.io/Interfaces.jl/stable/)
[![Dev](https://img.shields.io/badge/docs-dev-blue.svg)](https://rafaqz.github.io/Interfaces.jl/dev/)
[![Build Status](https://github.com/rafaqz/Interfaces.jl/actions/workflows/CI.yml/badge.svg?branch=main)](https://github.com/rafaqz/Interfaces.jl/actions/workflows/CI.yml?query=branch%3Amain)
[![Coverage](https://codecov.io/gh/rafaqz/Interfaces.jl/branch/main/graph/badge.svg)](https://codecov.io/gh/rafaqz/Interfaces.jl)

BaseInterfaces.jl is a subpackage of Interfaces.jl that provides predifined
definition and testing for Base Julia interfaces.

Currently this includes:
- A general iteration interface: `IterationInterface`
- `AbstractArray` interface: `ArrayInterface`
- `AbstractSet` interface: `SetInterface`
- `AbstractDict` interface: `DictInterface`


Testing your object follows the interfaces is as simple as:

```julia
using BaseInterfaces, Interfaces
Interfaces.tests(DictInterface, MyDict, [mydict1, mydict2, ...])
```

Declaring that it follows the interface is done with:

```julia
@implements DictInterface{(:component1, :component2)} MyDict
```

Where components can be chosen from `Interfaces.optional_keys(DictInterface)`.

See [the docs](https://rafaqz.github.io/Interfaces.jl/stable/) for use.

If you want to add more Base julia interfaces here, or think the existing
ones could be improved, please make an issue or pull request.
29 changes: 29 additions & 0 deletions InterfacesCore/src/InterfacesCore.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
module InterfacesCore

export Interface, requiredtype, @interface_type

"""
requiredtype(::Type{<:Interface})

Returns the supertype required for all interface implementations.
"""
function requiredtype end

"""
Interface{Components}

Abstract supertype for all Interfaces.jl interfaces.

Components is an `Tuple` of `Symbol`.
"""

abstract type Interface{Components} end

macro interface_core(interface::Symbol, type)
quote
@assert $type isa Type
abstract type $interface{Components} <: $InterfacesCore.Interface{Components} end
end |> esc
end

end
4 changes: 4 additions & 0 deletions InterfacesCore/test/runtests.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
using InterfacesCore, Test

@interface_core TestInterface
@test TestInterface <: Interface
7 changes: 7 additions & 0 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,14 @@ uuid = "85a1e053-f937-4924-92a5-1367d23b7b87"
authors = ["Rafael Schouten <rafaelschouten@gmail.com>"]
version = "0.3.0"

[deps]
InterfacesCore = "a94bad63-e719-4205-a4a7-d6d26991555a"

[compat]
Aqua = "0.8"
Documenter = "1"
InterfacesCore = "0.1"
Test = "1"
julia = "1.6"

[extras]
Expand Down
2 changes: 2 additions & 0 deletions src/Interfaces.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ A Julia package for specifying and testing interfaces (conditions verified by a
"""
module Interfaces

using InterfacesCore

export Arguments
export @implements, @interface

Expand Down
26 changes: 6 additions & 20 deletions src/interface.jl
Original file line number Diff line number Diff line change
@@ -1,13 +1,4 @@

"""
Interface{Components}

Abstract supertype for all Interfaces.jl interfaces.

Components is an `Tuple` of `Symbol`.
"""
abstract type Interface{Components} end

"""
optional_keys(T::Type{<:Interface}, O::Type)

Expand Down Expand Up @@ -42,13 +33,6 @@ Returns the components of the interface, as a `NamedTuple` of `NamedTuple`.
"""
function components end

"""
requiredtype(::Type{<:Interface})

Returns the supertype required for all interface implementations.
"""
function requiredtype end

"""
@interface(interfacename, components, [description])

Expand All @@ -67,15 +51,17 @@ description = "A description of the interface"
@interface MyInterface Any components description
```
"""
macro interface(interface::Symbol, type, components, description)
macro interface(interface::Symbol, type, components, description="")
quote
@assert $type isa Type
@assert $components isa NamedTuple{(:mandatory,:optional)}
@assert $description isa String
# Define the interface type (should it be concrete?)
abstract type $interface{Components} <: $Interfaces.Interface{Components} end
# Define the interface type if its for the local scope
if $interface isa Symbol
abstract type $interface{Components} <: $InterfacesCore.Interface{Components} end
end
# Define the interface component methods
$Interfaces.requiredtype(::Type{<:$interface}) = $type
$InterfacesCore.requiredtype(::Type{<:$interface}) = $type
$Interfaces.components(::Type{<:$interface}) = $components
$Interfaces.description(::Type{<:$interface}) = $description
# Generate a docstring for the interface
Expand Down
1 change: 0 additions & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ using Aqua
using Documenter
using Interfaces
using Test
using Aqua

@testset verbose = true "Interfaces.jl" begin
# Formal tests
Expand Down
Loading