Skip to content

Commit

Permalink
refactor: Compatibility with MkDocs 1.2: livereload isn't guaranteed now
Browse files Browse the repository at this point in the history
MkDocs doesn't depend on 'livereload' library, and neither should we, but we import it for the type annotation, which is now also wrong.

Also fix tests: `site_url` value is now required for MkDocs.

PR #294: #294
  • Loading branch information
oprypin committed Jun 9, 2021
1 parent b3e122b commit 36e8024
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 11 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
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
Expand Up @@ -15,7 +15,6 @@
import os
from typing import Callable, 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 @@ -105,7 +104,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 @@ -117,18 +116,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
Expand Up @@ -23,6 +23,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

0 comments on commit 36e8024

Please sign in to comment.