From 29abd0ef5a83f5e9ae22c656211834a41fcaa6a6 Mon Sep 17 00:00:00 2001 From: Henry Leung Date: Wed, 30 Aug 2023 13:55:18 -0400 Subject: [PATCH] make bokeh as optional deps --- .github/workflows/ci_tests.yml | 3 +-- .readthedocs.yaml | 2 +- mw_plot/__init__.py | 8 +++++++- mw_plot/mw_plot_bokeh.py | 7 +++++++ setup.py | 2 +- 5 files changed, 17 insertions(+), 5 deletions(-) diff --git a/.github/workflows/ci_tests.yml b/.github/workflows/ci_tests.yml index 05f7a1d..1909106 100644 --- a/.github/workflows/ci_tests.yml +++ b/.github/workflows/ci_tests.yml @@ -13,9 +13,8 @@ jobs: python-version: "3.11" - name: Install dependencies run: | - pip install coveralls pydot graphviz pytest pytest-cov galpy astroquery numpy + pip install coveralls pydot graphviz pytest pytest-cov galpy astroquery numpy bokeh pip install . - name: Test mw-plot - if: ${{ matrix.PAPER_MODELS == false}} run: > python -m pytest --cov mw_plot --cov-report=xml tests/test_mwplot.py diff --git a/.readthedocs.yaml b/.readthedocs.yaml index c38e40c..0117dfd 100644 --- a/.readthedocs.yaml +++ b/.readthedocs.yaml @@ -8,7 +8,7 @@ version: 2 build: os: ubuntu-22.04 tools: - python: "3.10" + python: "3.11" # You can also specify other tool versions: # nodejs: "20" # rust: "1.70" diff --git a/mw_plot/__init__.py b/mw_plot/__init__.py index 6dac58d..4cf8f9e 100644 --- a/mw_plot/__init__.py +++ b/mw_plot/__init__.py @@ -1,5 +1,11 @@ +try: + import bokeh +except ImportError: + _BOKEH_LOADED = False +else: + from mw_plot.mw_plot_bokeh import * + from mw_plot.mw_plot_matplotlib import * -from mw_plot.mw_plot_bokeh import * from pkg_resources import get_distribution from astropy.coordinates import SkyCoord, ICRS import astropy.units as u diff --git a/mw_plot/mw_plot_bokeh.py b/mw_plot/mw_plot_bokeh.py index ca9bc0f..fa54b72 100644 --- a/mw_plot/mw_plot_bokeh.py +++ b/mw_plot/mw_plot_bokeh.py @@ -1,3 +1,10 @@ +from mw_plot import _BOKEH_LOADED + +if _BOKEH_LOADED is False: + raise ImportError( + "Bokeh is not installed. Please install Bokeh to use this feature" + ) + import requests import numpy as np import astropy.units as u diff --git a/setup.py b/setup.py index 29efa03..8f63d48 100644 --- a/setup.py +++ b/setup.py @@ -21,7 +21,7 @@ include_package_data=True, package_data={"mw_plot": ["*.png", "*.jpg"]}, python_requires=">=3.7", - install_requires=["requests", "numpy", "astropy", "matplotlib", "Pillow", "bokeh", "galpy"], + install_requires=["requests", "numpy", "astropy", "matplotlib", "Pillow", "galpy"], url="https://github.com/henrysky/milkyway_plot", project_urls={ "Bug Tracker": "https://github.com/henrysky/milkyway_plot/issues",