Skip to content

Commit

Permalink
Make matplotlib optional (#104)
Browse files Browse the repository at this point in the history
* make matplotlib optional

* test with and without matplotlib

* 1

* d
  • Loading branch information
TheTripleV authored Jul 7, 2023
1 parent f510aea commit 7eafbd3
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 5 deletions.
6 changes: 6 additions & 0 deletions .github/workflows/workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,12 @@ jobs:
- name: Run tests for ${{ matrix.python-version }}
run: |
python -m pytest -vv
- name: Install matplotlib
run: |
python -m pip install matplotlib
- name: Run tests with matplotlib for ${{ matrix.python-version }}
run: |
python -m pytest -vv
build-docs:
runs-on: ubuntu-latest
Expand Down
1 change: 0 additions & 1 deletion dev-requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
sphinx
matplotlib
wheel==0.37.1
pytest==7.1.3
beautifulsoup4==4.11.1
Expand Down
1 change: 1 addition & 0 deletions docs/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ furo==2022.9.29
sphinx==5.2.3
sphinx-design
./
matplotlib
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
long_description_content_type="text/markdown",
url="https://github.com/wpilibsuite/sphinxext-opengraph",
license="LICENSE.md",
install_requires=["sphinx>=4.0", "matplotlib"],
install_requires=["sphinx>=4.0"],
packages=["sphinxext/opengraph"],
include_package_data=True,
package_data={"sphinxext.opengraph": ["sphinxext/opengraph/_static/*"]},
Expand Down
11 changes: 10 additions & 1 deletion sphinxext/opengraph/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,15 @@
from .descriptionparser import get_description
from .metaparser import get_meta_description
from .titleparser import get_title
from .socialcards import create_social_card, DEFAULT_SOCIAL_CONFIG

try:
import matplotlib
except ImportError:
print("matplotlib is not installed, social cards will not be generated")
create_social_card = None
DEFAULT_SOCIAL_CONFIG = {}
else:
from .socialcards import create_social_card, DEFAULT_SOCIAL_CONFIG

import os

Expand Down Expand Up @@ -139,6 +147,7 @@ def get_tags(
if (
not (image_url or ogp_use_first_image)
and config_social.get("enable") is not False
and create_social_card is not None
):
# Description
description_max_length = config_social.get(
Expand Down
5 changes: 3 additions & 2 deletions tests/test_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def test_meta_name_description(meta_tags):


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

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


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

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

0 comments on commit 7eafbd3

Please sign in to comment.