diff --git a/.github/workflows/workflow.yml b/.github/workflows/workflow.yml index 1846ed8..a62bf21 100644 --- a/.github/workflows/workflow.yml +++ b/.github/workflows/workflow.yml @@ -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 diff --git a/dev-requirements.txt b/dev-requirements.txt index 2541773..e0c25be 100644 --- a/dev-requirements.txt +++ b/dev-requirements.txt @@ -1,5 +1,4 @@ sphinx -matplotlib wheel==0.37.1 pytest==7.1.3 beautifulsoup4==4.11.1 diff --git a/docs/requirements.txt b/docs/requirements.txt index 5bfb0f2..83e6de9 100644 --- a/docs/requirements.txt +++ b/docs/requirements.txt @@ -3,3 +3,4 @@ furo==2022.9.29 sphinx==5.2.3 sphinx-design ./ +matplotlib \ No newline at end of file diff --git a/setup.py b/setup.py index 1799775..45b707b 100644 --- a/setup.py +++ b/setup.py @@ -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/*"]}, diff --git a/sphinxext/opengraph/__init__.py b/sphinxext/opengraph/__init__.py index 5d52cb9..66bfbdc 100644 --- a/sphinxext/opengraph/__init__.py +++ b/sphinxext/opengraph/__init__.py @@ -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 @@ -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( diff --git a/tests/test_options.py b/tests/test_options.py index acaf74f..5d0809a 100644 --- a/tests/test_options.py +++ b/tests/test_options.py @@ -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) @@ -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) @@ -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"