# What to use in v0.7 in place of \`Pkg.dir\`

**URL:** <https://discourse.julialang.org/t/what-to-use-in-v0-7-in-place-of-pkg-dir/12090>\
**Category:** General Usage\
**Tags:** question, package\
**Created:** [July 1, 2018, 1:58pm UTC](https://discourse.julialang.org/t/what-to-use-in-v0-7-in-place-of-pkg-dir/12090 "2018-07-01T13:58:43Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![dmbates](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dmbates/32/44_2.png) [@dmbates](https://discourse.julialang.org/u/dmbates)\
**Post date:** [July 1, 2018, 1:58pm UTC](https://discourse.julialang.org/t/what-to-use-in-v0-7-in-place-of-pkg-dir/12090/1 "2018-07-01T13:58:43Z")

</div>

In v0.7.0-beta the use of `Pkg.dir` produces a warning

```julia
julia> using Pkg

julia> Pkg.dir("Statistics")
┌ Warning: Pkg.dir is only kept for legacy CI script reasons
└ @ Pkg.API API.jl:432
"/home/bates/git/julia/usr/share/julia/stdlib/v0.7/Statistics/"

```

but without any indication of what should be used instead.

If I include sample data with a package and want to illustrate how to access that data, I could use

```julia
dat = load(Pkg.dir("MixedModels", "test", "dat.rda"))

```

in earlier versions. What would a v0.7 alternative be?

---

<div class="post-metadata">

**Author:** ![Ralph\_Smith](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ralph_smith/32/10344_2.png) [@Ralph\_Smith](https://discourse.julialang.org/u/Ralph_Smith)\
**Post date:** [July 1, 2018, 3:20pm UTC](https://discourse.julialang.org/t/what-to-use-in-v0-7-in-place-of-pkg-dir/12090/2 "2018-07-01T15:20:39Z")

</div>

This seems to be a work in progress (there are some subtle potential ambiguities):

[https://github.com/JuliaLang/julia/issues/27592](https://github.com/JuliaLang/julia/issues/27592)

For your use case, consider defining something like

```julia
exampledatapath(filename) = joinpath(@ __DIR__ ,"..","test",filename)

```

in your source tree, so users do

```julia
dat = load(MixedModels.exampledatapath("dat.rda"))

```

---

<div class="post-metadata">

**Author:** ![Keno](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/keno/32/285_2.png) [@Keno](https://discourse.julialang.org/u/Keno)\
**Post date:** [July 1, 2018, 3:42pm UTC](https://discourse.julialang.org/t/what-to-use-in-v0-7-in-place-of-pkg-dir/12090/3 "2018-07-01T15:42:35Z")

</div>

> [@Ralph\_Smith](#):
>
> ```julia
> exampledatapath(filename) = joinpath(@ __DIR__ ,"..","test",filename)
> 
> ```

This is the right answer. In the future, there may also be a separate mechansim for bundled example data/models, but not yet.

---

<div class="post-metadata">

**Author:** ![dmbates](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dmbates/32/44_2.png) [@dmbates](https://discourse.julialang.org/u/dmbates)\
**Post date:** [July 1, 2018, 4:41pm UTC](https://discourse.julialang.org/t/what-to-use-in-v0-7-in-place-of-pkg-dir/12090/4 "2018-07-01T16:41:10Z")

</div>

That works for `Pkg.test` but, unfortunately, not for my case, which is writing a tutorial on using the package.

I want to write a reproducible expression allowing the user to access the data file without any assumptions on the working directory.

---

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [July 2, 2018, 12:30pm UTC](https://discourse.julialang.org/t/what-to-use-in-v0-7-in-place-of-pkg-dir/12090/5 "2018-07-02T12:30:41Z")

</div>

> [@dmbates](#):
>
> I want to write a reproducible expression allowing the user to access the data file without any assumptions on the working directory.

`@ __DIR__ ` is not the “working directory”, it is the directory of the _file_ the macro appears in. So, if you define `exampledatapath(filename)` _in your module_, it won’t matter what directory the user is calling from.

---

<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:** [July 2, 2018, 12:45pm UTC](https://discourse.julialang.org/t/what-to-use-in-v0-7-in-place-of-pkg-dir/12090/6 "2018-07-02T12:45:31Z")

</div>

This is a common situation, and has various solutions. Perhaps some elements form the design of the R package [here](https://here.r-lib.org/) could be adapted to Julia.

---

<div class="post-metadata">

**Author:** ![piever](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/piever/32/1815_2.png) [@piever](https://discourse.julialang.org/u/piever)\
**Post date:** [July 2, 2018, 4:26pm UTC](https://discourse.julialang.org/t/what-to-use-in-v0-7-in-place-of-pkg-dir/12090/7 "2018-07-02T16:26:19Z")

</div>

I ended up needing this thing pretty often, and was wondering whether by default the package generator could add a

```julia
const __sourcedir__ = @ __DIR__

```

line by default (in MyPackage.jl), so that one could always use `MyPackage. __sourcedir__ ` to refer to the package.

---

<div class="post-metadata">

**Author:** ![tobias.knopp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tobias.knopp/32/7551_2.png) [@tobias.knopp](https://discourse.julialang.org/u/tobias.knopp)\
**Post date:** [July 2, 2018, 4:57pm UTC](https://discourse.julialang.org/t/what-to-use-in-v0-7-in-place-of-pkg-dir/12090/8 "2018-07-02T16:57:40Z")

</div>

I use `Pkg.dir` in package `A` but want to look into package `B`. In those cases `@ __DIR__ ` does not work. Why can’t we simply have/keep `Pkg.dir(m::String)`? Within our loading machinery such a thing must somewhere exist, so why not simply expose it. We previously had static package directories where things have been very easy. Now the package dir is dynamically changing (whether in dev mode or not) and in turn it would be good to leave existing package authors not alone.

---

<div class="post-metadata">

**Author:** ![fredrikekre](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fredrikekre/32/1688_2.png) [@fredrikekre](https://discourse.julialang.org/u/fredrikekre)\
**Post date:** [July 2, 2018, 5:05pm UTC](https://discourse.julialang.org/t/what-to-use-in-v0-7-in-place-of-pkg-dir/12090/9 "2018-07-02T17:05:21Z")

</div>

FWIW `Pkg.dir` was not correct in Pkg2 either so its not like there is a loss of functionality.

---

<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:** [July 2, 2018, 6:08pm UTC](https://discourse.julialang.org/t/what-to-use-in-v0-7-in-place-of-pkg-dir/12090/10 "2018-07-02T18:08:59Z")

</div>

Yes, `Pkg.dir()` did not work in all situations in Pkg2. It just prevented people with non standard setups to use your package. Hence the removal.

In particular, it did not work when the package was built into the standard image, did not work when packages were loaded via LOAD\_PATH. It was also problematic in centrally managed package directories.

Regards

Avik

---

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [July 2, 2018, 6:39pm UTC](https://discourse.julialang.org/t/what-to-use-in-v0-7-in-place-of-pkg-dir/12090/11 "2018-07-02T18:39:10Z")

</div>

I just noticed that `Pkg.dir` is [used extensively in Documenter.jl](https://github.com/JuliaDocs/Documenter.jl/search?q=Pkg.dir&unscoped_q=Pkg.dir) to build documentation for other packages. This is a good example of something that needs to find the directory of another package (which may not even be imported yet). (Similar usage can be found in Coverage.jl.)

Both Documenter.jl and Coverage.jl are extensively used in Julia packages, and their usage of `Pkg.dir` will need a non-deprecated replacement in 0.7.

---

<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:** [July 2, 2018, 6:48pm UTC](https://discourse.julialang.org/t/what-to-use-in-v0-7-in-place-of-pkg-dir/12090/12 "2018-07-02T18:48:46Z")

</div>

Yes, for things like `Documenter` and `Coverage` that explicitly deal with packages something like this is likely needed and is why I opened [https://github.com/JuliaLang/julia/issues/27592](https://github.com/JuliaLang/julia/issues/27592).
