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

Compatibility with MkDocs 1.2: livereload isn't guaranteed now #294

Merged
merged 1 commit into from
Jun 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ python = "^3.6"
Jinja2 = ">=2.11.1, <4.0"
Markdown = "^3.3"
MarkupSafe = ">=1.1, <3.0"
mkdocs = "^1.1"
mkdocs = "^1.1.1"
mkdocs-autorefs = ">=0.1, <0.3"
pymdown-extensions = ">=6.3, <9.0"
pytkdocs = ">=0.2.0, <0.12.0"
Expand Down
11 changes: 1 addition & 10 deletions src/mkdocstrings/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import urllib.request
from typing import Any, BinaryIO, Callable, Iterable, List, Mapping, Optional, Tuple

from livereload import Server
from mkdocs.config import Config
from mkdocs.config.config_options import Type as MkType
from mkdocs.plugins import BasePlugin
Expand Down Expand Up @@ -111,7 +110,7 @@ def handlers(self) -> Handlers:
raise RuntimeError("The plugin hasn't been initialized with a config yet")
return self._handlers

def on_serve(self, server: Server, builder: Callable = None, **kwargs) -> Server: # noqa: W0613 (unused arguments)
def on_serve(self, server, builder: Callable, **kwargs): # noqa: W0613 (unused arguments)
"""Watch directories.

Hook for the [`on_serve` event](https://www.mkdocs.org/user-guide/plugins/#on_serve).
Expand All @@ -123,18 +122,10 @@ def on_serve(self, server: Server, builder: Callable = None, **kwargs) -> Server
server: The `livereload` server instance.
builder: The function to build the site.
kwargs: Additional arguments passed by MkDocs.

Returns:
The server instance.
"""
if builder is None:
# The builder parameter was added in mkdocs v1.1.1.
# See issue https://github.com/mkdocs/mkdocs/issues/1952.
builder = list(server.watcher._tasks.values())[0]["func"] # noqa: W0212 (protected member)
for element in self.config["watch"]:
log.debug(f"Adding directory '{element}' to watcher")
server.watch(element, builder)
return server

def on_config(self, config: Config, **kwargs) -> Config: # noqa: W0613 (unused arguments)
"""Instantiate our Markdown extension.
Expand Down
1 change: 1 addition & 0 deletions tests/test_extension.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ def fixture_ext_markdown(request, tmp_path):

conf_dict = {
"site_name": "foo",
"site_url": "https://example.org/",
"site_dir": str(tmp_path),
"plugins": [{"mkdocstrings": {"default_handler": "python"}}],
**getattr(request, "param", {}),
Expand Down