Inline dependencies from info plugin

This commit is contained in:
squidfunk 2023-01-01 17:39:04 +01:00
parent 68f2381ca4
commit 2144c2fae8
3 changed files with 9 additions and 47 deletions

View File

@ -37,18 +37,9 @@ from mkdocs.config.base import Config
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 from pkg_resources import get_distribution
from pipdeptree import PackageDAG, get_installed_distributions, render_json_tree
from zipfile import ZipFile, ZIP_DEFLATED from zipfile import ZipFile, ZIP_DEFLATED
try:
from pipdeptree import (
PackageDAG,
get_installed_distributions,
render_json_tree
)
dependencies = True
except ImportError:
dependencies = False
# ----------------------------------------------------------------------------- # -----------------------------------------------------------------------------
# Class # Class
# ----------------------------------------------------------------------------- # -----------------------------------------------------------------------------
@ -73,14 +64,6 @@ class InfoPlugin(BasePlugin[InfoPluginConfig]):
if not self.config.enabled: if not self.config.enabled:
return return
# Check if required dependencies are installed
if not dependencies:
log.error("Required dependencies of \"info\" plugin not found.")
print(Style.NORMAL)
print(" pip install \"mkdocs-material[info]\"")
print(Style.NORMAL)
sys.exit(1)
# Resolve latest version # Resolve latest version
url = "https://github.com/squidfunk/mkdocs-material/releases/latest" url = "https://github.com/squidfunk/mkdocs-material/releases/latest"
res = requests.get(url, allow_redirects = False) res = requests.get(url, allow_redirects = False)
@ -89,7 +72,7 @@ class InfoPlugin(BasePlugin[InfoPluginConfig]):
_, version = res.headers.get("location").rsplit("/", 1) _, version = res.headers.get("location").rsplit("/", 1)
package = get_distribution("mkdocs-material") package = get_distribution("mkdocs-material")
if package.version != version: if package.version != version:
log.error("Please update 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(package.version, version)
# Print message that we're creating a bug report # Print message that we're creating a bug report
@ -192,10 +175,10 @@ class InfoPlugin(BasePlugin[InfoPluginConfig]):
# Print help on versions and exit # Print help on versions and exit
def _help_on_versions_and_exit(self, have, need): def _help_on_versions_and_exit(self, have, need):
print(Fore.RED) print(Fore.RED)
print(" When reporting issues, please first update to the latest") print(" When reporting issues, please first upgrade to the latest")
print(" version of Material for MkDocs, as the problem might already") print(" version of Material for MkDocs, as the problem might already")
print(" be fixed in the latest version. This helps reduce duplicate") print(" be fixed in the latest version. This helps reduce duplicate")
print(" efforts and saves the maintainers time.") print(" efforts and saves us maintainers time.")
print(Style.NORMAL) print(Style.NORMAL)
print(f" Please update from {have} to {need}.") print(f" Please update from {have} to {need}.")
print(Style.RESET_ALL) print(Style.RESET_ALL)

View File

@ -68,11 +68,7 @@ setup(
packages = find_packages(exclude = ["src", "src.*"]), packages = find_packages(exclude = ["src", "src.*"]),
include_package_data = True, include_package_data = True,
install_requires = install_requires, install_requires = install_requires,
extras_require = { extras_require = {},
"info": [
"pipdeptree>=2.3.3"
]
},
python_requires='>=3.7', python_requires='>=3.7',
entry_points = { entry_points = {
"mkdocs.themes": [ "mkdocs.themes": [

View File

@ -37,18 +37,9 @@ from mkdocs.config.base import Config
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 from pkg_resources import get_distribution
from pipdeptree import PackageDAG, get_installed_distributions, render_json_tree
from zipfile import ZipFile, ZIP_DEFLATED from zipfile import ZipFile, ZIP_DEFLATED
try:
from pipdeptree import (
PackageDAG,
get_installed_distributions,
render_json_tree
)
dependencies = True
except ImportError:
dependencies = False
# ----------------------------------------------------------------------------- # -----------------------------------------------------------------------------
# Class # Class
# ----------------------------------------------------------------------------- # -----------------------------------------------------------------------------
@ -73,14 +64,6 @@ class InfoPlugin(BasePlugin[InfoPluginConfig]):
if not self.config.enabled: if not self.config.enabled:
return return
# Check if required dependencies are installed
if not dependencies:
log.error("Required dependencies of \"info\" plugin not found.")
print(Style.NORMAL)
print(" pip install \"mkdocs-material[info]\"")
print(Style.NORMAL)
sys.exit(1)
# Resolve latest version # Resolve latest version
url = "https://github.com/squidfunk/mkdocs-material/releases/latest" url = "https://github.com/squidfunk/mkdocs-material/releases/latest"
res = requests.get(url, allow_redirects = False) res = requests.get(url, allow_redirects = False)
@ -89,7 +72,7 @@ class InfoPlugin(BasePlugin[InfoPluginConfig]):
_, version = res.headers.get("location").rsplit("/", 1) _, version = res.headers.get("location").rsplit("/", 1)
package = get_distribution("mkdocs-material") package = get_distribution("mkdocs-material")
if package.version != version: if package.version != version:
log.error("Please update 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(package.version, version)
# Print message that we're creating a bug report # Print message that we're creating a bug report
@ -192,10 +175,10 @@ class InfoPlugin(BasePlugin[InfoPluginConfig]):
# Print help on versions and exit # Print help on versions and exit
def _help_on_versions_and_exit(self, have, need): def _help_on_versions_and_exit(self, have, need):
print(Fore.RED) print(Fore.RED)
print(" When reporting issues, please first update to the latest") print(" When reporting issues, please first upgrade to the latest")
print(" version of Material for MkDocs, as the problem might already") print(" version of Material for MkDocs, as the problem might already")
print(" be fixed in the latest version. This helps reduce duplicate") print(" be fixed in the latest version. This helps reduce duplicate")
print(" efforts and saves the maintainers time.") print(" efforts and saves us maintainers time.")
print(Style.NORMAL) print(Style.NORMAL)
print(f" Please update from {have} to {need}.") print(f" Please update from {have} to {need}.")
print(Style.RESET_ALL) print(Style.RESET_ALL)