-
Notifications
You must be signed in to change notification settings - Fork 28
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
RFC: test, fix, and redesign Requires #46
Conversation
The precompiled tests fail currently
Precompilation seems to turn the UUID into `toplevel`, so it's not found as a key in the callback dict. By requiring that the user put the atsign-require into an __init__ function, this package becomes compatible with packages that have to define their own operations inside an __init__ (without them having to call `initm`). Moreover, it makes the package considerably simpler and less magical.
Thanks for making this PR. I was stuck with #45 because the mechanism for |
Thanks for making this PR, it will be amazing to get this working for 0.7, I already use it for 2 out of the 4 packages I have created :D The new interface, e.g. using Another plus is that this approach does not add any extra lines of code to users.
or
same story length-wise. The change does have the huge benefit that Tim mentioned, that it does not silently fail if an |
There is now a mini-blog post on this here (written by request in the comment above it). |
Sounds good to me. Might be useful to encourage pre-compilation compatibility and discourage changing local bindings though. Those together mean that it would encourage providing just a mapping of one module name name to another. when_loaded(@__MODULE__, :JSON, :MyJsonPlugin)
# or
@when_loaded JSON => MyJsonPlugin This would records locally that when and if JSON is loaded, then MyJsonPlugin should also get loaded. Requires.jl can implement this by creating a global array inside the current-module recording these relations in a hidden magic variable. Then when |
Create a fully-qualified token with |
Great stuff @timholy! This package has been fairly minimally maintained since the first release (I think for 0.4?) so it's no doubt due for an overhaul. FWIW, it is possible to have It's a shame we can't easily deprecate this (?) but luckily we can at least re-use the syntax deprecation to warn people. |
Thanks everyone for sorting this out, much appreciated!! |
Thanks Mike, I really appreciate the work you've done yourself putting this on more solid footing. And thanks for adding the syntax warning, that should cover people who haven't yet tried to update to 0.7. @vtjnash, I too wondered about the |
I'm currently moving EDIT: Looks like the same question was asked in #51 |
Sorry, I don't understand. So how do I specify a bunch of code to load from my package using Mymodule
using LinearAlgebra
## now Mymodule's support for functions in LinearAlgebra is loaded |
This is a very intrusive change that also has the consequence of getting this package working on 0.7. The first commit restructures the tests to be more typical, in my opinion, of how I suspect people use Requires in practice. It tests both non-precompiled and precompiled packages, and tests behavior from outside the module that leverages Requires to ensure that there's no weird scoping issue. If you check out just this commit, you can easily verify that it fails these new tests for precompiled packages.
The second commit is the dangerous one. One change you definitely want to keep is hard-coding the PkgId that gets passed to
listenpkg
:https://github.com/MikeInnes/Requires.jl/blob/dc9c472f0494ee2a858a13ebffeb0afc03e461a0/src/require.jl#L64
Precompilation, for reasons I don't fully understand, turns the
$pkg
key intoJSON [top-level]
, which is what populatesRequires._callbacks
. Consequently, when the package callback comes in with a keyJSON [682c06a0-de6a-54ab-a142-c8b1cf79cde6]
, it doesn't find it in the dictionary and Requires silently fails to load the requested resource.However, this wasn't (I think---I could have made a user error while putting this together) enough to fix the package completely. I have to confess I wasn't too fond of the way that Requires constructed an
__init__
function, especially since my reading of the code suggests that if a user needs to have her own__init__
doing something else, Requires will silently fail. Consequently I took the daring step of also redesigning how one should use Requires---now you do this:This leads to less need for macro-foo, and might make it easier for people to understand how this works and consequently help maintain it (e.g., #45). In my opinion it's also less magical-seeming and may help people have a bit more intuition for how this works.