From 66581c91312fac6ad76d6e7a51e50d88b0ef96b4 Mon Sep 17 00:00:00 2001 From: Curtis Vogt Date: Thu, 14 Nov 2019 09:45:41 -0600 Subject: [PATCH 1/4] Add pkgdir --- 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 20b298212..cb0bdc5a3 100644 --- a/README.md +++ b/README.md @@ -47,6 +47,8 @@ Currently, the `@compat` macro supports the following syntaxes: ## New functions, macros, and methods +* `pkgdir(m)` return the root directory of the package that imported module `m` ([#33128]). (since Compat 2.3.0) + * `only(x)` returns the one-and-only element of a collection `x` ([#33129]). (since Compat 2.2.0) * `mod` now accepts a unit range as the second argument ([#32628]). (since Compat 2.2.0) @@ -111,3 +113,4 @@ 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 diff --git a/src/Compat.jl b/src/Compat.jl index e4946a6d2..d81dfc31c 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 + include("deprecated.jl") end # module Compat diff --git a/test/runtests.jl b/test/runtests.jl index 6e1f8b77c..19f9a266f 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -97,4 +97,10 @@ end @test ∘(fs...)("ABC") == "AB" end +# https://github.com/JuliaLang/julia/pull/33128 +@testset "pkgdir" begin + @test pkgdir(Main) === nothing + @test pkgdir(Compat) == rstrip(abspath(joinpath(@__DIR__, "..")), '/') +end + nothing From 5f9267b3a4c0b7cf7d05370d0a8ccb36835f92a2 Mon Sep 17 00:00:00 2001 From: Curtis Vogt Date: Thu, 14 Nov 2019 10:13:33 -0600 Subject: [PATCH 2/4] fixup! Add pkgdir --- test/runtests.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/runtests.jl b/test/runtests.jl index 19f9a266f..e40bc5ced 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -100,7 +100,7 @@ end # https://github.com/JuliaLang/julia/pull/33128 @testset "pkgdir" begin @test pkgdir(Main) === nothing - @test pkgdir(Compat) == rstrip(abspath(joinpath(@__DIR__, "..")), '/') + @test joinpath(pkgdir(Compat), "") == abspath(joinpath(@__DIR__, "..")) end nothing From b18d821569810523cf95558578e82868b35e11aa Mon Sep 17 00:00:00 2001 From: Martin Holters Date: Tue, 19 Nov 2019 16:40:12 +0100 Subject: [PATCH 3/4] Update README.md Minor typo fix and remove the "(since Compat xxx)". --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 0bbc834d1..50578ae3e 100644 --- a/README.md +++ b/README.md @@ -50,7 +50,7 @@ Currently, the `@compat` macro supports the following syntaxes: ## New functions, macros, and methods -* `pkgdir(m)` return the root directory of the package that imported module `m` ([#33128]). (since Compat 2.3.0) +* `pkgdir(m)` returns the root directory of the package that imported module `m` ([#33128]). * `only(x)` returns the one-and-only element of a collection `x` ([#33129]). (since Compat 2.2.0) From 538d6d6d5fc5047aea958cf4442cf45c84e813b9 Mon Sep 17 00:00:00 2001 From: Martin Holters Date: Wed, 25 Dec 2019 21:57:18 +0100 Subject: [PATCH 4/4] Move `pkgdir` entry in README to top of the list Also add 3.2.0 as version where it is introduced. --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 9e06dee00..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) @@ -51,8 +53,6 @@ Please check the list below for the specific syntax you need. * Function composition now supports multiple functions: `∘(f, g, h) = f ∘ g ∘ h` and splatting `∘(fs...)` for composing an iterable collection of functions ([#33568]). (since Compat 3.0.0) -* `pkgdir(m)` returns the root directory of the package that imported module `m` ([#33128]). - * `only(x)` returns the one-and-only element of a collection `x` ([#33129]). (since Compat 2.2.0) * `mod` now accepts a unit range as the second argument ([#32628]). (since Compat 2.2.0)