Skip to content

Commit

Permalink
ci: Remove references to archived altair_viewer and altair_saver in c…
Browse files Browse the repository at this point in the history
…i, docs, and tests. Uninstall anywidget and vl-convert-python during one test run (#3419)

* Remove references to altair_viewer

* Clean up build workflow and also uninstall anywidget and vl-convert-python for one build step

* Remove altair_viewer and altair_saver references from pyproject.toml

* Remove references to altair_saver

* Add deprecation warning if someone uses webdriver argument as it's not relevant for vl-convert. This was used for altair_saver which is no longer compatible and maintained

* Remove the save_engine pytest mark as it no longer makes sense in the current GitHub workflow setup

* Run test_save_html again with inline=True as vl-convert now supports it

* Remove unused imports

* Run __init__ update script

* Skip jupyterchart tests if anywidget is not installed

* Some more test skips if vl convert or anywidget are not installed

* Fix mypy errors

* Skip more tests which are expected to fail if vl-convert is not installed

---------

Co-authored-by: Mattijn van Hoek <mattijn@gmail.com>
  • Loading branch information
binste and mattijn authored May 18, 2024
1 parent ad9a261 commit 81de7c4
Show file tree
Hide file tree
Showing 17 changed files with 127 additions and 193 deletions.
21 changes: 1 addition & 20 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,10 @@ jobs:
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
# - name: Set Up Chromedriver
# run: |
# sudo apt-get update
# sudo apt-get --only-upgrade install google-chrome-stable
# sudo apt-get -yqq install chromium-chromedriver
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install ".[all, dev]"
# pip install "selenium<4.3.0"
# pip install altair_saver
- name: Install specific jsonschema
# Only have to execute this if we don't want the latest jsonschema version
if: ${{ matrix.jsonschema-version != 'latest' }}
Expand All @@ -39,7 +32,7 @@ jobs:
# Also see https://github.com/vega/altair/pull/3114
if: ${{ matrix.python-version == '3.8' }}
run: |
pip uninstall -y pyarrow vegafusion vegafusion-python-embed
pip uninstall -y pyarrow vegafusion vegafusion-python-embed vl-convert-python anywidget
- name: Maybe install lowest supported pandas version
# We install the lowest supported pandas version for one job to test that
# it still works. Downgrade to the oldest versions of pandas and numpy that include
Expand Down Expand Up @@ -72,18 +65,6 @@ jobs:
- name: Test with pytest
run: |
pytest --doctest-modules tests
# - name: Selected tests without vl-convert-python
# run: |
# pip uninstall vl-convert-python --yes
# pytest -m save_engine --doctest-modules tests
# - name: Selected tests without vl-convert-python and altair_saver
# run: |
# pip uninstall altair_saver --yes
# pytest -m save_engine --doctest-modules tests
- name: Selected tests with vl-convert-python and without altair_saver
run: |
# pip install vl-convert-python
pytest -m save_engine --doctest-modules tests
- name: Validate Vega-Lite schema
run: |
# We install all 'format' dependencies of jsonschema as check-jsonschema
Expand Down
1 change: 1 addition & 0 deletions altair/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"AggregatedFieldDef",
"Align",
"AllSortString",
"AltairDeprecationWarning",
"Angle",
"AngleDatum",
"AngleValue",
Expand Down
7 changes: 0 additions & 7 deletions altair/utils/display.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,6 @@ class RendererRegistry(PluginRegistry[RendererType]):
for more information.
"""
),
"altair_viewer": textwrap.dedent(
"""
To use the 'altair_viewer' renderer, you must install the altair_viewer
package; see http://github.com/altair-viz/altair_viewer/
for more information.
"""
),
}

def set_embed_options(
Expand Down
47 changes: 12 additions & 35 deletions altair/utils/mimebundle.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
from typing import Literal, Optional, Union, cast, Tuple

from .deprecation import AltairDeprecationWarning
from .html import spec_to_html
from ._importers import import_vl_convert, vl_version_for_vl_convert
import struct
import warnings


def spec_to_mimebundle(
Expand All @@ -15,7 +13,7 @@ def spec_to_mimebundle(
vegaembed_version: Optional[str] = None,
vegalite_version: Optional[str] = None,
embed_options: Optional[dict] = None,
engine: Optional[Literal["vl-convert", "altair_saver"]] = None,
engine: Optional[Literal["vl-convert"]] = None,
**kwargs,
) -> Union[dict, Tuple[dict, dict]]:
"""Convert a vega-lite specification to a mimebundle
Expand All @@ -41,7 +39,7 @@ def spec_to_mimebundle(
The vegaEmbed options dictionary. Defaults to the embed options set with
alt.renderers.set_embed_options().
(See https://github.com/vega/vega-embed for details)
engine: string {'vl-convert', 'altair_saver'}
engine: string {'vl-convert'}
the conversion engine to use for 'png', 'svg', 'pdf', and 'vega' formats
**kwargs :
Additional arguments will be passed to the generating function
Expand All @@ -53,7 +51,7 @@ def spec_to_mimebundle(
Note
----
The png, svg, pdf, and vega outputs require the altair_saver package
The png, svg, pdf, and vega outputs require the vl-convert package
"""
# Local import to avoid circular ImportError
from altair.utils.display import (
Expand Down Expand Up @@ -130,7 +128,7 @@ def _spec_to_mimebundle_with_engine(
the format of the mimebundle to be returned
mode : string {'vega-lite', 'vega'}
The rendering mode.
engine: string {'vl-convert', 'altair_saver'}
engine: string {'vl-convert'}
the conversion engine to use
format_locale : str or dict
d3-format locale name or dictionary. Defaults to "en-US" for United States English.
Expand Down Expand Up @@ -221,16 +219,6 @@ def _spec_to_mimebundle_with_engine(
# This should be validated above
# but raise exception for the sake of future development
raise ValueError("Unexpected format {fmt!r}".format(fmt=format))
elif normalized_engine == "altairsaver":
warnings.warn(
"The altair_saver export engine is deprecated and will be removed in a future version.\n"
"Please migrate to the vl-convert engine",
AltairDeprecationWarning,
stacklevel=1,
)
import altair_saver

return altair_saver.render(spec, format, mode=mode, **kwargs)
else:
# This should be validated above
# but raise exception for the sake of future development
Expand All @@ -240,12 +228,12 @@ def _spec_to_mimebundle_with_engine(


def _validate_normalize_engine(
engine: Optional[Literal["vl-convert", "altair_saver"]],
engine: Optional[Literal["vl-convert"]],
format: Literal["png", "svg", "pdf", "vega"],
) -> str:
"""Helper to validate and normalize the user-provided engine
engine : {None, 'vl-convert', 'altair_saver'}
engine : {None, 'vl-convert'}
the user-provided engine string
format : string {'png', 'svg', 'pdf', 'vega'}
the format of the mimebundle to be returned
Expand All @@ -256,12 +244,6 @@ def _validate_normalize_engine(
except ImportError:
vlc = None

# Try to import altair_saver
try:
import altair_saver
except ImportError:
altair_saver = None

# Normalize engine string by lower casing and removing underscores and hyphens
normalized_engine = (
None if engine is None else engine.lower().replace("-", "").replace("_", "")
Expand All @@ -273,25 +255,20 @@ def _validate_normalize_engine(
raise ValueError(
"The 'vl-convert' conversion engine requires the vl-convert-python package"
)
elif normalized_engine == "altairsaver":
if altair_saver is None:
raise ValueError(
"The 'altair_saver' conversion engine requires the altair_saver package"
)
elif normalized_engine is None:
if vlc is not None:
normalized_engine = "vlconvert"
elif altair_saver is not None:
normalized_engine = "altairsaver"
else:
raise ValueError(
"Saving charts in {fmt!r} format requires the vl-convert-python or altair_saver package: "
"see http://github.com/altair-viz/altair_saver/".format(fmt=format)
"Saving charts in {fmt!r} format requires the vl-convert-python package: "
"see https://altair-viz.github.io/user_guide/saving_charts.html#png-svg-and-pdf-format".format(
fmt=format
)
)
else:
raise ValueError(
"Invalid conversion engine {engine!r}. Expected one of {valid!r}".format(
engine=engine, valid=("vl-convert", "altair_saver")
"Invalid conversion engine {engine!r}. Expected vl-convert".format(
engine=engine
)
)
return normalized_engine
Expand Down
17 changes: 13 additions & 4 deletions altair/utils/save.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from .mimebundle import spec_to_mimebundle
from ..vegalite.v5.data import data_transformers
from altair.utils._vegafusion_data import using_vegafusion
from altair.utils.deprecation import AltairDeprecationWarning


def write_file_or_filename(
Expand Down Expand Up @@ -80,7 +81,7 @@ def save(
json_kwds: Optional[dict] = None,
webdriver: Optional[Literal["chrome", "firefox"]] = None,
scale_factor: float = 1,
engine: Optional[Literal["vl-convert", "altair_saver"]] = None,
engine: Optional[Literal["vl-convert"]] = None,
inline: bool = False,
**kwargs,
) -> None:
Expand Down Expand Up @@ -114,10 +115,10 @@ def save(
Additional keyword arguments are passed to the output method
associated with the specified format.
webdriver : string {'chrome' | 'firefox'} (optional)
Webdriver to use for png, svg, or pdf output when using altair_saver engine
This argument is deprecated as it's not relevant for the new vl-convert engine.
scale_factor : float (optional)
scale_factor to use to change size/resolution of png or svg output
engine: string {'vl-convert', 'altair_saver'}
engine: string {'vl-convert'}
the conversion engine to use for 'png', 'svg', and 'pdf' formats
inline: bool (optional)
If False (default), the required JavaScript libraries are loaded
Expand All @@ -128,6 +129,15 @@ def save(
**kwargs :
additional kwargs passed to spec_to_mimebundle.
"""
if webdriver is not None:
warnings.warn(
"The webdriver argument is deprecated as it's not relevant for"
+ " the new vl-convert engine which replaced altair_saver."
+ " The argument will be removed in a future release.",
AltairDeprecationWarning,
stacklevel=1,
)

if json_kwds is None:
json_kwds = {}

Expand Down Expand Up @@ -174,7 +184,6 @@ def perform_save():
vegalite_version=vegalite_version,
vegaembed_version=vegaembed_version,
embed_options=embed_options,
webdriver=webdriver,
scale_factor=scale_factor,
engine=engine,
**kwargs,
Expand Down
21 changes: 15 additions & 6 deletions altair/vegalite/v5/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
)
from ...utils.core import DataFrameLike
from ...utils.data import DataType
from ...utils.deprecation import AltairDeprecationWarning

if sys.version_info >= (3, 11):
from typing import Self
Expand Down Expand Up @@ -231,9 +232,9 @@ def to_dict(self) -> TypingDict[str, Union[str, dict]]:
return {"expr": self.name}
elif self.param_type == "selection":
return {
"param": self.name.to_dict()
if hasattr(self.name, "to_dict")
else self.name
"param": (
self.name.to_dict() if hasattr(self.name, "to_dict") else self.name
)
}
else:
raise ValueError(f"Unrecognized parameter type: {self.param_type}")
Expand Down Expand Up @@ -1155,7 +1156,7 @@ def save(
"""Save a chart to file in a variety of formats
Supported formats are json, html, png, svg, pdf; the last three require
the altair_saver package to be installed.
the vl-convert-python package to be installed.
Parameters
----------
Expand Down Expand Up @@ -1187,7 +1188,7 @@ def save(
Additional keyword arguments are passed to the output method
associated with the specified format.
webdriver : string {'chrome' | 'firefox'} (optional)
Webdriver to use for png, svg, or pdf output when using altair_saver engine
This argument is deprecated as it's not relevant for the new vl-convert engine.
engine: string {'vl-convert', 'altair_saver'}
the conversion engine to use for 'png', 'svg', and 'pdf' formats
inline: bool (optional)
Expand All @@ -1199,6 +1200,15 @@ def save(
**kwargs :
additional kwargs passed to spec_to_mimebundle.
"""
if webdriver is not None:
warnings.warn(
"The webdriver argument is deprecated as it's not relevant for"
+ " the new vl-convert engine which replaced altair_saver."
+ " The argument will be removed in a future release.",
AltairDeprecationWarning,
stacklevel=1,
)

from ...utils.save import save

kwds = dict(
Expand All @@ -1212,7 +1222,6 @@ def save(
vegaembed_version=vegaembed_version,
embed_options=embed_options,
json_kwds=json_kwds,
webdriver=webdriver,
engine=engine,
inline=inline,
**kwargs,
Expand Down
8 changes: 0 additions & 8 deletions doc/getting_started/resources.rst
Original file line number Diff line number Diff line change
Expand Up @@ -88,14 +88,6 @@ VegaFusion provides server-side scaling for Altair charts, which can accelerate
.. List of links.
.. _VegaFusion: https://vegafusion.io/

altair_saver_
~~~~~~~~~~~~~

Enables saving charts to a variety of output types.

.. List of links.
.. _altair_saver: https://github.com/altair-viz/altair_saver

altair_data_server_
~~~~~~~~~~~~~~~~~~~

Expand Down
1 change: 0 additions & 1 deletion doc/user_guide/display_frontends.rst
Original file line number Diff line number Diff line change
Expand Up @@ -701,7 +701,6 @@ see :ref:`display-general`.
.. _nteract: https://nteract.io
.. _nbconvert: https://nbconvert.readthedocs.io/
.. _nbviewer: https://nbviewer.jupyter.org/
.. _Altair Viewer: https://github.com/altair-viz/altair_viewer/
.. _Colab: https://colab.research.google.com
.. _Hydrogen: https://github.com/nteract/hydrogen
.. _Jupyter Notebook: https://jupyter-notebook.readthedocs.io/en/stable/
Expand Down
4 changes: 1 addition & 3 deletions doc/user_guide/large_datasets.rst
Original file line number Diff line number Diff line change
Expand Up @@ -296,8 +296,7 @@ prerender the visualization and send only a static image to your notebook. This
greatly reduce the amount of data that is being transmitted. The downside with this approach is,
that you loose all interactivity features of Altair.

Both renderers require you to install either the `vl-convert`_ or the `altair_saver`_ package, see :ref:`saving-png`,
whereas `vl-convert`_ is expected to provide the better performance.
Both renderers require you to install the `vl-convert`_ package, see :ref:`saving-png`.

.. _preaggregate-and-filter:

Expand Down Expand Up @@ -469,4 +468,3 @@ summary statistics to Altair instead of the full dataset.
.. _DuckDB: https://duckdb.org/
.. _VegaFusion DuckDB: https://vegafusion.io/duckdb.html
.. _vl-convert: https://github.com/vega/vl-convert
.. _altair_saver: https://github.com/altair-viz/altair_saver/
Loading

0 comments on commit 81de7c4

Please sign in to comment.