From ad45cf36cbb2e4af509b5db7ff4472e6569c6fd7 Mon Sep 17 00:00:00 2001 From: squidfunk Date: Wed, 30 Aug 2023 16:28:59 +0200 Subject: [PATCH] Fixed social plugin checking dependencies albeit being disabled --- material/plugins/social/__init__.py | 19 ------------------- material/plugins/social/plugin.py | 17 +++++++++++++++-- src/plugins/social/__init__.py | 19 ------------------- src/plugins/social/plugin.py | 17 +++++++++++++++-- 4 files changed, 30 insertions(+), 42 deletions(-) diff --git a/material/plugins/social/__init__.py b/material/plugins/social/__init__.py index e61266112..d18993785 100644 --- a/material/plugins/social/__init__.py +++ b/material/plugins/social/__init__.py @@ -17,22 +17,3 @@ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS # IN THE SOFTWARE. - -import logging -import sys - -# ----------------------------------------------------------------------------- -# Checks -# ----------------------------------------------------------------------------- - -# Check for pillow and cairosvg -try: - import cairosvg as _ - import PIL as _ -except ImportError: - log = logging.getLogger("mkdocs.material.social") - log.error( - "Required dependencies of \"social\" plugin not found. " - "Install with: pip install pillow cairosvg" - ) - sys.exit(1) diff --git a/material/plugins/social/plugin.py b/material/plugins/social/plugin.py index 011992b81..5c550c7d6 100644 --- a/material/plugins/social/plugin.py +++ b/material/plugins/social/plugin.py @@ -40,19 +40,24 @@ import re import requests import sys -from cairosvg import svg2png from collections import defaultdict from hashlib import md5 from io import BytesIO from mkdocs.commands.build import DuplicateFilter +from mkdocs.exceptions import PluginError from mkdocs.plugins import BasePlugin -from PIL import Image, ImageDraw, ImageFont from shutil import copyfile from tempfile import TemporaryFile from zipfile import ZipFile +try: + from cairosvg import svg2png + from PIL import Image, ImageDraw, ImageFont +except ImportError: + pass from .config import SocialConfig + # ----------------------------------------------------------------------------- # Classes # ----------------------------------------------------------------------------- @@ -66,9 +71,17 @@ class SocialPlugin(BasePlugin[SocialConfig]): # Retrieve configuration def on_config(self, config): self.color = colors.get("indigo") + self.config.cards = self.config.enabled if not self.config.cards: return + # Check dependencies + if "Image" not in globals(): + raise PluginError( + "Required dependencies of \"social\" plugin not found. " + "Install with: pip install pillow cairosvg" + ) + # Move color options if self.config.cards_color: diff --git a/src/plugins/social/__init__.py b/src/plugins/social/__init__.py index e61266112..d18993785 100644 --- a/src/plugins/social/__init__.py +++ b/src/plugins/social/__init__.py @@ -17,22 +17,3 @@ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS # IN THE SOFTWARE. - -import logging -import sys - -# ----------------------------------------------------------------------------- -# Checks -# ----------------------------------------------------------------------------- - -# Check for pillow and cairosvg -try: - import cairosvg as _ - import PIL as _ -except ImportError: - log = logging.getLogger("mkdocs.material.social") - log.error( - "Required dependencies of \"social\" plugin not found. " - "Install with: pip install pillow cairosvg" - ) - sys.exit(1) diff --git a/src/plugins/social/plugin.py b/src/plugins/social/plugin.py index 011992b81..5c550c7d6 100644 --- a/src/plugins/social/plugin.py +++ b/src/plugins/social/plugin.py @@ -40,19 +40,24 @@ import re import requests import sys -from cairosvg import svg2png from collections import defaultdict from hashlib import md5 from io import BytesIO from mkdocs.commands.build import DuplicateFilter +from mkdocs.exceptions import PluginError from mkdocs.plugins import BasePlugin -from PIL import Image, ImageDraw, ImageFont from shutil import copyfile from tempfile import TemporaryFile from zipfile import ZipFile +try: + from cairosvg import svg2png + from PIL import Image, ImageDraw, ImageFont +except ImportError: + pass from .config import SocialConfig + # ----------------------------------------------------------------------------- # Classes # ----------------------------------------------------------------------------- @@ -66,9 +71,17 @@ class SocialPlugin(BasePlugin[SocialConfig]): # Retrieve configuration def on_config(self, config): self.color = colors.get("indigo") + self.config.cards = self.config.enabled if not self.config.cards: return + # Check dependencies + if "Image" not in globals(): + raise PluginError( + "Required dependencies of \"social\" plugin not found. " + "Install with: pip install pillow cairosvg" + ) + # Move color options if self.config.cards_color: