Skip to content

Commit 219c4bb

Browse files
committed
Make plotly an optional dependency
1 parent 5babb28 commit 219c4bb

6 files changed

Lines changed: 17 additions & 15 deletions

File tree

.envs/testenv-linux.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ dependencies:
1010
- pytest # dev, tests
1111
- pytest-cov # tests
1212
- pytest-xdist # dev, tests
13-
- optimagic # run, tests
13+
- optimagic>=0.5.0 # run, tests
1414
- numba # run, tests
1515
- numpy>=1.17.0 # run, tests
1616
- pandas # run, tests

.envs/testenv-others.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ dependencies:
99
- pytest # dev, tests
1010
- pytest-cov # tests
1111
- pytest-xdist # dev, tests
12-
- optimagic # run, tests
12+
- optimagic>=0.5.0 # run, tests
1313
- numba # run, tests
1414
- numpy>=1.17.0 # run, tests
1515
- pandas # run, tests

environment.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ dependencies:
1414
- pytest-xdist # dev, tests
1515
- setuptools_scm # dev
1616
- toml # dev
17-
- optimagic # run, tests
17+
- optimagic>=0.5.0 # run, tests
1818
- numba # run, tests
1919
- numpy>=1.17.0 # run, tests
2020
- pandas # run, tests

setup.cfg

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,9 @@ packages = find:
3131
install_requires =
3232
numba
3333
numpy>=1.17.0
34-
optimagic>=0.5.1
3534
pandas
36-
plotly
3735
scipy>=1.2.1
38-
python_requires = >=3.8
36+
python_requires = >=3.10
3937
include_package_data = True
4038
package_dir =
4139
=src

src/tranquilo/config.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,13 @@
11
from pathlib import Path
22
import importlib.util
33

4-
import plotly.express as px
5-
64
DOCS_DIR = Path(__file__).parent.parent / "docs"
75

86
EXAMPLE_DIR = Path(__file__).parent / "examples"
97

108
TEST_FIXTURES_DIR = Path(__file__).parent.parent.parent / "tests" / "fixtures"
119

1210

13-
PLOTLY_TEMPLATE = "simple_white"
14-
PLOTLY_PALETTE = px.colors.qualitative.Set2
15-
1611
DEFAULT_N_CORES = 1
1712

1813
CRITERION_PENALTY_SLOPE = 0.1
@@ -30,6 +25,7 @@ def _is_installed(module_name: str) -> bool:
3025

3126

3227
IS_OPTIMAGIC_INSTALLED = _is_installed("optimagic")
28+
IS_PLOTLY_INSTALLED = _is_installed("plotly")
3329

3430

3531
# =================================================================================

src/tranquilo/visualize.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,21 @@
22

33
import numpy as np
44
import pandas as pd
5-
import plotly.express as px
65
from numba import njit
7-
from plotly import figure_factory as ff
8-
from plotly import graph_objects as go
9-
from plotly.subplots import make_subplots
106

117
from tranquilo.clustering import cluster
128
from tranquilo.geometry import log_d_quality_calculator
139
from tranquilo.volume import get_radius_after_volume_scaling
10+
from tranquilo.config import IS_PLOTLY_INSTALLED
1411

1512
from typing import Any, Protocol, runtime_checkable
1613

14+
if IS_PLOTLY_INSTALLED:
15+
import plotly.express as px
16+
from plotly import figure_factory as ff
17+
from plotly import graph_objects as go
18+
from plotly.subplots import make_subplots
19+
1720

1821
def visualize_tranquilo(results, iterations):
1922
"""Plot diagnostic information of optimization result in given iteration(s).
@@ -53,6 +56,11 @@ def visualize_tranquilo(results, iterations):
5356
iteration.
5457
5558
"""
59+
if not IS_PLOTLY_INSTALLED:
60+
raise ImportError(
61+
"Plotly is not installed. Please install plotly to use visualize_tranquilo."
62+
)
63+
5664
results = deepcopy(results)
5765
if isinstance(iterations, int):
5866
iterations = {case: iterations for case in results}

0 commit comments

Comments
 (0)