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
mkdocs serve
does not watch for changes in mkdocstrings
#36
Comments
Yes I noticed it as well while implementing the watch feature. It's not a trivial thing to do. The way I implemented it is a complete hack, see the code at https://github.com/pawamoy/mkdocstrings/blob/master/src/mkdocstrings/plugin.py#L74-L90 When the plugin is instantiated, we store the set of modules currently loaded in a private var, and when a file changes in the watched directories, we get the diff of modules (current ones minus stored ones) and unload them. This was the only way I got it working, but only for other directories than mkdocstrings itself. I can think of other solutions but they are not trivial either. One of them is using a subprocess to import the Python objects and prebuild their documentation, return it as JSON to be able to pick it up in the parent process. This way we don't interfere with the current Python env and we do not need the Another solution which would completely change how mkdocstrings work would be to parse the code (just like what we do for attributes and their docstrings) instead of importing objects. But retrieving info with |
Hey, I noticed one bug due to an obscure Numpy bug. If
I think this is due to the fact you reload all modules upon save to obtain the potentially new changes. Is there any way to whitelist |
Hm, I patched this in and seems to work. def on_serve(self, server, config, **kwargs):
builder = list(server.watcher._tasks.values())[0]["func"]
def unload_and_rebuild():
diff = set(sys.modules.keys()) - self._sys
log.info(
f"mkdocstrings: Unloading modules loaded after mkdocstrings plugin was instantiated ({len(diff)} modules)"
)
for module in diff:
if "numpy" in module: # <<<<<<<<< add this
continue # <<<<<<<<< add this
del sys.modules[module]
self.clear()
builder()
for element in self.config["watch"]:
log.info(f"mkdocstrings: Adding directory '{element}' to watcher")
server.watch(element, unload_and_rebuild)
return server |
Ultimately we won't need this module reloading hack (see #28 (comment)), but until then I can accept this patch if you want to send a PR 🙂 |
Submitted! :) |
New architecture is almost ready. The data collection is done in a subprocess, with pytkdocs, and so this issue should be resolved, therefore I'm closing it. We'll open a new one if similar problem appear. |
Usually when I view mkdocs-generated documenation during development, the server will watch for changes and the page will auto-reload when changes are detected. Using mkdocstrings, I have not seen this happening, and to view changes I have to kill the
mkdocs serve
process and restart it.The text was updated successfully, but these errors were encountered: