Skip to content

Commit 7ffcc45

Browse files
Fix documenting of custom agent type.
Using `define_agent`, if an agent is defined in `__module`, we also point `Core.@__doc__` to document the type inside that module.
1 parent dccb8fb commit 7ffcc45

File tree

8 files changed

+39
-40
lines changed

8 files changed

+39
-40
lines changed

.github/workflows/CompatHelper.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ jobs:
1717
- name: Install Julia, but only if it is not already available in the PATH
1818
uses: julia-actions/setup-julia@v1
1919
with:
20-
version: '1.8'
20+
version: '1.9'
2121
arch: ${{ runner.arch }}
2222
if: steps.julia_in_path.outcome != 'success'
2323
- name: "Add the General registry via Git"

.github/workflows/Documenter.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414
- uses: actions/checkout@v3
1515
- uses: julia-actions/setup-julia@latest
1616
with:
17-
version: '1.8'
17+
version: '1.10'
1818
- uses: actions/cache@v3
1919
env:
2020
cache-name: cache-artifacts

.github/workflows/Formatter.yml

Lines changed: 20 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -7,30 +7,24 @@ on:
77
pull_request:
88
jobs:
99
build:
10-
runs-on: ${{ matrix.os }}
11-
strategy:
12-
matrix:
13-
julia-version: [1]
14-
julia-arch: [x86]
15-
os: [ubuntu-latest]
10+
runs-on: ubuntu-latest
1611
steps:
17-
- uses: julia-actions/setup-julia@latest
18-
with:
19-
version: ${{ matrix.julia-version }}
20-
21-
- uses: actions/checkout@v3
22-
- name: Install JuliaFormatter and format
23-
run: |
24-
julia -e 'using Pkg; Pkg.add(PackageSpec(name="JuliaFormatter"))'
25-
julia -e 'using JuliaFormatter; format(".", verbose=true)'
26-
- name: Format check
27-
run: |
28-
julia -e '
29-
out = Cmd(`git diff --name-only`) |> read |> String
30-
if out == ""
31-
exit(0)
32-
else
33-
@error "Some files have not been formatted !!!"
34-
write(stdout, out)
35-
exit(1)
36-
end'
12+
- uses: julia-actions/setup-julia@latest
13+
with:
14+
version: '1.10'
15+
- uses: actions/checkout@v3
16+
- name: Install JuliaFormatter and format
17+
run: |
18+
julia -e 'using Pkg; Pkg.add(PackageSpec(name="JuliaFormatter"))'
19+
julia -e 'using JuliaFormatter; format(".", verbose=true)'
20+
- name: Format check
21+
run: |
22+
julia -e '
23+
out = Cmd(`git diff --name-only`) |> read |> String
24+
if out == ""
25+
exit(0)
26+
else
27+
@error "Some files have not been formatted !!!"
28+
write(stdout, out)
29+
exit(1)
30+
end'

.github/workflows/Tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ jobs:
1111
strategy:
1212
fail-fast: false
1313
matrix:
14-
julia_version: ['1.8']
14+
julia_version: ['1.9', '1.10']
1515
os: [ubuntu-latest]
1616
steps:
1717
- uses: actions/checkout@v3

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "AlgebraicAgents"
22
uuid = "f6eb0ae3-10fa-40e6-88dd-9006ba45093a"
3-
version = "0.3.22"
3+
version = "0.3.23"
44

55
[deps]
66
Crayons = "a8cc5b0e-0ffa-5ad4-8c14-923d3ee1735f"

src/agents.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,12 @@ function define_agent(base_type, super_type, type, __module, constructor)
4444
$$(QuoteNode(constructor))
4545
end
4646
end
47+
4748
# it is important to evaluate the macro in the module of the toplevel eval
4849
Base.eval($__module, expr)
4950
end
5051

51-
Core.@__doc__($(esc(Docs.namify(new_name))))
52+
Core.@__doc__($__module.$(Docs.namify(new_name)))
5253
nothing
5354
end
5455
end

src/queries.jl

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -80,12 +80,12 @@ Run filter query on agents in a hierarchy.
8080
filter(agent, f"_.age > 21 && _.name ∈ ['a', 'b']") # filter query
8181
```
8282
"""
83-
function Base.filter(a::AbstractAlgebraicAgent, queries::Vararg{<:FilterQuery})
83+
function Base.filter(a::AbstractAlgebraicAgent, queries::Vararg{FilterQuery})
8484
filter(collect(values(flatten(a))), queries...)
8585
end
8686

8787
function Base.filter(a::Vector{<:AbstractAlgebraicAgent},
88-
queries::Vararg{<:FilterQuery})
88+
queries::Vararg{FilterQuery})
8989
filtered = AbstractAlgebraicAgent[]
9090
for a in a
9191
all(q -> _filter(a, q), queries) && push!(filtered, a)
@@ -139,8 +139,10 @@ Accepts both anonymous queries (`_.name`) and named queries (`name=_.name`). By
139139
"""
140140
macro transform(exs...)
141141
n_noname::Int = 0
142-
queries = map(ex -> Meta.isexpr(ex, :(=)) ? (ex.args[1], ex.args[2]) :
143-
(n_noname += 1; ("query_$n_noname", ex)), exs)
142+
queries = map(
143+
ex -> Meta.isexpr(ex, :(=)) ? (ex.args[1], ex.args[2]) :
144+
(n_noname += 1; ("query_$n_noname", ex)),
145+
exs)
144146
names, queries = map(x -> x[1], queries), map(x -> x[2], queries)
145147
quote
146148
queries = TransformQuery.($(names),
@@ -165,12 +167,12 @@ agent |> @transform(name=_.name)
165167
agent |> @transform(name=_.name, _.age)
166168
```
167169
"""
168-
function transform(a::AbstractAlgebraicAgent, queries::Vararg{<:TransformQuery})
170+
function transform(a::AbstractAlgebraicAgent, queries::Vararg{TransformQuery})
169171
transform(collect(values(flatten(a))), queries...)
170172
end
171173

172174
function transform(a::Vector{<:AbstractAlgebraicAgent},
173-
queries::Vararg{<:TransformQuery})
175+
queries::Vararg{TransformQuery})
174176
results = []
175177
for a in a
176178
try

test/agents.jl

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,8 @@ end
100100
system_dump = AlgebraicAgents.save(system)
101101

102102
@test system_dump == Dict{String, Any}("name" => "diagram",
103-
"inners" => Dict{String, Any}[Dict("name" => "agent1",
103+
"inners" => Dict{String, Any}[
104+
Dict("name" => "agent1",
104105
"arguments" => [1],
105106
"type" => MyAgentLoadsave),
106107
Dict("name" => "agent2", "arguments" => [2], "type" => MyAgentLoadsave)],
@@ -123,8 +124,9 @@ end
123124
agent1 = inners(system_reloaded)["agent1"]
124125
@test agent1 isa MyAgentLoadsave
125126

126-
opera_dump = Dict("instantious" => [
127-
Dict("call" => () -> println("instantious interaction")),
127+
opera_dump = Dict(
128+
"instantious" => [
129+
Dict("call" => () -> println("instantious interaction"))
128130
],
129131
"futures" => [Dict("time" => 2.0, "call" => () -> println("future"))],
130132
"controls" => [Dict("call" => () -> println("control"))])

0 commit comments

Comments
 (0)