Fixed social plugin checking dependencies albeit being disabled

This commit is contained in:
squidfunk 2023-08-30 16:28:59 +02:00
parent f2512ded4a
commit ad45cf36cb
No known key found for this signature in database
GPG Key ID: 5ED40BC4F9C436DF
4 changed files with 30 additions and 42 deletions

View File

@ -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)

View File

@ -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:

View File

@ -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)

View File

@ -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: