Skip to content

Commit

Permalink
Merge pull request hyperspy#3439 from ericpre/add_style_parameters_pr…
Browse files Browse the repository at this point in the history
…int_known_signals

Add style parameter to `print_known_signal_types`
  • Loading branch information
jlaehne authored Sep 13, 2024
2 parents 5dbd2b5 + d0ee956 commit fcba3b4
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 1 deletion.
1 change: 1 addition & 0 deletions doc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,7 @@
"widget",
"strategy",
"module",
"prettytable",
}

# if Version(numpydoc.__version__) >= Version("1.6.0rc0"):
Expand Down
13 changes: 13 additions & 0 deletions hyperspy/tests/utils/test_print_known_signal_types.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from prettytable import MARKDOWN

from hyperspy.utils import print_known_signal_types


Expand All @@ -7,3 +9,14 @@ def test_text_output(capsys):
assert "signal_type" in captured.out
# the output will be str, not html
assert "<p>" not in captured.out


def test_style(capsys):
print_known_signal_types(style=MARKDOWN)
captured = capsys.readouterr()

assert "signal_type" in captured.out
# the output will be markdown, not ascii
assert ":--" in captured.out # markdown
assert "<p>" not in captured.out # not html
assert "+--" not in captured.out # not ascii
10 changes: 9 additions & 1 deletion hyperspy/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,17 @@
import importlib


def print_known_signal_types():
def print_known_signal_types(style=None):
r"""Print all known `signal_type`\s
This includes `signal_type`\s from all installed packages that
extend HyperSpy.
Parameters
----------
style : prettytable style or None
If None, the default prettytable style will be used.
Examples
--------
>>> hs.print_known_signal_types() # doctest: +SKIP
Expand All @@ -65,6 +70,8 @@ def print_known_signal_types():

table = PrettyTable()
table.field_names = ["signal_type", "aliases", "class name", "package"]
if style is not None:
table.set_style(style)
for sclass, sdict in ALL_EXTENSIONS["signals"].items():
# skip lazy signals and non-data-type specific signals
if sdict["lazy"] or not sdict["signal_type"]:
Expand All @@ -77,6 +84,7 @@ def print_known_signal_types():
package = sdict["module"].split(".")[0]
table.add_row([sdict["signal_type"], aliases, sclass, package])
table.sortby = "class name"

display(table)


Expand Down
1 change: 1 addition & 0 deletions upcoming_changes/3439.enhancements.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add ``style`` parameter to the :func:`~.api.print_known_signal_types` function.

0 comments on commit fcba3b4

Please sign in to comment.