diff --git a/MANIFEST.in b/MANIFEST.in index 540b72040d..54939b7ce9 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1 +1,4 @@ -include requirements.txt \ No newline at end of file +include requirements.txt +include requirements/core.txt +include requirements/plotly.txt +include requirements/dev.txt \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index d599d4b382..37d7b312ec 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,19 +1 @@ -# required for running tidy3d (note xarray) -xarray -scipy -h5py>=3.0.0 -rich -nlopt -matplotlib -shapely==1.7.1 -descartes -pydantic>=1.9.0 -PyYAML -boto3 -requests -plotly==5.5.0 -dash -jupyter_dash - -# required to get xarray to not complain -dask +-r requirements/core.txt diff --git a/requirements/core.txt b/requirements/core.txt new file mode 100644 index 0000000000..30faf177ef --- /dev/null +++ b/requirements/core.txt @@ -0,0 +1,15 @@ +# just core (no plotly, no tests) + +xarray +scipy +h5py>=3.0.0 +rich +nlopt +matplotlib +shapely==1.7.1 +descartes +pydantic>=1.9.0 +PyYAML +boto3 +requests +dask diff --git a/tests/requirements.txt b/requirements/dev.txt similarity index 57% rename from tests/requirements.txt rename to requirements/dev.txt index 4ce7a5cd99..60f2a25b9c 100644 --- a/tests/requirements.txt +++ b/requirements/dev.txt @@ -1,3 +1,8 @@ +# core, plotly and tests + +-r core.txt +-r plotly.txt + # required for development click==8.0.3 black==22.1.0 diff --git a/requirements/plotly.txt b/requirements/plotly.txt new file mode 100644 index 0000000000..3ee7dbf795 --- /dev/null +++ b/requirements/plotly.txt @@ -0,0 +1,6 @@ +# core + plotly plotting, no tests +-r core.txt + +plotly==5.5.0 +dash +jupyter_dash diff --git a/setup.py b/setup.py index 14df7cac15..e77b5ee992 100644 --- a/setup.py +++ b/setup.py @@ -16,8 +16,12 @@ with open("README.md", "r", encoding="utf-8") as fh: long_description = fh.read() -with open("requirements.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() + plotly_required = [req for req in plotly_required if "-r" not in req] setuptools.setup( name=PIP_NAME, @@ -36,9 +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 bcf836c455..d302c442c5 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/__init__.py b/tidy3d/plugins/__init__.py index 1c643a8819..764cef1ed7 100644 --- a/tidy3d/plugins/__init__.py +++ b/tidy3d/plugins/__init__.py @@ -5,5 +5,3 @@ from .mode.mode_solver import ModeSolver, ModeSolverData from .near2far.near2far import Near2Far, Near2FarSurface from .smatrix.smatrix import ComponentModeler, Port -from .webplots.app import SimulationDataApp -from .webplots.simulation import SimulationPlotly diff --git a/tidy3d/plugins/webplots/__init__.py b/tidy3d/plugins/webplots/__init__.py index e69de29bb2..bb36d55f38 100644 --- a/tidy3d/plugins/webplots/__init__.py +++ b/tidy3d/plugins/webplots/__init__.py @@ -0,0 +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 diff --git a/tox.ini b/tox.ini index 797f17e850..f06c9a7be3 100644 --- a/tox.ini +++ b/tox.ini @@ -14,8 +14,9 @@ python = [testenv] deps = - -rrequirements.txt - -rtests/requirements.txt + -rrequirements/core.txt + -rrequirements/plotly.txt + -rrequirements/dev.txt commands = pip install requests black --check --diff . --line-length 100