mirror of
https://github.com/mkdocs/mkdocs.git
synced 2026-03-27 09:58:31 +07:00
Avoid importlib_metadata dependency since Python 3.10 (#2959)
This commit is contained in:
committed by
GitHub
parent
3896a82ebf
commit
4ada758a79
@@ -5,10 +5,15 @@ Implements the plugin API for MkDocs.
|
||||
from __future__ import annotations
|
||||
|
||||
import logging
|
||||
import sys
|
||||
from collections import OrderedDict
|
||||
from typing import Any, Callable, Dict, Optional, Sequence, Tuple, TypeVar, overload
|
||||
|
||||
import importlib_metadata
|
||||
if sys.version_info >= (3, 10):
|
||||
from importlib.metadata import entry_points
|
||||
else:
|
||||
from importlib_metadata import entry_points
|
||||
|
||||
import jinja2.environment
|
||||
|
||||
from mkdocs.config.base import BaseConfigOption, Config
|
||||
@@ -23,7 +28,7 @@ log = logging.getLogger('mkdocs.plugins')
|
||||
def get_plugins():
|
||||
"""Return a dict of all installed Plugins as {name: EntryPoint}."""
|
||||
|
||||
plugins = importlib_metadata.entry_points(group='mkdocs.plugins')
|
||||
plugins = entry_points(group='mkdocs.plugins')
|
||||
|
||||
# Allow third-party plugins to override core plugins
|
||||
pluginmap = {}
|
||||
|
||||
@@ -239,7 +239,7 @@ MockEntryPoint = mock.Mock()
|
||||
MockEntryPoint.configure_mock(**{'name': 'sample', 'load.return_value': DummyPlugin})
|
||||
|
||||
|
||||
@mock.patch('importlib_metadata.entry_points', return_value=[MockEntryPoint])
|
||||
@mock.patch('mkdocs.plugins.entry_points', return_value=[MockEntryPoint])
|
||||
class TestPluginConfig(unittest.TestCase):
|
||||
def test_plugin_config_without_options(self, mock_class):
|
||||
|
||||
|
||||
@@ -293,7 +293,7 @@ class UtilsTests(unittest.TestCase):
|
||||
|
||||
self.assertEqual(sorted(utils.get_theme_names()), ['mkdocs', 'readthedocs'])
|
||||
|
||||
@mock.patch('importlib_metadata.entry_points', autospec=True)
|
||||
@mock.patch('mkdocs.utils.entry_points', autospec=True)
|
||||
def test_get_theme_dir(self, mock_iter):
|
||||
|
||||
path = 'some/path'
|
||||
@@ -312,7 +312,7 @@ class UtilsTests(unittest.TestCase):
|
||||
with self.assertRaises(KeyError):
|
||||
utils.get_theme_dir('nonexistanttheme')
|
||||
|
||||
@mock.patch('importlib_metadata.entry_points', autospec=True)
|
||||
@mock.patch('mkdocs.utils.entry_points', autospec=True)
|
||||
def test_get_theme_dir_importerror(self, mock_iter):
|
||||
|
||||
theme = mock.Mock()
|
||||
@@ -325,7 +325,7 @@ class UtilsTests(unittest.TestCase):
|
||||
with self.assertRaises(ImportError):
|
||||
utils.get_theme_dir(theme.name)
|
||||
|
||||
@mock.patch('importlib_metadata.entry_points', autospec=True)
|
||||
@mock.patch('mkdocs.utils.entry_points', autospec=True)
|
||||
def test_get_themes_warning(self, mock_iter):
|
||||
|
||||
theme1 = mock.Mock()
|
||||
@@ -342,7 +342,7 @@ class UtilsTests(unittest.TestCase):
|
||||
|
||||
self.assertEqual(sorted(utils.get_theme_names()), sorted(['mkdocs2']))
|
||||
|
||||
@mock.patch('importlib_metadata.entry_points', autospec=True)
|
||||
@mock.patch('mkdocs.utils.entry_points', autospec=True)
|
||||
def test_get_themes_error(self, mock_iter):
|
||||
|
||||
theme1 = mock.Mock()
|
||||
|
||||
@@ -12,13 +12,18 @@ import os
|
||||
import posixpath
|
||||
import re
|
||||
import shutil
|
||||
import sys
|
||||
import warnings
|
||||
from collections import defaultdict
|
||||
from datetime import datetime, timezone
|
||||
from pathlib import PurePath
|
||||
from urllib.parse import urlsplit
|
||||
|
||||
import importlib_metadata
|
||||
if sys.version_info >= (3, 10):
|
||||
from importlib.metadata import entry_points
|
||||
else:
|
||||
from importlib_metadata import entry_points
|
||||
|
||||
import yaml
|
||||
from mergedeep import merge
|
||||
from yaml_env_tag import construct_env_tag
|
||||
@@ -307,7 +312,7 @@ def get_themes():
|
||||
"""Return a dict of all installed themes as {name: EntryPoint}."""
|
||||
|
||||
themes = {}
|
||||
eps = set(importlib_metadata.entry_points(group='mkdocs.themes'))
|
||||
eps = set(entry_points(group='mkdocs.themes'))
|
||||
builtins = {ep.name for ep in eps if ep.dist.name == 'mkdocs'}
|
||||
|
||||
for theme in eps:
|
||||
|
||||
@@ -6,7 +6,7 @@ PyYAML==5.1
|
||||
watchdog==2.0.0
|
||||
ghp-import==1.0
|
||||
pyyaml_env_tag==0.1
|
||||
importlib_metadata==4.3
|
||||
importlib_metadata==4.3; python_version < "3.10"
|
||||
packaging==20.5
|
||||
mergedeep==1.3.4
|
||||
babel==2.9.0
|
||||
|
||||
@@ -6,7 +6,7 @@ PyYAML>=5.1
|
||||
watchdog>=2.0.0
|
||||
ghp-import>=1.0
|
||||
pyyaml_env_tag>=0.1
|
||||
importlib_metadata>=4.3
|
||||
importlib_metadata>=4.3; python_version < "3.10"
|
||||
packaging>=20.5
|
||||
mergedeep>=1.3.4
|
||||
babel>=2.9.0
|
||||
|
||||
Reference in New Issue
Block a user