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: