Skip to content

Commit 7eafbd3

Browse files
authored
Make matplotlib optional (#104)
* make matplotlib optional * test with and without matplotlib * 1 * d
1 parent f510aea commit 7eafbd3

File tree

6 files changed

+21
-5
lines changed

6 files changed

+21
-5
lines changed

.github/workflows/workflow.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,12 @@ jobs:
102102
- name: Run tests for ${{ matrix.python-version }}
103103
run: |
104104
python -m pytest -vv
105+
- name: Install matplotlib
106+
run: |
107+
python -m pip install matplotlib
108+
- name: Run tests with matplotlib for ${{ matrix.python-version }}
109+
run: |
110+
python -m pytest -vv
105111
106112
build-docs:
107113
runs-on: ubuntu-latest

dev-requirements.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
sphinx
2-
matplotlib
32
wheel==0.37.1
43
pytest==7.1.3
54
beautifulsoup4==4.11.1

docs/requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ furo==2022.9.29
33
sphinx==5.2.3
44
sphinx-design
55
./
6+
matplotlib

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
long_description_content_type="text/markdown",
1515
url="https://github.com/wpilibsuite/sphinxext-opengraph",
1616
license="LICENSE.md",
17-
install_requires=["sphinx>=4.0", "matplotlib"],
17+
install_requires=["sphinx>=4.0"],
1818
packages=["sphinxext/opengraph"],
1919
include_package_data=True,
2020
package_data={"sphinxext.opengraph": ["sphinxext/opengraph/_static/*"]},

sphinxext/opengraph/__init__.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,15 @@
88
from .descriptionparser import get_description
99
from .metaparser import get_meta_description
1010
from .titleparser import get_title
11-
from .socialcards import create_social_card, DEFAULT_SOCIAL_CONFIG
11+
12+
try:
13+
import matplotlib
14+
except ImportError:
15+
print("matplotlib is not installed, social cards will not be generated")
16+
create_social_card = None
17+
DEFAULT_SOCIAL_CONFIG = {}
18+
else:
19+
from .socialcards import create_social_card, DEFAULT_SOCIAL_CONFIG
1220

1321
import os
1422

@@ -139,6 +147,7 @@ def get_tags(
139147
if (
140148
not (image_url or ogp_use_first_image)
141149
and config_social.get("enable") is not False
150+
and create_social_card is not None
142151
):
143152
# Description
144153
description_max_length = config_social.get(

tests/test_options.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def test_meta_name_description(meta_tags):
4040

4141

4242
@pytest.mark.sphinx("html", testroot="meta-name-description-manual-description")
43-
def test_meta_name_description(meta_tags):
43+
def test_meta_name_manual_description(meta_tags):
4444
og_description = get_tag_content(meta_tags, "description")
4545
description = get_meta_description(meta_tags)
4646

@@ -49,7 +49,7 @@ def test_meta_name_description(meta_tags):
4949

5050

5151
@pytest.mark.sphinx("html", testroot="meta-name-description-manual-og-description")
52-
def test_meta_name_description(meta_tags):
52+
def test_meta_name_manual_og_description(meta_tags):
5353
og_description = get_tag_content(meta_tags, "description")
5454
description = get_meta_description(meta_tags)
5555

@@ -101,6 +101,7 @@ def test_image_alt(og_meta_tags):
101101
@pytest.mark.sphinx("html", testroot="simple")
102102
def test_image_social_cards(meta_tags):
103103
"""Social cards should automatically be added if no og:image is given."""
104+
pytest.importorskip("matplotlib")
104105
# Asserting `in` instead of `==` because of the hash that is generated
105106
assert (
106107
"http://example.org/en/latest/_images/social_previews/summary_index"

0 commit comments

Comments
 (0)