Skip to content

Commit

Permalink
Fix documenting of custom agent type.
Browse files Browse the repository at this point in the history
Using `define_agent`, if an agent is defined
in `__module`, we also point `Core.@__doc__` to
document the type inside that module.
  • Loading branch information
thevolatilebit committed Feb 22, 2024
1 parent dccb8fb commit 7b8a63a
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 40 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/CompatHelper.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
- name: Install Julia, but only if it is not already available in the PATH
uses: julia-actions/setup-julia@v1
with:
version: '1.8'
version: '1.9'
arch: ${{ runner.arch }}
if: steps.julia_in_path.outcome != 'success'
- name: "Add the General registry via Git"
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/Documenter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
- uses: actions/checkout@v3
- uses: julia-actions/setup-julia@latest
with:
version: '1.8'
version: '1.10'
- uses: actions/cache@v3
env:
cache-name: cache-artifacts
Expand Down
46 changes: 20 additions & 26 deletions .github/workflows/Formatter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,30 +7,24 @@ on:
pull_request:
jobs:
build:
runs-on: ${{ matrix.os }}
strategy:
matrix:
julia-version: [1]
julia-arch: [x86]
os: [ubuntu-latest]
runs-on: ubuntu-latest
steps:
- uses: julia-actions/setup-julia@latest
with:
version: ${{ matrix.julia-version }}

- uses: actions/checkout@v3
- name: Install JuliaFormatter and format
run: |
julia -e 'using Pkg; Pkg.add(PackageSpec(name="JuliaFormatter"))'
julia -e 'using JuliaFormatter; format(".", verbose=true)'
- name: Format check
run: |
julia -e '
out = Cmd(`git diff --name-only`) |> read |> String
if out == ""
exit(0)
else
@error "Some files have not been formatted !!!"
write(stdout, out)
exit(1)
end'
- uses: julia-actions/setup-julia@latest
with:
version: '1.10'
- uses: actions/checkout@v3
- name: Install JuliaFormatter and format
run: |
julia -e 'using Pkg; Pkg.add(PackageSpec(name="JuliaFormatter"))'
julia -e 'using JuliaFormatter; format(".", verbose=true)'
- name: Format check
run: |
julia -e '
out = Cmd(`git diff --name-only`) |> read |> String
if out == ""
exit(0)
else
@error "Some files have not been formatted !!!"
write(stdout, out)
exit(1)
end'
2 changes: 1 addition & 1 deletion .github/workflows/Tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
strategy:
fail-fast: false
matrix:
julia_version: ['1.8']
julia_version: ['1.9', '1.10']
os: [ubuntu-latest]
steps:
- uses: actions/checkout@v3
Expand Down
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "AlgebraicAgents"
uuid = "f6eb0ae3-10fa-40e6-88dd-9006ba45093a"
version = "0.3.22"
version = "0.3.23"

[deps]
Crayons = "a8cc5b0e-0ffa-5ad4-8c14-923d3ee1735f"
Expand Down
3 changes: 2 additions & 1 deletion src/agents.jl
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,12 @@ function define_agent(base_type, super_type, type, __module, constructor)
$$(QuoteNode(constructor))
end
end

# it is important to evaluate the macro in the module of the toplevel eval
Base.eval($__module, expr)
end

Core.@__doc__($(esc(Docs.namify(new_name))))
Core.@__doc__($__module.$(Docs.namify(new_name)))
nothing
end
end
Expand Down
14 changes: 8 additions & 6 deletions src/queries.jl
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,12 @@ Run filter query on agents in a hierarchy.
filter(agent, f"_.age > 21 && _.name ∈ ['a', 'b']") # filter query
```
"""
function Base.filter(a::AbstractAlgebraicAgent, queries::Vararg{<:FilterQuery})
function Base.filter(a::AbstractAlgebraicAgent, queries::Vararg{FilterQuery})
filter(collect(values(flatten(a))), queries...)
end

function Base.filter(a::Vector{<:AbstractAlgebraicAgent},
queries::Vararg{<:FilterQuery})
queries::Vararg{FilterQuery})
filtered = AbstractAlgebraicAgent[]
for a in a
all(q -> _filter(a, q), queries) && push!(filtered, a)
Expand Down Expand Up @@ -139,8 +139,10 @@ Accepts both anonymous queries (`_.name`) and named queries (`name=_.name`). By
"""
macro transform(exs...)
n_noname::Int = 0
queries = map(ex -> Meta.isexpr(ex, :(=)) ? (ex.args[1], ex.args[2]) :
(n_noname += 1; ("query_$n_noname", ex)), exs)
queries = map(
ex -> Meta.isexpr(ex, :(=)) ? (ex.args[1], ex.args[2]) :
(n_noname += 1; ("query_$n_noname", ex)),
exs)
names, queries = map(x -> x[1], queries), map(x -> x[2], queries)
quote
queries = TransformQuery.($(names),
Expand All @@ -165,12 +167,12 @@ agent |> @transform(name=_.name)
agent |> @transform(name=_.name, _.age)
```
"""
function transform(a::AbstractAlgebraicAgent, queries::Vararg{<:TransformQuery})
function transform(a::AbstractAlgebraicAgent, queries::Vararg{TransformQuery})
transform(collect(values(flatten(a))), queries...)
end

function transform(a::Vector{<:AbstractAlgebraicAgent},
queries::Vararg{<:TransformQuery})
queries::Vararg{TransformQuery})
results = []
for a in a
try
Expand Down
8 changes: 5 additions & 3 deletions test/agents.jl
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,8 @@ end
system_dump = AlgebraicAgents.save(system)

@test system_dump == Dict{String, Any}("name" => "diagram",
"inners" => Dict{String, Any}[Dict("name" => "agent1",
"inners" => Dict{String, Any}[
Dict("name" => "agent1",
"arguments" => [1],
"type" => MyAgentLoadsave),
Dict("name" => "agent2", "arguments" => [2], "type" => MyAgentLoadsave)],
Expand All @@ -123,8 +124,9 @@ end
agent1 = inners(system_reloaded)["agent1"]
@test agent1 isa MyAgentLoadsave

opera_dump = Dict("instantious" => [
Dict("call" => () -> println("instantious interaction")),
opera_dump = Dict(
"instantious" => [
Dict("call" => () -> println("instantious interaction"))
],
"futures" => [Dict("time" => 2.0, "call" => () -> println("future"))],
"controls" => [Dict("call" => () -> println("control"))])
Expand Down

0 comments on commit 7b8a63a

Please sign in to comment.