diff --git a/requirements.txt b/requirements.txt index c58f7cb09..37d7b312e 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1 +1 @@ --r requirements/common.txt +-r requirements/core.txt diff --git a/requirements/common.txt b/requirements/core.txt similarity index 100% rename from requirements/common.txt rename to requirements/core.txt diff --git a/requirements/dev.txt b/requirements/dev.txt index 5d014afe3..60f2a25b9 100644 --- a/requirements/dev.txt +++ b/requirements/dev.txt @@ -1,6 +1,6 @@ # core, plotly and tests --r common.txt +-r core.txt -r plotly.txt # required for development diff --git a/requirements/plotly.txt b/requirements/plotly.txt index 292f1bd88..3ee7dbf79 100644 --- a/requirements/plotly.txt +++ b/requirements/plotly.txt @@ -1,5 +1,5 @@ # core + plotly plotting, no tests --r common.txt +-r core.txt plotly==5.5.0 dash diff --git a/setup.py b/setup.py index 49ae115ce..e77b5ee99 100644 --- a/setup.py +++ b/setup.py @@ -16,8 +16,8 @@ with open("README.md", "r", encoding="utf-8") as fh: long_description = fh.read() -with open("requirements/common.txt") as f: - required = f.read().splitlines() +with open("requirements/core.txt") as f: + core_required = f.read().splitlines() with open("requirements/plotly.txt") as f: plotly_required = f.read().splitlines() @@ -40,10 +40,8 @@ "License :: OSI Approved :: MIT License", "Operating System :: OS Independent", ], - # package_dir={"": ""}, - # packages=[PACKAGE_NAME], packages=setuptools.find_packages(), python_requires=">=3.6", - install_requires=required, + install_requires=core_required, extras_require={"plotly": plotly_required}, ) diff --git a/tidy3d/log.py b/tidy3d/log.py index bcf836c45..d302c442c 100644 --- a/tidy3d/log.py +++ b/tidy3d/log.py @@ -66,6 +66,10 @@ class DataError(Tidy3dError): """Error accessing data.""" +class Tidy3dImportError(Tidy3dError): + """Error importing a package needed for tidy3d.""" + + """ Logging functions """ diff --git a/tidy3d/plugins/webplots/__init__.py b/tidy3d/plugins/webplots/__init__.py index 79bf464e8..bb36d55f3 100644 --- a/tidy3d/plugins/webplots/__init__.py +++ b/tidy3d/plugins/webplots/__init__.py @@ -1,3 +1,19 @@ """Import post run visualization app and Simulation plotting through plotly.""" + +from ...log import Tidy3dImportError + +# try to get the plotly packages, otherwise print a helpful error message. +try: + from jupyter_dash import JupyterDash + from dash import Dash + import plotly.graph_objects as go +except ImportError as e: + raise Tidy3dImportError( + "Could not import plotly requirements. " + "Ensure that tidy3d is installed with [plotly] requirements specified. " + '``pip install "tidy3d-beta[plotly]" or `pip install -e ".[plotly]". ' + "Or, install the dependencies directly with `pip install -r requirements/plotly.txt`" + ) from e + from .app import SimulationDataApp from .simulation import SimulationPlotly