From 303428fb7fc9d171fce9129118bac57f05ec8818 Mon Sep 17 00:00:00 2001 From: tylerflex Date: Tue, 19 Apr 2022 11:57:29 -0700 Subject: [PATCH 1/3] separated requirements, now plotly not installed by default but must be specified in pip --- requirements.txt | 20 +------------------ requirements/common.txt | 15 ++++++++++++++ .../requirements.txt => requirements/dev.txt | 5 +++++ requirements/plotly.txt | 6 ++++++ setup.py | 7 ++++++- tidy3d/plugins/__init__.py | 2 -- tidy3d/plugins/webplots/__init__.py | 3 +++ 7 files changed, 36 insertions(+), 22 deletions(-) create mode 100644 requirements/common.txt rename tests/requirements.txt => requirements/dev.txt (56%) create mode 100644 requirements/plotly.txt diff --git a/requirements.txt b/requirements.txt index d599d4b382..c58f7cb09c 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/common.txt diff --git a/requirements/common.txt b/requirements/common.txt new file mode 100644 index 0000000000..30faf177ef --- /dev/null +++ b/requirements/common.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 56% rename from tests/requirements.txt rename to requirements/dev.txt index 4ce7a5cd99..5d014afe3c 100644 --- a/tests/requirements.txt +++ b/requirements/dev.txt @@ -1,3 +1,8 @@ +# core, plotly and tests + +-r common.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..292f1bd887 --- /dev/null +++ b/requirements/plotly.txt @@ -0,0 +1,6 @@ +# core + plotly plotting, no tests +-r common.txt + +plotly==5.5.0 +dash +jupyter_dash diff --git a/setup.py b/setup.py index 14df7cac15..49ae115ce3 100644 --- a/setup.py +++ b/setup.py @@ -16,9 +16,13 @@ with open("README.md", "r", encoding="utf-8") as fh: long_description = fh.read() -with open("requirements.txt") as f: +with open("requirements/common.txt") as f: 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, version=version["__version__"], @@ -41,4 +45,5 @@ packages=setuptools.find_packages(), python_requires=">=3.6", install_requires=required, + extras_require={"plotly": plotly_required}, ) 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..79bf464e8d 100644 --- a/tidy3d/plugins/webplots/__init__.py +++ b/tidy3d/plugins/webplots/__init__.py @@ -0,0 +1,3 @@ +"""Import post run visualization app and Simulation plotting through plotly.""" +from .app import SimulationDataApp +from .simulation import SimulationPlotly From 4b26c41275e462677a29c1006f2564070774b55b Mon Sep 17 00:00:00 2001 From: tylerflex Date: Tue, 19 Apr 2022 12:15:44 -0700 Subject: [PATCH 2/3] rename common.txt to core.txt and added import message in try except --- requirements.txt | 2 +- requirements/{common.txt => core.txt} | 0 requirements/dev.txt | 2 +- requirements/plotly.txt | 2 +- setup.py | 8 +++----- tidy3d/log.py | 4 ++++ tidy3d/plugins/webplots/__init__.py | 16 ++++++++++++++++ 7 files changed, 26 insertions(+), 8 deletions(-) rename requirements/{common.txt => core.txt} (100%) diff --git a/requirements.txt b/requirements.txt index c58f7cb09c..37d7b312ec 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 5d014afe3c..60f2a25b9c 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 292f1bd887..3ee7dbf795 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 49ae115ce3..e77b5ee992 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 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/webplots/__init__.py b/tidy3d/plugins/webplots/__init__.py index 79bf464e8d..bb36d55f38 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 From a064292dfe43d799ae2fc397ca4a0920a8903ee4 Mon Sep 17 00:00:00 2001 From: tylerflex Date: Tue, 19 Apr 2022 12:56:24 -0700 Subject: [PATCH 3/3] fixed tox problem getting requirements.txt --- MANIFEST.in | 5 ++++- tox.ini | 5 +++-- 2 files changed, 7 insertions(+), 3 deletions(-) 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/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