# How to reference modules from current package (v0.7)

**URL:** <https://discourse.julialang.org/t/how-to-reference-modules-from-current-package-v0-7/11454>\
**Category:** General Usage\
**Created:** [June 5, 2018, 9:41pm UTC](https://discourse.julialang.org/t/how-to-reference-modules-from-current-package-v0-7/11454 "2018-06-05T21:41:36Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![essenciary](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/essenciary/32/210469_2.png) [@essenciary](https://discourse.julialang.org/u/essenciary)\
**Post date:** [June 5, 2018, 9:41pm UTC](https://discourse.julialang.org/t/how-to-reference-modules-from-current-package-v0-7/11454/1 "2018-06-05T21:41:36Z")

</div>

This worked perfectly on v0.6 but no longer works on v0.7 and I can’t understand why.

Say I have a package, `Foo` with the following structure:

```julia
Foo/src/Foo.jl
Foo/src/Bar.jl

```

In `Foo.jl` I have

```julia
push!(LOAD_PATH, @ __DIR__ )
using Bar

```

However, `Bar` can not be found. ☹

---

<div class="post-metadata">

**Author:** ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)\
**Post date:** [June 5, 2018, 9:44pm UTC](https://discourse.julialang.org/t/how-to-reference-modules-from-current-package-v0-7/11454/2 "2018-06-05T21:44:42Z")

</div>

The typical way to do this would be

Foo.jl

```julia
include("Bar.jl")
using Bar

```

instead of messing with `LOAD_PATH`. Is there a reason for not doing that?

---

<div class="post-metadata">

**Author:** ![essenciary](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/essenciary/32/210469_2.png) [@essenciary](https://discourse.julialang.org/u/essenciary)\
**Post date:** [June 5, 2018, 10:02pm UTC](https://discourse.julialang.org/t/how-to-reference-modules-from-current-package-v0-7/11454/3 "2018-06-05T22:02:20Z")

</div>

Thanks.

Not really. I guess it just wasn’t clear to me.

Is it recommended against using `LOAD_PATH`? Why? What’s the purpose of `LOAD_PATH` if not to be used for such scenarios? And more importantly, why doesn’t it work in 0.7 anymore if the folder is added to `LOAD_PATH`?

Sorry, I’m just extremely confused about the way the dependencies are supposed to be handled now.

---

<div class="post-metadata">

**Author:** ![essenciary](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/essenciary/32/210469_2.png) [@essenciary](https://discourse.julialang.org/u/essenciary)\
**Post date:** [June 6, 2018, 7:38pm UTC](https://discourse.julialang.org/t/how-to-reference-modules-from-current-package-v0-7/11454/4 "2018-06-06T19:38:11Z")

</div>

@kristoffer.carlsson Is `LOAD_PATH` going to work again as it did in v0.6? I tried switching to `include(...)` + `using ...` but there are so many modules which are cross-referenced, it’s so redundant and just plain ugly. In v0.6 I’d just setup the `LOAD_PATH` and everything would just load, which was super neat and elegant.

---

<div class="post-metadata">

**Author:** ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)\
**Post date:** [June 6, 2018, 9:59pm UTC](https://discourse.julialang.org/t/how-to-reference-modules-from-current-package-v0-7/11454/5 "2018-06-06T21:59:21Z")

</div>

All I can say is that `LOAD_PATH` is not really supposed to be used like that. `LOAD_PATH` is a “higher level” concept meant for users to control which packages they can load but the package itself shouldn’t depend on it.

Using submodules in a package is fine but the files of the submodules should be included, as e.g. Documenter does:

[https://github.com/JuliaDocs/Documenter.jl/blob/a8a651e3bacd6380ebb2971af69a5070ad0a0a2e/src/Documenter.jl#L42-L54](https://github.com/JuliaDocs/Documenter.jl/blob/a8a651e3bacd6380ebb2971af69a5070ad0a0a2e/src/Documenter.jl#L42-L54)

---

<div class="post-metadata">

**Author:** ![essenciary](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/essenciary/32/210469_2.png) [@essenciary](https://discourse.julialang.org/u/essenciary)\
**Post date:** [June 7, 2018, 3:30pm UTC](https://discourse.julialang.org/t/how-to-reference-modules-from-current-package-v0-7/11454/6 "2018-06-07T15:30:01Z")

</div>

Thank you @kristoffer.carlsson - that’s very helpful. I started refactoring per your feedback and it’s all working very well! 😃

Just as a side-note, from my perspective, it’s a shame that `LOAD_PATH` doesn’t work for this anymore. Genie has a pretty large code base and since starting it, with Julia v0.4, I’ve spent a ridiculous amount of time organizing and optimizing the project’s structure and managing the dependencies (which are both inner package submodules and in-app, developer-generated MVC files).

The result of these multiple iterations was setting up the `LOAD_PATH` and `using Module`. Employing `LOAD_PATH` was by far the most productive approach. Without it, one has to `include` 10-20 (30?) submodules, by hand – instead of adding the folder and having Julia pick them up from there. It’s the kind of work that computers are much better at. Less to type, less to manage, neat and tidy.

Anyway, just my 2 cents, in case other developers feel the same, I’d like to see this back…

---

<div class="post-metadata">

**Author:** ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)\
**Post date:** [June 7, 2018, 3:37pm UTC](https://discourse.julialang.org/t/how-to-reference-modules-from-current-package-v0-7/11454/7 "2018-06-07T15:37:40Z")

</div>

You can always programmatically just loop through a folder with submodules and include everything.

If the packages are truly different packages then they should depend on each other with REQUIRE files and all that.

---

<div class="post-metadata">

**Author:** ![essenciary](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/essenciary/32/210469_2.png) [@essenciary](https://discourse.julialang.org/u/essenciary)\
**Post date:** [June 7, 2018, 3:55pm UTC](https://discourse.julialang.org/t/how-to-reference-modules-from-current-package-v0-7/11454/8 "2018-06-07T15:55:40Z")

</div>

Yup, thought about the loop myself – problem is load order though?

> [@kristoffer.carlsson](#):
>
> If the packages are truly different packages then they should depend on each other with REQUIRE files and all that.

Oh yes, that’s a totally different issue which has been bugging me for months now. Between `Genie` and `SearchLight`, for example, I have a number of modules which are used in both packages. Like a `Configuration` module. I wouldn’t want to publish a package which does nothing on its own, just so it can be shared by other packages. So, for now, I’ve resorted to having a `Configuration` submodule in each package, copy-pasted, yuck!

---

<div class="post-metadata">

**Author:** ![leiteiro](https://avatars.discourse-cdn.com/v4/letter/l/b5e925/32.png) [@leiteiro](https://discourse.julialang.org/u/leiteiro)\
**Post date:** [June 7, 2018, 5:07pm UTC](https://discourse.julialang.org/t/how-to-reference-modules-from-current-package-v0-7/11454/9 "2018-06-07T17:07:13Z")

</div>

I share your regret because I seem to have connected my modules  
in a similar way as you. With the current behavior of LoadPath,  
a very clear and systematic method of the workflow has been  
broken.

The “why” is not answered by the fact that this freedom of  
design was not initially intended, it was there and seemingly  
had no disadvantages. I still hope that this will be acknowledged  
as a bug.

In my setup the following workaround seems to work: add the line  
(@ **DIR** ) \notin LOAD\_PATH && push!(LOAD\_PATH, (@ **DIR** ))  
as the first line of each file.

Clearly a very ugly thing.
