Skip to content

Commit

Permalink
enh: make matplotlib optional for CLI
Browse files Browse the repository at this point in the history
  • Loading branch information
paulmueller committed Mar 20, 2024
1 parent 8b0a0ba commit 24d40c3
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 27 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -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
Expand Down
26 changes: 7 additions & 19 deletions Readme.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
13 changes: 11 additions & 2 deletions igor2/cli/script.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__

Expand Down Expand Up @@ -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:
Expand All @@ -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()
6 changes: 2 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
2 changes: 1 addition & 1 deletion tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""

0 comments on commit 24d40c3

Please sign in to comment.