-
Notifications
You must be signed in to change notification settings - Fork 51
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
Need a registration hook for other plugins #237
Comments
@timvink It's written. I have tested it roughly, so that I see that the code should work; but it would take me some time to build a test case. Would you like to see if it works for you? |
Sure, will try next week. At the scale mkdocs-macros is at already, sure you don't write to write a unit test for this functionality, to ensure it keeps working in the future? |
Yes. I have relied on testing my plugin on test websites (available), but I need to introduce a unit testing system. In a few words, how do you go about unit-testing an mkdocs plugin, without using |
You can test the functions / custom classes separately of course. I actually do prefer small 'integration' testing using What's worked for me is to build up a collection of small standalone examples (like here https://github.com/timvink/mkdocs-table-reader-plugin/tree/master/tests/fixtures) and test whether they fail (sometimes they should) or succeed, and whether the resulting html page(s) contain expected output. See f.e. https://github.com/timvink/mkdocs-table-reader-plugin/blob/master/tests/test_build.py |
@timvink Thank you for these examples, this is very interesting! |
Started having a look, and here's a first thing we can improve. I will need to implement it in a backwards compatible way, or at least require the user to upgrade to the latest version. So I want to know the version of macros plugin installed by the user. Previously the convention was for python packages to have # __init__.py
import importlib.metadata
__version__ = importlib.metadata.version("mypackage") But that will require you to move from For now I'll work around by testing to see if the register methods are available in table-reader. |
Fixed it. See PR #238 Implemented in table reader here: timvink/mkdocs-table-reader-plugin#77 (I will wait for new macros release before releasing it table reader) |
I passed the PR. Thanks a lot! |
- added the register_macros test case - reimplemented the .variables, .macros and .filters properties for MacrosDocProject - updated documentation, to document hooks scripts (including comparison with MkDocs-Macros modules)
We now have a formal test in MkDocs-Macros for this development (test/register_macros)! Which was what prompted the whole discussion about the testing framework in the first place (#244), leading to the creation of the MkDocs-Test plugin! 😮💨. So we have gone full circle 🙂. |
As explained by @timvink in squidfunk/mkdocs-material#5933, writers of other plugins would need some hook to declare variables, macros and filters before the Mkdocs-Macros is actually run.
The rule adopted is following: three methods
register_variables()
,register_macros()
andregister_filters()
.To facilitate work, these three method should work regardless of the order of declaration of plugins.
on_config()
is run beforeMacrosPlugin.on_config()
): they will be stored for later, and added last to the list of variables, macros or filters.In both cases, those keys are added on top of all other ones. Duplicate keys are not allowed and will cause a KeyError.
The text was updated successfully, but these errors were encountered: