Skip to content

Commit

Permalink
Fixed social plugin checking dependencies albeit being disabled
Browse files Browse the repository at this point in the history
  • Loading branch information
squidfunk committed Aug 30, 2023
1 parent f2512de commit ad45cf3
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 42 deletions.
19 changes: 0 additions & 19 deletions material/plugins/social/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
17 changes: 15 additions & 2 deletions material/plugins/social/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,19 +40,24 @@
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
# -----------------------------------------------------------------------------
Expand All @@ -66,9 +71,17 @@ def __init__(self):
# 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:

Expand Down
19 changes: 0 additions & 19 deletions src/plugins/social/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
17 changes: 15 additions & 2 deletions src/plugins/social/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,19 +40,24 @@
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
# -----------------------------------------------------------------------------
Expand All @@ -66,9 +71,17 @@ def __init__(self):
# 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:

Expand Down

0 comments on commit ad45cf3

Please sign in to comment.