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

Not getting access to functions as expected #111

Open
hbsmith opened this issue Sep 8, 2022 · 2 comments
Open

Not getting access to functions as expected #111

hbsmith opened this issue Sep 8, 2022 · 2 comments

Comments

@hbsmith
Copy link

hbsmith commented Sep 8, 2022

(Originally this was created as an issue in the InteractiveDynamics repo, but the issue might be with requires so I'm reposting here):

I have a MWE where I would expect to get access to the agents/ functions from InteractiveDynamics, but for some reason they don't get loaded.

The main InteractiveDynamics.jl src file looks like this:

module InteractiveDynamics

using Makie, Observables, OSMMakie

include("colors.jl")
include("utils.jl")
using Requires

function __init__()
    @require DynamicalSystems = "61744808-ddfa-5f27-97ff-6e42cc95d634" begin
        # include("numericdata/plot_dataset.jl")
        # include("numericdata/trajectory_highlighter.jl")
        include("chaos/orbitdiagram.jl")
        include("chaos/poincareclick.jl")
        include("chaos/trajanim.jl")
        include("chaos/cobweb.jl")
        include("chaos/brainscan.jl")
    end
    @require DynamicalBilliards = "4986ee89-4ee5-5cef-b6b8-e49ba721d7a5" begin
        include("billiards/defs_plotting.jl")
        include("billiards/defs_animating.jl")
        include("billiards/premade_anim_functions.jl")
        include("billiards/exports.jl")
    end
    @require Agents = "46ada45e-f475-11e8-01d0-f70cc89e6671" begin
        include("agents/abmplot.jl")
        include("agents/lifting.jl")
        include("agents/interaction.jl")
        include("agents/inspection.jl")
        include("agents/convenience.jl")
        include("agents/deprecations.jl")
    end
end

end

If I generate a new package "TestMod", activate the environment, and add only "InteractiveDynamics" and "Agents", I get a Project.toml that looks like this:

name = "TestMod"
uuid = "43a1a35d-8048-4c0f-b05e-6c9f886ced7d"
authors = ["me <me@myemail.com>"]
version = "0.1.0"

[deps]
Agents = "46ada45e-f475-11e8-01d0-f70cc89e6671"
InteractiveDynamics = "ec714cd0-5f51-11eb-0b6e-452e7367ff84"

Then if my TestMod.jl file is simply:

module TestMod;

using Agents
using InteractiveDynamics

@show(names(InteractiveDynamics, all=true))

import InteractiveDynamics.agent2string

end

And I run:

(@v1.8) pkg> activate .
julia> using TestMod

[ Info: Precompiling TestMod [43a1a35d-8048-4c0f-b05e-6c9f886ced7d]
names(InteractiveDynamics, all = true) = [Symbol("##meta#58"), Symbol("##record_interaction#1"), Symbol("##record_interaction#4"), Symbol("#10#19"), Symbol("#11#20"), Symbol("#12#21"), Symbol("#13#22"), Symbol("#14#23"), Symbol("#15#24"), Symbol("#16#25"), Symbol("#17#26"), Symbol("#2#3"), Symbol("#5#6"), Symbol("#7#8"), Symbol("#9#18"), Symbol("#__init__"), Symbol("#colors_from_map"), Symbol("#darken_color"), Symbol("#eval"), Symbol("#get_value"), Symbol("#has_key"), Symbol("#include"), Symbol("#lighten_color"), Symbol("#pushupdate!"), Symbol("#randomcolor"), Symbol("#record_interaction"), Symbol("#record_interaction##kw"), Symbol("#record_interaction#1"), Symbol("#record_interaction#4"), Symbol("#rotate2D"), Symbol("#scale"), Symbol("#set_value!"), Symbol("#subscript"), Symbol("#superscript"), Symbol("#to_alpha"), Symbol("#translate"), :COLORSCHEME, :CYCLIC_COLORS, :CyclicContainer, :DEFAULT_BG, :InteractiveDynamics, :JULIADYNAMICS_BLACK, :JULIADYNAMICS_CMAP, :JULIADYNAMICS_CMAP_DIVERGING, :JULIADYNAMICS_COLORS, :MARKER, :Point2f, :Polygon, :__init__, :colors_from_map, :darken_color, :eval, :get_value, :has_key, :include, :lighten_color, :pushupdate!, :randomcolor, :record_interaction, :rotate2D, :scale, :set_value!, :subscript, :superscript, :to_alpha, :translate]
WARNING: could not import InteractiveDynamics.agent2string into TestMod

I would expect to get access to all the functions within the src/agents/ files, but we can see that I don't get access to any of them.

Is this expected behavior? How can I get access to these functions from inside my "TestMod.jl" module?

Thanks

@hbsmith
Copy link
Author

hbsmith commented Sep 8, 2022

It's worth noting that if instead of trying to load the module with using, I just navigate to the directory and do

julia> include("src/TestMod.jl")

everything works as expected

@mkitti
Copy link

mkitti commented Jan 7, 2023

You might need to use @eval before the includes so that the methods are read into the top level global scope.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants