Skip to content
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

[WIP]Add support for --dirty and --dirtyreloead options #248

Closed
wants to merge 4 commits into from

Conversation

AngryMane
Copy link
Contributor

@AngryMane AngryMane commented Aug 30, 2023

Hi! I issued a PR once a long time ago. Long time no see.🙂

description

I found mkdocs supports incremental builds (--dirty and --dirtyreload options), but this plugin does not.
This PR changes to support them.

motivation

If there are many documents, not supporting --dirty and --dirtyreload will cause extra time to build.
(For instance, my documents have been getting larger and larger, eventually taking as long as two minutes to hot reload!)
This PR allows hot reloads to be performed in a fraction of the time.

remarks

Frankly, I think dirty flag should be passed from mkdocs. However, since it is currently not possible to obtain the flag from mkdocs, I implemented this by referencing sys.argv.

Signed-off-by: AngryMane <regulationdango@gmail.com>
@ultrabug
Copy link
Owner

Hi @AngryMane ; long time no see, thanks for yet another contrib :)

Frankly, I think dirty flag should be passed from mkdocs. However, since it is currently not possible to obtain the flag from mkdocs, I implemented this by referencing sys.argv.

As a matter a fact, mkdocs DOES provide a way to let plugins know about its own command line invocation AND the dirty flag using the on_startup event!

So you could add a property to the ExtendedPlugin class defined in reconfigure.py and then implement a on_startup method in the plugin.py which could look like this:

    def on_startup(self, command: str, dirty: bool):
        """
        Store dirty flag to propagate it to language builds.
        """
        self.dirty = dirty

and of course use it later in the on_post_build method just like you did!

@AngryMane
Copy link
Contributor Author

Thank you, I had missed it. I'll correct it. 😄

Signed-off-by: AngryMane <regulationdango@gmail.com>
@AngryMane
Copy link
Contributor Author

AngryMane commented Aug 31, 2023

Something is wrong with the behavior...
Only updates to the default language pages seem not to be hot reloaded. I need to investigate

self.building may need to be set False at the end of on_post_build 🤔

Signed-off-by: AngryMane <regulationdango@gmail.com>
Signed-off-by: AngryMane <regulationdango@gmail.com>
@AngryMane AngryMane changed the title Add support for --dirty and --dirtyreloead options [WIP]Add support for --dirty and --dirtyreloead options Aug 31, 2023
@AngryMane
Copy link
Contributor Author

AngryMane commented Aug 31, 2023

I understood why the test failed.
mkdocs make a cache for plugins if the plugin has "on_startup" or "on_shuddown" event.
https://github.com/mkdocs/mkdocs/blob/79f17b4b71c73460c304e3281f6ff209788a76bf/mkdocs/config/config_options.py#L1128

This PR adds "on_startup" event, so mkdocs create plugin cache, and it causes current_language parameter of one previous test case is left. This is the direct cause of test failed.

@ultrabug
Copy link
Owner

You're almost there @AngryMane ! Keep it up :)

@AngryMane
Copy link
Contributor Author

AngryMane commented Aug 31, 2023

OK. I fixed. But the commit log is a bit messy, so I'm going to create a new branch and re-create the PR, and close this PR.

-> #249

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants