diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml index efff5e8..090382b 100644 --- a/.github/workflows/check.yml +++ b/.github/workflows/check.yml @@ -25,7 +25,7 @@ jobs: python -m pip install --upgrade pip wheel python -m pip install coverage flake8 pytest # install dependencies - pip install -e . + pip install -e .[dev] # show installed packages pip freeze - name: Test with pytest diff --git a/CHANGELOG b/CHANGELOG index c0e6486..04137b9 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,5 +1,6 @@ 0.5.4 - fix: entrypoints not working (#6, #10) + - enh: make matplotlib optional for CLI 0.5.3 - setup: bump numpy to 1.25.1 - tests: workaround for broken numpy repr diff --git a/Readme.rst b/Readme.rst index 4381a09..2e07ad7 100644 --- a/Readme.rst +++ b/Readme.rst @@ -35,8 +35,12 @@ See the docstrings and unit tests for examples using the Python API. CLI --- -The package also installs two scripts, ``igorbinarywave`` and -``igorpackedexperiment`` which can be used to dump files to stdout. +The package also installs two command-line-interface (CLI) scripts, +``igorbinarywave`` and ``igorpackedexperiment`` which can be used to dump files +to stdout. You should install the ``[CLI]`` extra for them to fully work:: + + pip install igor2[CLI] + For details on their usage, use the ``--help`` option. For example:: igorbinarywave --help @@ -46,7 +50,7 @@ Testing ------- Run internal unit tests by cloning the repository and installing the -test requirements ``pytest`` and then running the tests:: +``[dev]`` extra and then running the tests:: git clone https://github.com/AFM-analysis/igor2.git cd igor2 @@ -62,22 +66,6 @@ License Version 3`_ or greater, see the ``LICENSE`` file distributed with the project for details. -.. _layman: http://layman.sourceforge.net/ -.. _wtk overlay: http://blog.tremily.us/posts/Gentoo_overlay/ -.. _Debian: http://www.debian.org/ -.. _Gentoo: http://www.gentoo.org/ -.. _NumPy: http://numpy.scipy.org/ -.. _Matplotlib: http://matplotlib.sourceforge.net/ -.. _Nose: http://somethingaboutorange.com/mrl/projects/nose/ -.. _Git: http://git-scm.com/ -.. _homepage: http://blog.tremily.us/posts/igor/ -.. _pip: http://pypi.python.org/pypi/pip -.. _igor.py: http://pypi.python.org/pypi/igor.py -.. _GNU Lesser General Public License Version 3: - http://www.gnu.org/licenses/lgpl.txt -.. _update-copyright: http://blog.tremily.us/posts/update-copyright/ - - .. |PyPI Version| image:: https://img.shields.io/pypi/v/igor2.svg :target: https://pypi.python.org/pypi/igor2 .. |Build Status| image:: https://img.shields.io/github/actions/workflow/status/AFM-analysis/igor2/check.yml?branch=master diff --git a/igor2/cli/script.py b/igor2/cli/script.py index 7ba183c..67b8f6b 100644 --- a/igor2/cli/script.py +++ b/igor2/cli/script.py @@ -4,9 +4,14 @@ import argparse as _argparse import logging import sys as _sys +import warnings -import matplotlib.pyplot as pyplot - +try: + import matplotlib.pyplot as pyplot +except (ImportError, ModuleNotFoundError): + warnings.warn("Please install `matplotlib` to get the full CLI" + "functionality.") + pyplot = None from .._version import __version__ @@ -55,6 +60,8 @@ def _run(self, args): raise NotImplementedError() def plot_wave(self, args, wave, title=None): + if pyplot is None: + raise ValueError("Please install `matplotlib` for plotting.") if not args.plot: return # no-op if title is None: @@ -70,5 +77,7 @@ def plot_wave(self, args, wave, title=None): self._num_plots += 1 def display_plots(self): + if pyplot is None: + raise ValueError("Please install `matplotlib` for plotting.") if self._num_plots: pyplot.show() diff --git a/pyproject.toml b/pyproject.toml index 78a39e0..cd07d4b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -24,14 +24,12 @@ classifiers = [ license = {text = "GNU Lesser General Public License v3 or later (LGPLv3+)"} dependencies = [ "numpy>=1.25.1", - "matplotlib", ] dynamic = ["version"] [project.optional-dependencies] -dev = [ - "pytest", -] +CLI = ["matplotlib"] +dev = ["pytest"] [project.scripts] igorbinarywave = 'igor2.cli.igorbinarywave:main' diff --git a/tests/test_cli.py b/tests/test_cli.py index dade922..6b0496d 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -7,5 +7,5 @@ def test_wavescript(capsys): """Test the WaveScript class entry point.""" -def test_wavescript(capsys): +def test_packetscript(capsys): """Test the PackedScript class entry point."""