Skip to content

Commit

Permalink
Merge pull request #982 from jakevdp/selenium-lazy
Browse files Browse the repository at this point in the history
MAINT: avoid selenium import when altair is imported
  • Loading branch information
jakevdp authored Jun 27, 2018
2 parents 9eb71cd + 78e00ad commit 97cf10e
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions altair/utils/headless.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,6 @@
import os
import tempfile

try:
import selenium.webdriver
except ImportError:
selenium = None


@contextlib.contextmanager
def temporary_filename(**kwargs):
Expand Down Expand Up @@ -110,9 +105,15 @@ def temporary_filename(**kwargs):
def compile_spec(spec, format, mode,
vega_version, vegaembed_version, vegalite_version,
scale_factor=1, driver_timeout=20, webdriver='chrome'):

# TODO: detect & use local Jupyter caches of JS packages?

# selenium is an optional dependency, so import it here
try:
import selenium.webdriver
except ImportError:
raise ImportError("selenium package is required "
"for saving chart as {0}".format(format))

if format not in ['png', 'svg', 'vega']:
raise NotImplementedError("format must be 'svg', 'png' or 'vega'")

Expand All @@ -128,9 +129,6 @@ def compile_spec(spec, format, mode,
if mode == 'vega-lite' and vegalite_version is None:
raise ValueError("must specify vega-lite version")

if selenium is None:
raise ImportError("selenium package is required "
"for saving chart as {0}".format(format))
if webdriver == 'chrome':
webdriver_class = selenium.webdriver.Chrome
webdriver_options_class = selenium.webdriver.chrome.options.Options
Expand Down

0 comments on commit 97cf10e

Please sign in to comment.