From acc8b1ca2b5f27337a2ee58c3c1f4aac24bb71cd Mon Sep 17 00:00:00 2001 From: slackline Date: Sat, 9 Dec 2023 21:36:35 +0000 Subject: [PATCH] Fixing entry points MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Whilst checking up on #9 I was browsing the other issues and thought I might be Work related to #6 Fixes the entry points (also known as Command Line Interface) by... * Adding `if __name__ == "__main__:"` to each of the `cll.*` submodules to instantiate and run the classes defined within. * Changes some of the dependencies (`matplotlib`) to not be conditional on installing the CLI optional dependencies. * Corrects the entry points defined in `pyproject.toml` ```bash (igor2) ❱ pip install -e . (igor2) ❱ igorbinarywave -f tests/data/mac-double.ibw 5 4 3 2 1 (igor2) ❱ igorpackedexperiment -f tests/data/polar-graphs-demo.pxp [, , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ] ``` I'm not sure if this is the expected output but the entry points work in some manner. I couldn't work out the difference between the test data files (I'm on GNU/Linux rather than OSX/Windows). However, I don't think this should be the final solution as there is still a dependency on the original `igor` as the [`Script`](https://github.com/wking/igor/blob/master/igor/script.py) module is imported and it would make more sense to have the entry points defined wholly within `igor2`. --- .gitignore | 4 ++++ Readme.rst | 33 ++++++++++++------------------- igor2/cli/igorbinarywave.py | 20 ++++++++++--------- igor2/cli/igorpackedexperiment.py | 25 ++++++++++++----------- pyproject.toml | 14 +++++++------ tests/requirements.txt | 1 - tests/test_cli.py | 11 +++++++++++ 7 files changed, 60 insertions(+), 48 deletions(-) delete mode 100644 tests/requirements.txt create mode 100644 tests/test_cli.py diff --git a/.gitignore b/.gitignore index 95600fb..6e839d1 100644 --- a/.gitignore +++ b/.gitignore @@ -9,3 +9,7 @@ igor2/_version.py *.egg-info .env + +# Emacs +*~ +\#* \ No newline at end of file diff --git a/Readme.rst b/Readme.rst index 5362b99..4381a09 100644 --- a/Readme.rst +++ b/Readme.rst @@ -4,12 +4,12 @@ Igor2 |PyPI Version| |Build Status| |Coverage Status| -Python parser for Igor Binary Waves (.ibw) and Packed Experiment -(.pxp) files written by WaveMetrics' IGOR Pro software. +Python parser for Igor Binary Waves (``.ibw``) and Packed Experiment +(``.pxp``) files written by WaveMetrics' IGOR Pro software. + +Igor2 is the continuation of the inactive +`igor `_ project. -Igor2 is the continuation of the inactive igor project, forked -from W. Trevor King and originally written by Paul Kienzle (see -git history). Installation ------------ @@ -17,20 +17,13 @@ You can install igor2 via pip:: pip install igor2 -The commands ``igorbinarywave`` and ``igorpackedexperiment`` are currently -not properly implemented (see https://github.com/AFM-analysis/igor2/issues/6), -but it should be straight-forward to fix this. - -To install igor2 with the command-line interface (CLI), run:: - - pip install igor2[CLI] - Usage ----- This package is a direct replacement of `igor`. Your scripts should work without any issues if you replace:: + import igor with:: @@ -42,7 +35,7 @@ See the docstrings and unit tests for examples using the Python API. CLI --- -The package also installs to scripts, ``igorbinarywave`` and +The package also installs two scripts, ``igorbinarywave`` and ``igorpackedexperiment`` which can be used to dump files to stdout. For details on their usage, use the ``--help`` option. For example:: @@ -52,14 +45,14 @@ For details on their usage, use the ``--help`` option. For example:: Testing ------- -Run internal unit tests with pytest:: +Run internal unit tests by cloning the repository and installing the +test requirements ``pytest`` and then running the tests:: - pip install -r tests/requirements.txt - pytest tests + git clone https://github.com/AFM-analysis/igor2.git + cd igor2 + pip install -e .[dev] + pytest -The data in the ``test/data`` directory is in the Git repository, but -it is not bundled with the source code. If you want the test data, -you'll have to clone the Git repository or download a snapshot. Licence ------- diff --git a/igor2/cli/igorbinarywave.py b/igor2/cli/igorbinarywave.py index fff594c..bb72ed5 100755 --- a/igor2/cli/igorbinarywave.py +++ b/igor2/cli/igorbinarywave.py @@ -1,24 +1,26 @@ -#!/usr/bin/env python """IBW -> ASCII conversion""" - import pprint import numpy -from igor.binarywave import load +from igor2.binarywave import load from igor.script import Script -class WaveScript (Script): +class WaveScript(Script): def _run(self, args): wave = load(args.infile) - numpy.savetxt( - args.outfile, wave['wave']['wData'], fmt='%g', delimiter='\t') + numpy.savetxt(args.outfile, wave["wave"]["wData"], fmt="%g", delimiter="\t") self.plot_wave(args, wave) if args.verbose > 0: - wave['wave'].pop('wData') + wave["wave"].pop("wData") pprint.pprint(wave) -s = WaveScript(description=__doc__) -s.run() +def main(): + s = WaveScript(description=__doc__) + s.run() + + +if __name__ == "__main__": + main() diff --git a/igor2/cli/igorpackedexperiment.py b/igor2/cli/igorpackedexperiment.py index b7e9972..f8f1140 100755 --- a/igor2/cli/igorpackedexperiment.py +++ b/igor2/cli/igorpackedexperiment.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python -# # Copyright (C) 2012 W. Trevor King # # This file is part of igor. @@ -16,27 +14,26 @@ # # You should have received a copy of the GNU Lesser General Public License # along with igor. If not, see . - "PXP -> ASCII conversion" import pprint -from igor.packed import load, walk -from igor.record.wave import WaveRecord +from igor2.packed import load, walk +from igor2.record.wave import WaveRecord from igor.script import Script -class PackedScript (Script): +class PackedScript(Script): def _run(self, args): self.args = args records, filesystem = load(args.infile) - if hasattr(args.outfile, 'write'): + if hasattr(args.outfile, "write"): f = args.outfile # filename is actually a stream object else: - f = open(args.outfile, 'w') + f = open(args.outfile, "w") try: f.write(pprint.pformat(records)) - f.write('\n') + f.write("\n") finally: if f != args.outfile: f.close() @@ -49,6 +46,10 @@ def _plot_wave_callback(self, dirpath, key, value): self.plot_wave(self.args, value.wave, title=dirpath + [key]) -s = PackedScript( - description=__doc__, filetype='IGOR Packed Experiment (.pxp) file') -s.run() +def main(): + s = PackedScript(description=__doc__, filetype="IGOR Packed Experiment (.pxp) file") + s.run() + + +if __name__ == "__main__": + main() diff --git a/pyproject.toml b/pyproject.toml index d2b7bb1..51aefc8 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -23,18 +23,20 @@ classifiers = [ ] license = {text = "GNU Lesser General Public License v3 or later (LGPLv3+)"} dependencies = [ - "numpy>=1.25.1", + "igor", + "numpy>=1.25.1", + "matplotlib", ] dynamic = ["version"] [project.optional-dependencies] -CLI = [ - "matplotlib", - ] +dev = [ + "pytest", +] [project.scripts] -igorbinarywave = 'igor2.cli:igorbinarywave' -igorpackedexperiment = 'igor2.cli:igorpackedexperiment' +igorbinarywave = 'igor2.cli.igorbinarywave:main' +igorpackedexperiment = 'igor2.cli.igorpackedexperiment:main' [tool.setuptools] packages = ["igor2"] diff --git a/tests/requirements.txt b/tests/requirements.txt deleted file mode 100644 index e079f8a..0000000 --- a/tests/requirements.txt +++ /dev/null @@ -1 +0,0 @@ -pytest diff --git a/tests/test_cli.py b/tests/test_cli.py new file mode 100644 index 0000000..dade922 --- /dev/null +++ b/tests/test_cli.py @@ -0,0 +1,11 @@ +"""Test the CLI entry points.""" +from igor2.cli.igorbinarywave import WaveScript +from igor2.cli.igorpackedexperiment import PackedScript + + +def test_wavescript(capsys): + """Test the WaveScript class entry point.""" + + +def test_wavescript(capsys): + """Test the PackedScript class entry point."""