Skip to content

Commit ad45cf3

Browse files
committed
Fixed social plugin checking dependencies albeit being disabled
1 parent f2512de commit ad45cf3

File tree

4 files changed

+30
-42
lines changed

4 files changed

+30
-42
lines changed

material/plugins/social/__init__.py

-19
Original file line numberDiff line numberDiff line change
@@ -17,22 +17,3 @@
1717
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
1818
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
1919
# IN THE SOFTWARE.
20-
21-
import logging
22-
import sys
23-
24-
# -----------------------------------------------------------------------------
25-
# Checks
26-
# -----------------------------------------------------------------------------
27-
28-
# Check for pillow and cairosvg
29-
try:
30-
import cairosvg as _
31-
import PIL as _
32-
except ImportError:
33-
log = logging.getLogger("mkdocs.material.social")
34-
log.error(
35-
"Required dependencies of \"social\" plugin not found. "
36-
"Install with: pip install pillow cairosvg"
37-
)
38-
sys.exit(1)

material/plugins/social/plugin.py

+15-2
Original file line numberDiff line numberDiff line change
@@ -40,19 +40,24 @@
4040
import requests
4141
import sys
4242

43-
from cairosvg import svg2png
4443
from collections import defaultdict
4544
from hashlib import md5
4645
from io import BytesIO
4746
from mkdocs.commands.build import DuplicateFilter
47+
from mkdocs.exceptions import PluginError
4848
from mkdocs.plugins import BasePlugin
49-
from PIL import Image, ImageDraw, ImageFont
5049
from shutil import copyfile
5150
from tempfile import TemporaryFile
5251
from zipfile import ZipFile
52+
try:
53+
from cairosvg import svg2png
54+
from PIL import Image, ImageDraw, ImageFont
55+
except ImportError:
56+
pass
5357

5458
from .config import SocialConfig
5559

60+
5661
# -----------------------------------------------------------------------------
5762
# Classes
5863
# -----------------------------------------------------------------------------
@@ -66,9 +71,17 @@ def __init__(self):
6671
# Retrieve configuration
6772
def on_config(self, config):
6873
self.color = colors.get("indigo")
74+
self.config.cards = self.config.enabled
6975
if not self.config.cards:
7076
return
7177

78+
# Check dependencies
79+
if "Image" not in globals():
80+
raise PluginError(
81+
"Required dependencies of \"social\" plugin not found. "
82+
"Install with: pip install pillow cairosvg"
83+
)
84+
7285
# Move color options
7386
if self.config.cards_color:
7487

src/plugins/social/__init__.py

-19
Original file line numberDiff line numberDiff line change
@@ -17,22 +17,3 @@
1717
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
1818
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
1919
# IN THE SOFTWARE.
20-
21-
import logging
22-
import sys
23-
24-
# -----------------------------------------------------------------------------
25-
# Checks
26-
# -----------------------------------------------------------------------------
27-
28-
# Check for pillow and cairosvg
29-
try:
30-
import cairosvg as _
31-
import PIL as _
32-
except ImportError:
33-
log = logging.getLogger("mkdocs.material.social")
34-
log.error(
35-
"Required dependencies of \"social\" plugin not found. "
36-
"Install with: pip install pillow cairosvg"
37-
)
38-
sys.exit(1)

src/plugins/social/plugin.py

+15-2
Original file line numberDiff line numberDiff line change
@@ -40,19 +40,24 @@
4040
import requests
4141
import sys
4242

43-
from cairosvg import svg2png
4443
from collections import defaultdict
4544
from hashlib import md5
4645
from io import BytesIO
4746
from mkdocs.commands.build import DuplicateFilter
47+
from mkdocs.exceptions import PluginError
4848
from mkdocs.plugins import BasePlugin
49-
from PIL import Image, ImageDraw, ImageFont
5049
from shutil import copyfile
5150
from tempfile import TemporaryFile
5251
from zipfile import ZipFile
52+
try:
53+
from cairosvg import svg2png
54+
from PIL import Image, ImageDraw, ImageFont
55+
except ImportError:
56+
pass
5357

5458
from .config import SocialConfig
5559

60+
5661
# -----------------------------------------------------------------------------
5762
# Classes
5863
# -----------------------------------------------------------------------------
@@ -66,9 +71,17 @@ def __init__(self):
6671
# Retrieve configuration
6772
def on_config(self, config):
6873
self.color = colors.get("indigo")
74+
self.config.cards = self.config.enabled
6975
if not self.config.cards:
7076
return
7177

78+
# Check dependencies
79+
if "Image" not in globals():
80+
raise PluginError(
81+
"Required dependencies of \"social\" plugin not found. "
82+
"Install with: pip install pillow cairosvg"
83+
)
84+
7285
# Move color options
7386
if self.config.cards_color:
7487

0 commit comments

Comments
 (0)