From 36e80248d2ab9e61975f6c83ae517115c9410fc1 Mon Sep 17 00:00:00 2001 From: Oleh Prypin Date: Wed, 9 Jun 2021 21:58:05 +0200 Subject: [PATCH] refactor: Compatibility with MkDocs 1.2: livereload isn't guaranteed now 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: https://github.com/mkdocstrings/mkdocstrings/pull/294 --- pyproject.toml | 2 +- src/mkdocstrings/plugin.py | 11 +---------- tests/test_extension.py | 1 + 3 files changed, 3 insertions(+), 11 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index faa18416..cbe1a4b3 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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" diff --git a/src/mkdocstrings/plugin.py b/src/mkdocstrings/plugin.py index 054cd2e0..f7c7b611 100644 --- a/src/mkdocstrings/plugin.py +++ b/src/mkdocstrings/plugin.py @@ -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 @@ -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). @@ -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. diff --git a/tests/test_extension.py b/tests/test_extension.py index baf77fbf..c6eef821 100644 --- a/tests/test_extension.py +++ b/tests/test_extension.py @@ -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", {}),