Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 0 additions & 14 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -104,20 +104,6 @@ UltraPlot is published on `PyPi <https://pypi.org/project/ultraplot/>`__ and
pip install ultraplot
conda install -c conda-forge ultraplot

pyCirclize-based plots require the optional ``circos`` extra:

.. code-block:: bash

pip install 'ultraplot[circos]'

The ``docs`` extra also includes pyCirclize for building the documentation.

To install the ``circos``, ``docs``, and ``stats`` dependency groups together:

.. code-block:: bash

pip install 'ultraplot[all]'

Likewise, an existing installation of UltraPlot can be upgraded
to the latest version with:

Expand Down
21 changes: 11 additions & 10 deletions ultraplot/axes/plot_types/circlize.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,15 @@
#: saved, so `_import_pycirclize` puts these back.
_PYCIRCLIZE_RC_LEAKS = ("savefig.bbox", "savefig.pad_inches", "svg.fonttype")

_PYCIRCLIZE_INSTALL_MESSAGE = (
"This plot requires the optional pyCirclize dependency, which is not "
"available in this Python environment. Chord diagrams, radar charts, "
"phylogenies, and Circos plots need it.\n"
"Install it in the environment running your code:\n"
" pip install 'ultraplot[circos]'\n"
"Then restart Python or your notebook kernel and run the plot again."
)


def _import_pycirclize():
"""
Expand Down Expand Up @@ -56,17 +65,9 @@ def _import_pycirclize_unguarded():
try:
import pycirclize
except ImportError as exc2:
raise ImportError(
"pycirclize is required for circos plots. Install it with "
"`pip install 'ultraplot[circos]'` or ensure "
"`pyCirclize/src` is on PYTHONPATH."
) from exc2
raise ImportError(_PYCIRCLIZE_INSTALL_MESSAGE) from exc2
else:
raise ImportError(
"pycirclize is required for circos plots. Install it with "
"`pip install 'ultraplot[circos]'` or ensure "
"`pyCirclize/src` is on PYTHONPATH."
) from exc
raise ImportError(_PYCIRCLIZE_INSTALL_MESSAGE) from exc
return pycirclize


Expand Down
37 changes: 30 additions & 7 deletions ultraplot/tests/test_circlize_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,23 @@ def test_circos_bed_plot_toggle(fake_pycirclize, tmp_path):
uplt.close(fig)


def test_import_pycirclize_error_message(monkeypatch):
@pytest.mark.parametrize(
"method, args, kwargs",
[
(None, (), {}),
("circos", ({"A": 10},), {}),
("chord_diagram", ({"A": {"A": 1}},), {}),
("chord", ({"A": {"A": 1}},), {}),
("radar_chart", ({"A": [1, 2]},), {"vmin": 0, "vmax": 3}),
("radar", ({"A": [1, 2]},), {"vmin": 0, "vmax": 3}),
("phylogeny", ("((A,B),C);",), {}),
("circos_bed", ("missing.bed",), {}),
("bed", ("missing.bed",), {}),
],
)
def test_import_pycirclize_error_message(monkeypatch, method, args, kwargs):
"""Every circular plot entry point explains how to install its dependency."""
fig, ax = uplt.subplots(proj="polar")
orig_import = builtins.__import__

def fake_import(name, *args, **kwargs):
Expand All @@ -176,12 +192,19 @@ def fake_import(name, *args, **kwargs):

monkeypatch.setattr(builtins, "__import__", fake_import)
monkeypatch.setattr(Path, "is_dir", lambda self: False)
sys.modules.pop("pycirclize", None)
with pytest.warns(UserWarning, match=r"pip install 'ultraplot\[circos\]'"):
with pytest.raises(
ImportError, match="pycirclize is required for circos plots"
):
circlize_mod._import_pycirclize()
monkeypatch.delitem(sys.modules, "pycirclize", raising=False)
try:
with pytest.warns(
UserWarning, match=r"pip install 'ultraplot\[circos\]'"
) as caught:
with pytest.raises(ImportError, match="optional pyCirclize dependency"):
if method is None:
circlize_mod._import_pycirclize()
else:
getattr(ax, method)(*args, **kwargs)
assert "restart Python or your notebook kernel" in str(caught[0].message)
finally:
uplt.close(fig)


def test_resolve_defaults_with_existing_objects(fake_pycirclize):
Expand Down
Loading