From 7ffcc4598e46f772f178194ae9588865340385f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?B=C3=ADma=2C=20Jan?= Date: Thu, 22 Feb 2024 14:50:15 +0100 Subject: [PATCH] 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. --- .github/workflows/CompatHelper.yml | 2 +- .github/workflows/Documenter.yml | 2 +- .github/workflows/Formatter.yml | 46 +++++++++++++----------------- .github/workflows/Tests.yml | 2 +- Project.toml | 2 +- src/agents.jl | 3 +- src/queries.jl | 14 +++++---- test/agents.jl | 8 ++++-- 8 files changed, 39 insertions(+), 40 deletions(-) diff --git a/.github/workflows/CompatHelper.yml b/.github/workflows/CompatHelper.yml index 87ac2b2..c7f7a64 100644 --- a/.github/workflows/CompatHelper.yml +++ b/.github/workflows/CompatHelper.yml @@ -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" diff --git a/.github/workflows/Documenter.yml b/.github/workflows/Documenter.yml index 2701a45..1cb1c01 100644 --- a/.github/workflows/Documenter.yml +++ b/.github/workflows/Documenter.yml @@ -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 diff --git a/.github/workflows/Formatter.yml b/.github/workflows/Formatter.yml index 08e348f..61c3ed0 100644 --- a/.github/workflows/Formatter.yml +++ b/.github/workflows/Formatter.yml @@ -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' \ No newline at end of file + - 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' \ No newline at end of file diff --git a/.github/workflows/Tests.yml b/.github/workflows/Tests.yml index f7c7a74..f841318 100644 --- a/.github/workflows/Tests.yml +++ b/.github/workflows/Tests.yml @@ -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 diff --git a/Project.toml b/Project.toml index 203c7e2..2ec8279 100644 --- a/Project.toml +++ b/Project.toml @@ -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" diff --git a/src/agents.jl b/src/agents.jl index 88eacaa..6b9f74d 100644 --- a/src/agents.jl +++ b/src/agents.jl @@ -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 diff --git a/src/queries.jl b/src/queries.jl index 551ddce..36df44a 100644 --- a/src/queries.jl +++ b/src/queries.jl @@ -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) @@ -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), @@ -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 diff --git a/test/agents.jl b/test/agents.jl index f6a64d8..37cf04e 100644 --- a/test/agents.jl +++ b/test/agents.jl @@ -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)], @@ -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"))])