# Adding environment to library LOAD\_PATH

**URL:** <https://discourse.julialang.org/t/adding-environment-to-library-load-path/39597>\
**Category:** General Usage\
**Tags:** question, pkg\
**Created:** [May 16, 2020, 8:54pm UTC](https://discourse.julialang.org/t/adding-environment-to-library-load-path/39597 "2020-05-16T20:54:29Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![yoh-meyers](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yoh-meyers/32/14700_2.png) [@yoh-meyers](https://discourse.julialang.org/u/yoh-meyers)\
**Post date:** [May 16, 2020, 8:54pm UTC](https://discourse.julialang.org/t/adding-environment-to-library-load-path/39597/1 "2020-05-16T20:54:29Z")

</div>

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:

```julia
┌ 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](https://docs.julialang.org/en/v1/manual/code-loading/#Conclusion-1)_”, 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

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [May 17, 2020, 5:53am UTC](https://discourse.julialang.org/t/adding-environment-to-library-load-path/39597/2 "2020-05-17T05:53:39Z")

</div>

> [@yoh-meyers](#):
>
> Am trying to load a dependency of a project into a library that project is using.

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.

---

<div class="post-metadata">

**Author:** ![yoh-meyers](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yoh-meyers/32/14700_2.png) [@yoh-meyers](https://discourse.julialang.org/u/yoh-meyers)\
**Post date:** [May 17, 2020, 8:23am UTC](https://discourse.julialang.org/t/adding-environment-to-library-load-path/39597/3 "2020-05-17T08:23:46Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [May 17, 2020, 9:40am UTC](https://discourse.julialang.org/t/adding-environment-to-library-load-path/39597/4 "2020-05-17T09:40:09Z")

</div>

> [@yoh-meyers](#):
>
> if there is other way to evaluate included Julia file without evaluating in scope of library

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.

---

<div class="post-metadata">

**Author:** ![yoh-meyers](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yoh-meyers/32/14700_2.png) [@yoh-meyers](https://discourse.julialang.org/u/yoh-meyers)\
**Post date:** [May 17, 2020, 10:19am UTC](https://discourse.julialang.org/t/adding-environment-to-library-load-path/39597/5 "2020-05-17T10:19:07Z")

</div>

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:

```julia
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

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [May 17, 2020, 12:31pm UTC](https://discourse.julialang.org/t/adding-environment-to-library-load-path/39597/6 "2020-05-17T12:31:35Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![yoh-meyers](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yoh-meyers/32/14700_2.png) [@yoh-meyers](https://discourse.julialang.org/u/yoh-meyers)\
**Post date:** [May 17, 2020, 12:55pm UTC](https://discourse.julialang.org/t/adding-environment-to-library-load-path/39597/7 "2020-05-17T12:55:44Z")

</div>

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/](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.
