# Allow Pkg.dir on JuliaBox

**URL:** <https://discourse.julialang.org/t/allow-pkg-dir-on-juliabox/9784>\
**Category:** Community\
**Created:** [March 18, 2018, 9:41am UTC](https://discourse.julialang.org/t/allow-pkg-dir-on-juliabox/9784 "2018-03-18T09:41:45Z")\
**Posts on this page:** 19\
**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:** [March 18, 2018, 9:41am UTC](https://discourse.julialang.org/t/allow-pkg-dir-on-juliabox/9784/1 "2018-03-18T09:41:45Z")

</div>

Is it possible to whitelist `Pkg.dir` on JuliaBox? I use it `include` certain files which are not modules, from the source dir and/or to check the existence of other packages. Or is there another, recommended way of doing this without `Pkg.dir`? Thanks

---

<div class="post-metadata">

**Author:** ![chakravala](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chakravala/32/6832_2.png) [@chakravala](https://discourse.julialang.org/u/chakravala)\
**Post date:** [March 18, 2018, 2:29pm UTC](https://discourse.julialang.org/t/allow-pkg-dir-on-juliabox/9784/2 "2018-03-18T14:29:59Z")

</div>

You can use `dirname(@ __FILE__ )` within a package, which gives the directory of the currently running file.

---

<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:** [March 18, 2018, 3:20pm UTC](https://discourse.julialang.org/t/allow-pkg-dir-on-juliabox/9784/3 "2018-03-18T15:20:24Z")

</div>

Or `@ __DIR__ `

---

<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:** [March 18, 2018, 4:53pm UTC](https://discourse.julialang.org/t/allow-pkg-dir-on-juliabox/9784/4 "2018-03-18T16:53:08Z")

</div>

Thanks!

---

<div class="post-metadata">

**Author:** ![djsegal](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/djsegal/32/13752_2.png) [@djsegal](https://discourse.julialang.org/u/djsegal)\
**Post date:** [March 18, 2018, 5:53pm UTC](https://discourse.julialang.org/t/allow-pkg-dir-on-juliabox/9784/5 "2018-03-18T17:53:38Z")

</div>

What about finding Julia’s root Pkg.dir?

i.e. the result of:

```julia
Pkg.dir()

```

---

<div class="post-metadata">

**Author:** ![chakravala](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chakravala/32/6832_2.png) [@chakravala](https://discourse.julialang.org/u/chakravala)\
**Post date:** [March 19, 2018, 1:39am UTC](https://discourse.julialang.org/t/allow-pkg-dir-on-juliabox/9784/6 "2018-03-19T01:39:56Z")

</div>

You could do

```julia
joinpath(homedir(),".julia","v$(VERSION.major).$(VERSION.minor)")

```

to get `~/.julia/v*.*`

---

<div class="post-metadata">

**Author:** ![avik](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/avik/32/17_2.png) [@avik](https://discourse.julialang.org/u/avik)\
**Post date:** [March 19, 2018, 10:22am UTC](https://discourse.julialang.org/t/allow-pkg-dir-on-juliabox/9784/7 "2018-03-19T10:22:39Z")

</div>

So it is a bit of an annoyance that you cannot do `Pkg.dir()` on Juliabox, no doubt.

I will point out however that `Pkg.dir()` is incorrect in many other situations. For example, if people build custom sysimages, or compile to binary. `Pkg.dir()` will also fail in those situations. Hence, using `Pkg.dir()` (or `Pkg.installed()`) in your packages is really not a good idea.

---

<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:** [March 19, 2018, 3:42pm UTC](https://discourse.julialang.org/t/allow-pkg-dir-on-juliabox/9784/8 "2018-03-19T15:42:22Z")

</div>

Thanks - so then `@ __DIR__ ` is the way to go?

---

<div class="post-metadata">

**Author:** ![StefanKarpinski](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stefankarpinski/32/24_2.png) [@StefanKarpinski](https://discourse.julialang.org/u/StefanKarpinski)\
**Post date:** [March 19, 2018, 8:42pm UTC](https://discourse.julialang.org/t/allow-pkg-dir-on-juliabox/9784/9 "2018-03-19T20:42:08Z")

</div>

`Pkg.dir()` is also going away in Pkg3 since it allows multiple different versions of a given package to be installed at the same time (and in different depots) so there is no longer a coherent answer to the question this function asks.

---

<div class="post-metadata">

**Author:** ![djsegal](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/djsegal/32/13752_2.png) [@djsegal](https://discourse.julialang.org/u/djsegal)\
**Post date:** [May 29, 2018, 8:36pm UTC](https://discourse.julialang.org/t/allow-pkg-dir-on-juliabox/9784/10 "2018-05-29T20:36:35Z")

</div>

> [@StefanKarpinski](#):
>
> `Pkg.dir()` is also going away in Pkg3

Has there been any discussion about how to migrate existing Pkgs?

// running into this problem with getting [`WebIO`](https://github.com/JuliaGizmos/WebIO.jl/issues/128) to v0.7

* * *

**edit:** similar discussion: [How to get Julia home in Julia 0.7?](https://discourse.julialang.org/t/how-to-get-julia-home-in-julia-0-7/9953) (maybe that answers the question)

---

<div class="post-metadata">

**Author:** ![StefanKarpinski](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stefankarpinski/32/24_2.png) [@StefanKarpinski](https://discourse.julialang.org/u/StefanKarpinski)\
**Post date:** [May 29, 2018, 9:03pm UTC](https://discourse.julialang.org/t/allow-pkg-dir-on-juliabox/9784/11 "2018-05-29T21:03:39Z")

</div>

You can use `@ __DIR__ ` which is actually the recommended approach previously as well. Pkg3 just happens to break the non-recommended approach of using `Pkg.dir`. Otherwise there’s not really much you have to do at this point.

---

<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, 4:50pm UTC](https://discourse.julialang.org/t/allow-pkg-dir-on-juliabox/9784/12 "2018-06-05T16:50:23Z")

</div>

How can `@ __DIR__ ` be used to replicate the behavior of `Pkg.dir("PkgName")`?  
Or, rather, how to check if a package is installed?

---

<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, 5:25pm UTC](https://discourse.julialang.org/t/allow-pkg-dir-on-juliabox/9784/13 "2018-06-05T17:25:19Z")

</div>

> [@essenciary](#):
>
> Or, rather, how to check if a package is installed?

What is your use case? In 0.7 it is hard to give a definite answer to this question. You can use Requires.jl to load code when another package is loaded.

---

<div class="post-metadata">

**Author:** ![StefanKarpinski](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stefankarpinski/32/24_2.png) [@StefanKarpinski](https://discourse.julialang.org/u/StefanKarpinski)\
**Post date:** [June 5, 2018, 6:09pm UTC](https://discourse.julialang.org/t/allow-pkg-dir-on-juliabox/9784/14 "2018-06-05T18:09:21Z")

</div>

There’s also `Pkg.API.installed()` which will show you all the packages that are installed in your current environment, but as @kristoffer.carlsson said, it’s not so clear what it means for a package to be installed or not in Pkg3. It can be installed in one environment at one version, installed at a different version in a different environment, and not installed in yet another environment.

---

<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, 6:14pm UTC](https://discourse.julialang.org/t/allow-pkg-dir-on-juliabox/9784/15 "2018-06-05T18:14:30Z")

</div>

I just want to say that don’t get too attached to the exact output of `Pkg.API.installed()` because the output it gives with names as the keys is fundamentally a bit flawed.

---

<div class="post-metadata">

**Author:** ![StefanKarpinski](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stefankarpinski/32/24_2.png) [@StefanKarpinski](https://discourse.julialang.org/u/StefanKarpinski)\
**Post date:** [June 5, 2018, 6:15pm UTC](https://discourse.julialang.org/t/allow-pkg-dir-on-juliabox/9784/16 "2018-06-05T18:15:37Z")

</div>

Right, that will have to go at some point as names are no longer unique within the dependency graph of a project. It’s really just a legacy API shim.

---

<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, 7:03pm UTC](https://discourse.julialang.org/t/allow-pkg-dir-on-juliabox/9784/19 "2018-06-05T19:03:01Z")

</div>

Mostly for “user-friendly dependency management”.

Take SearchLight, the ORM: it works with a multitude of database backends and relies on the corresponding lower level access libraries. It didn’t make sense to add all the libraries (SQLite.jl, MySQL.jl, ODBC.jl, etc) as dependencies, given that a project will use just one backend. So I’ve added none. At runtime, when the package loads the database configuration file, it checks if the configured backend library is installed - if not, it installs it.

I guess it’s not a big deal, this can be offloaded onto the user. But as it is now, it makes for a pretty good user experience.

---

<div class="post-metadata">

**Author:** ![avik](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/avik/32/17_2.png) [@avik](https://discourse.julialang.org/u/avik)\
**Post date:** [June 6, 2018, 7:44am UTC](https://discourse.julialang.org/t/allow-pkg-dir-on-juliabox/9784/22 "2018-06-06T07:44:12Z")

</div>

I think in these situations, the idea in `Pkg3` is to offload this to the user. `Pkg3` essentially allows you to create a custom environment for each project. Hence in this case, the user would create a Pkg3 environment for their web application, and specify Genie, Searchlight and say ODBC.jl as dependencies for that environment. Searchlight would, on load, read the app configuration, and load ODBC.jl, assuming it to be available.

This is the only way to ensure that the environment in dev and prod are the same. The issue with the existing system (where Searchlight installs the package if not found, or even a user installs it manually) is that there is no guarantee that you will get the same version on two installs.

---

<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, 9:13am UTC](https://discourse.julialang.org/t/allow-pkg-dir-on-juliabox/9784/23 "2018-06-06T09:13:26Z")

</div>

OK, thank you - yes, I see your point. Similar to ruby’s Gemfile, managed by Bundler. Indeed, in such a scenario, the user would have to fully configure and manage the dependency requirements. Makes sense, thanks.
