Adding environment to library LOAD_PATH

Hello,

I am possibly trying something impossible by design of Julia.

Am trying to load a dependency of a project into a library that project is using.
By trying so, I get following error:

┌ Warning: Package Dance does not have DatabaseConnector in its dependencies:
│ - If you have Dance checked out for development and have
│   added DatabaseConnector as a dependency but haven't updated your primary
│   environment's manifest file, try `Pkg.resolve()`.
│ - Otherwise you may need to report an issue with Dance
└ Loading DatabaseConnector into Dance from project dependency, future warnings for Dance are suppressed.

I read “Environment Stacks” under “Code Loading · The Julia Language”, and from my understanding this should be possible.
But is it so without above warning?

Tried populating LOAD_PATH array of libray (is my code).
Suppose I misunderstood “By adding an environment containing these tools to the load path, you immediately have access to them in top-level code without needing to add them to your project.

Any suggestion?

Thank you

I am not sure I understand what you are trying to do here.

In any case, if your package is using DatabaseConnector, just pkg> add it to that project. There should be no reason to use LOAD_PATH or anything similar. Dependencies should be explicitly declared for a project.

1 Like

Thank you for response.
Also realised now, it is due to way I structured my package Dance.jl.

As there is a file from project that gets loaded into library via include. Though I would like to evaluate file, this is wrong as include will evaluate everything in scope of library.

Basically I want to parse the included file, as Julia code.
So suppose better approach would be to ask if there is other way to evaluate included Julia file without evaluating in scope of library.

As of now believe am limited to reading file as string, unless there is other solution?

Where would you want to evaluate it then?

You can always eval(:(include("/path/to/file.jl"))) but in all likelihood you are doing something very convoluted and unnecessary instead of going for an idiomatic solution. But without some context, it is hard to be more specific.

Instead of asking how to do something, it would be better if you told us what you are trying to do.

1 Like

Sure, let me explain.

Idea is to launch web library by calling julia dance.jl from terminal.
The dance.jl file contains Dance.populate_router(abspath(@__DIR__)) command which in turn calls:

function populate_router(file_path::String) :: Bool
    return Router.populate(file_path)
end

function populate(file_path::String) :: Bool
    is_success::Bool = false
    routes_filepath::String = joinpath(file_path, Configuration.Settings[:routes_filename]*".jl")

    if isfile(routes_filepath)
        include(routes_filepath)
        is_success = true
    else
        @error "Populating Routes: file not found at $routes_filepath"
    end

    return is_success
end

Items under routes.jl follow structure of: route("/", index; method=GET, endpoint=HTML).
Hence arguments are: path, function to call, HTTP method and endpoint type (JSON/HTML).
Issue lies with imported items in this file.
Above is to have populated OrderedDict of routes that is populated on startup.

I am trying to make integrating existing code base with web library as smooth as possible.
Hence moving all abstraction to library, with minimum number of files for user (in case of library update will be smoother than telling user has to update multiple files in their project).
Also allows me to integrate async functionality in web library backend.

Hence my issue of parsing the project’s routes.jl file in library itself.
Thanks again

I am still not sure I understand the problem, but it looks like you are reading data as executed code. Perhaps you could externalize it and read it as data?

Yes the code is executed in project itself, I am indeed reading executed code when populating OrderedDict of routes of Dance.jl lib.
This as I link the route functions that will be called when route is accessed.

Let me explain better.
For example, with route("/", index; method=GET, endpoint=HTML) under project’s route.jl, populate_router called during startup will populate library’s routes OrderedDict with 1 entry.
So when accessing “http://localhost:8000/” in browser library will call index function.

Idea is to link route paths to functions that are called when path is accessed.
But entries under project’s route.jl can of course depend on other modules/libraries.

But yes, I will read data as string when performing startup procedure.