-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add pkgdir(m::Module) #33128
Add pkgdir(m::Module) #33128
Conversation
N.B. the submodule test required adding a submodule to |
base/loading.jl
Outdated
rootmodule = Base.moduleroot(m) | ||
path = pathof(rootmodule) | ||
path === nothing && return nothing | ||
return joinpath(splitpath(path)[1:end-2]...) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn’t the usual dirname(dirname(path))
be slightly more efficient?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Your judgement is best here.. so I've switched it out
Looks good to me. I'm tagging for triage just to discuss the API. |
A minor snag is the discrepancy in meaning of |
That is unfortunate.
Also, not that I’m suggesting changing it, but |
How about |
But I like the mentality of this being a How about both? |
Eh, I'd prefer not to have two gratuitously different ways to spell the same thing. |
I’d go for the former then, given convenience |
Yeah, that's a pretty serious issue that almost makes these functions worse than useless. I've been intending to eventually get around to fixing that. I guess this is good motivation for me to address both at the same time. So, I'm good with merging this now, with the intention that the implementation will be completely redone at some point (so that it'll still typically give this answer, but actually give it correctly in all cases). |
Just to check, I’d need to rename the function to |
How do you propose doing that? This function returns the root directory of the package that a module comes from. It can't, by definition, do that unless the module comes from a package.
Before you do any of that, please explain what you have in mind. |
Giving the path to the file where the module was defined (which is what
If you just have the packages |
I think there's a strong case for easy read-only access to dirs like And dev-ing packages describes another kind of user. I don't think people would be looking to modify the examples generally. Copying the path out of I just see a lot of |
+1 to |
I've switched out the name to |
Do we need two functions that do (basically) the same thing? |
|
Triage is ok with this. |
Could this get into v1.3, or is that window closed? |
Feature freeze was August 15. |
ok, thanks @fredrikekre |
I don't get this comment. @fredrikekre, what's the other function that's the same as this? |
It'd be nice to get this into 1.4 🙏🏻 |
Looks like this is missing from NEWS.md |
testing fails because pkgdir wasn't added till 1.4: see JuliaLang/julia#33128
Edit: function now named
pkgdir(m::Module)
but was originally proposed asrootof(m::Module)
Provides a convenient way to get to the root directory (the parent directory of
src
) of the package that imported module m.Closely equivalent to:
Submodules resolve the same root:
One notable use case would be getting to package examples easily:
Discussed in #31638