mirror of
https://github.com/squidfunk/mkdocs-material.git
synced 2024-06-14 11:52:32 +03:00
Switched info plugin to importlib to mitigate deprecations
This commit is contained in:
parent
15c024cbbf
commit
0be6172765
@ -26,11 +26,11 @@ import requests
|
|||||||
import sys
|
import sys
|
||||||
|
|
||||||
from colorama import Fore, Style
|
from colorama import Fore, Style
|
||||||
|
from importlib.metadata import distributions, version
|
||||||
from io import BytesIO
|
from io import BytesIO
|
||||||
from mkdocs import utils
|
from mkdocs import utils
|
||||||
from mkdocs.plugins import BasePlugin, event_priority
|
from mkdocs.plugins import BasePlugin, event_priority
|
||||||
from mkdocs.structure.files import get_files
|
from mkdocs.structure.files import get_files
|
||||||
from pkg_resources import get_distribution, working_set
|
|
||||||
from zipfile import ZipFile, ZIP_DEFLATED
|
from zipfile import ZipFile, ZIP_DEFLATED
|
||||||
|
|
||||||
from material.plugins.info.config import InfoConfig
|
from material.plugins.info.config import InfoConfig
|
||||||
@ -70,11 +70,11 @@ class InfoPlugin(BasePlugin[InfoConfig]):
|
|||||||
res = requests.get(url, allow_redirects = False)
|
res = requests.get(url, allow_redirects = False)
|
||||||
|
|
||||||
# Check if we're running the latest version
|
# Check if we're running the latest version
|
||||||
_, version = res.headers.get("location").rsplit("/", 1)
|
_, current = res.headers.get("location").rsplit("/", 1)
|
||||||
package = get_distribution("mkdocs-material")
|
present = version("mkdocs-material")
|
||||||
if not package.version.startswith(version):
|
if not present.startswith(current):
|
||||||
log.error("Please upgrade to the latest version.")
|
log.error("Please upgrade to the latest version.")
|
||||||
self._help_on_versions_and_exit(package.version, version)
|
self._help_on_versions_and_exit(present, current)
|
||||||
|
|
||||||
# Print message that we're creating a bug report
|
# Print message that we're creating a bug report
|
||||||
log.info("Started archive creation for bug report")
|
log.info("Started archive creation for bug report")
|
||||||
@ -116,7 +116,10 @@ class InfoPlugin(BasePlugin[InfoConfig]):
|
|||||||
f.writestr(
|
f.writestr(
|
||||||
os.path.join(archive_name, "requirements.lock.txt"),
|
os.path.join(archive_name, "requirements.lock.txt"),
|
||||||
"\n".join(sorted([
|
"\n".join(sorted([
|
||||||
f"{dist.as_requirement()}" for dist in working_set
|
"==".join([
|
||||||
|
package.name,
|
||||||
|
package.version
|
||||||
|
]) for package in distributions()
|
||||||
]))
|
]))
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -26,11 +26,11 @@ import requests
|
|||||||
import sys
|
import sys
|
||||||
|
|
||||||
from colorama import Fore, Style
|
from colorama import Fore, Style
|
||||||
|
from importlib.metadata import distributions, version
|
||||||
from io import BytesIO
|
from io import BytesIO
|
||||||
from mkdocs import utils
|
from mkdocs import utils
|
||||||
from mkdocs.plugins import BasePlugin, event_priority
|
from mkdocs.plugins import BasePlugin, event_priority
|
||||||
from mkdocs.structure.files import get_files
|
from mkdocs.structure.files import get_files
|
||||||
from pkg_resources import get_distribution, working_set
|
|
||||||
from zipfile import ZipFile, ZIP_DEFLATED
|
from zipfile import ZipFile, ZIP_DEFLATED
|
||||||
|
|
||||||
from material.plugins.info.config import InfoConfig
|
from material.plugins.info.config import InfoConfig
|
||||||
@ -70,11 +70,11 @@ class InfoPlugin(BasePlugin[InfoConfig]):
|
|||||||
res = requests.get(url, allow_redirects = False)
|
res = requests.get(url, allow_redirects = False)
|
||||||
|
|
||||||
# Check if we're running the latest version
|
# Check if we're running the latest version
|
||||||
_, version = res.headers.get("location").rsplit("/", 1)
|
_, current = res.headers.get("location").rsplit("/", 1)
|
||||||
package = get_distribution("mkdocs-material")
|
present = version("mkdocs-material")
|
||||||
if not package.version.startswith(version):
|
if not present.startswith(current):
|
||||||
log.error("Please upgrade to the latest version.")
|
log.error("Please upgrade to the latest version.")
|
||||||
self._help_on_versions_and_exit(package.version, version)
|
self._help_on_versions_and_exit(present, current)
|
||||||
|
|
||||||
# Print message that we're creating a bug report
|
# Print message that we're creating a bug report
|
||||||
log.info("Started archive creation for bug report")
|
log.info("Started archive creation for bug report")
|
||||||
@ -116,7 +116,10 @@ class InfoPlugin(BasePlugin[InfoConfig]):
|
|||||||
f.writestr(
|
f.writestr(
|
||||||
os.path.join(archive_name, "requirements.lock.txt"),
|
os.path.join(archive_name, "requirements.lock.txt"),
|
||||||
"\n".join(sorted([
|
"\n".join(sorted([
|
||||||
f"{dist.as_requirement()}" for dist in working_set
|
"==".join([
|
||||||
|
package.name,
|
||||||
|
package.version
|
||||||
|
]) for package in distributions()
|
||||||
]))
|
]))
|
||||||
)
|
)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user