From 310219dc43b242c93fdd9b32cd5cd185d4cc516d Mon Sep 17 00:00:00 2001 From: Curtis Vogt Date: Wed, 25 Dec 2019 15:54:44 -0600 Subject: [PATCH] Add `pkgdir` (#674) --- README.md | 3 +++ src/Compat.jl | 11 +++++++++++ test/runtests.jl | 6 ++++++ 3 files changed, 20 insertions(+) diff --git a/README.md b/README.md index 5049e55b8..ef2c33fb1 100644 --- a/README.md +++ b/README.md @@ -44,6 +44,8 @@ Please check the list below for the specific syntax you need. ## Supported features +* `pkgdir(m)` returns the root directory of the package that imported module `m` ([#33128]). (since Compat 3.2.0) + * `filter` can now act on a `Tuple` [#32968]. (since Compat 3.1.0) * `Base.Order.ReverseOrdering` has a zero arg constructor [#33736]. (since Compat 3.0.0) @@ -104,5 +106,6 @@ Note that you should specify the correct minimum version for `Compat` in the [#32628]: https://github.com/JuliaLang/julia/issues/32628 [#33129]: https://github.com/JuliaLang/julia/issues/33129 [#33568]: https://github.com/JuliaLang/julia/pull/33568 +[#33128]: https://github.com/JuliaLang/julia/pull/33128 [#33736]: http://github.com/JuliaLang/julia/pull/33736 [#32968]: https://github.com/JuliaLang/julia/pull/32968 diff --git a/src/Compat.jl b/src/Compat.jl index b53df9823..3d2842c93 100644 --- a/src/Compat.jl +++ b/src/Compat.jl @@ -93,6 +93,17 @@ if VERSION < v"1.4.0-DEV.329" Base.:∘(f, g, h...) = ∘(f ∘ g, h...) end +# https://github.com/JuliaLang/julia/pull/33128 +if VERSION < v"1.4.0-DEV.397" + export pkgdir + function pkgdir(m::Module) + rootmodule = Base.moduleroot(m) + path = pathof(rootmodule) + path === nothing && return nothing + return dirname(dirname(path)) + end +end + # https://github.com/JuliaLang/julia/pull/33736/ if VERSION < v"1.4.0-DEV.493" Base.Order.ReverseOrdering() = Base.Order.ReverseOrdering(Base.Order.Forward) diff --git a/test/runtests.jl b/test/runtests.jl index 6315805b8..4837c4183 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -97,6 +97,12 @@ end @test ∘(fs...)("ABC") == "AB" end +# https://github.com/JuliaLang/julia/pull/33128 +@testset "pkgdir" begin + @test pkgdir(Main) === nothing + @test joinpath(pkgdir(Compat), "") == abspath(joinpath(@__DIR__, "..")) +end + # https://github.com/JuliaLang/julia/pull/33736/ @testset "ReverseOrdering constructor" begin @test Base.Order.ReverseOrdering() == Base.Order.Reverse